9. Compact Long-Running Context
Compaction reduces long conversation state into durable facts, open questions, constraints, and next actions. This cell documents the application-side compaction pattern as a small JSON object so the concept is clear without adding another live feature path. Inspect which facts are kept and which details are omitted before the next turn.
from __future__ import annotations
compaction_note = {
"feature": "Compaction",
"how_to_apply": "Summarize older support turns into durable facts, open questions, policy constraints, and next actions before continuing the workflow.",
"brightcart_example": {
"durable_facts": ["Customer Maya Chen", "ORDER-8831", "replacement delayed", "carrier scan stale"],
"policy_constraints": ["Do not promise refund without eligibility", "Offer expedited replacement or 15% concession after 48-hour delay with approval"],
"next_action": "Check latest carrier scan and supervisor callback status.",
},
}
record_check("Compaction", "documented", compaction_note)
record_response("Compacted support context", "json", compaction_note)
print_json(compaction_note) <div style="background:#f6f8fa; padding:6px 8px; font-weight:600;">JSON</div>
<div style="padding:8px; white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.45;">\{
"feature": "Compaction", "how_to_apply": "Summarize older support turns into durable facts, open questions, policy constraints, and next actions before continuing the workflow.", "brightcart_example": { "durable_facts": [ "Customer Maya Chen", "ORDER-8831", "replacement delayed", "carrier scan stale" ], "policy_constraints": [ "Do not promise refund without eligibility", "Offer expedited replacement or 15% concession after 48-hour delay with approval" ], "next_action": "Check latest carrier scan and supervisor callback status." } }</div>