Expand description
Agents context and Agents compact
(docs/specs/SPEC_AGENT_SELF_COMPACTION_2026_10_23.md §3.3): an agent reads
how full its own context is, and compacts itself when its turn ends.
Both act on the caller’s own pane only, resolved from its agent token’s UID
(actor::own_pane_by_token), never from a name: there is no target.
Structs§
Constants§
- EXIT_
WAIT 🔒 - The longest a fresh session waits for the old CLI to exit.
- FOCUS_
MAX_ 🔒CHARS - The most focus text sent with
/compact. - FRESH_
ATTEMPTS 🔒 - Tries a fresh session makes when a message queued behind the turn starts the next one before the old session can be ended.
- FRESH_
FAILED_ 🔒NOTE_ KEY - Held for the agent’s next turn when its fresh session couldn’t start.
- HANDOFF_
MAX_ 🔒CHARS - The most handoff text a fresh session carries.
- STOP_
PENDING 🔒 - TURN_
END_ 🔒POLL - TURN_
END_ 🔒WAIT - The longest a self-compaction waits for the caller’s turn to end.
- TURN_
RUNNING 🔒 - What
start_fresh_sessionsays when the turn hasn’t ended, or the CLI is already being stopped: the two it is worth trying again after.
Functions§
- acp_
compact_ 🔒message - The message that compacts the ACP agent in
block_id, by what its harness announced:/compactwith the focus when the command takes one, alone when it doesn’t, a refusal when the harness announced no compaction command.Nonewhen the pane is not an ACP agent. - compact_
for_ 🔒backstop - srv’s own compaction of a route agent whose context is far over its budget: the compaction
Agents compactschedules, without a focus (the harness’s summarizer decides what to keep).Err(why)when it can’t be sent now. - compact_
message 🔒 /compactwith the focus, trimmed toFOCUS_MAX_CHARSand to one paragraph’s worth of whitespace.- compact_
request 🔒 - The message that compacts a
provideragent, or why it can’t be: a Claude agent takes/compact(with its focus) as a turn wherever it runs, and a container’s turn is that same message on its per-turn exec controller. - compact_
when_ 🔒turn_ ends - Send
messageas AgentMux’s own turn onceblock_id’s turn has ended. A container agent’s turn is not waited for: it runs one turn at a time from a queue, and the compaction is placed at the head of that queue, so it starts the moment the turn in flight ends and ahead of the messages already waiting. Waiting for a moment with no turn running could take as long as the queue stays full, and the compaction would then go behind it (the queue is never empty for a busy agent: the next waiting message starts the moment a turn ends). - end_
session 🔒 - End
block_id’s provider session, so the next message starts a new one. An ACP agent’s old session id comes back, so the new session’s first message can name it. - fresh_
refusal 🔒 - Why the pane of a model change can’t start a fresh session, or nothing: the test
Agents freshapplies to its own pane. - fresh_
supported 🔒 - Whether an agent of
providercan start a fresh session, and why not. A container’s Claude or Codex agent runs oneexecper turn on the same controller a host Codex agent does, so ending its session is forgetting its id, as there (blockcontroller/subprocess/codex_fresh.rs); the harnesses that speak ACP have no such controller in a container. - fresh_
when_ 🔒turn_ ends - Wait for the turn to end, end the session, then send
first_messageas AgentMux’s own turn, which starts the new session. - handle_
compact_ 🔒self POST /api/v1/agent/self/compact:scheduled(runs when the caller’s turn ends) orrefusedwith why.- handle_
context_ 🔒self POST /api/v1/agent/self/context- handle_
fresh_ 🔒self POST /api/v1/agent/self/fresh:scheduled(when the caller’s turn ends, its session ends and a new one starts with the handoff) orrefused.focuscarries the handoff here.- handoff_
message 🔒 - The new session’s first message from AgentMux: the agent’s own handoff and a pointer to the old session. Nothing else of the conversation comes with it.
- hint_
kind 🔒 - Which hint rules
block_id‘s agent gets: an ACP harness has its window’s sizes and offers compaction only when it announced it (the same the turn-end note uses), every other agent the settings’ own. - no_pane 🔒
- provider_
of 🔒 claudeorcodexfor a pane that can compact, with whether it runs in a container.- speaks_
acp 🔒 - Whether
provideris an Agent Client Protocol harness (dsh, Gemini, Copilot, …): every one can open a new session. - start_
fresh_ 🔒after_ switch - Start
block_id’s fresh session after a model change: when its turn ends its session ends, andfirst_messagestarts the new one on the model the agent is set to now.falsewhen there is no async runtime to run it on. - switch_
message 🔒 - The first message of the fresh session a model change starts (
agent.model.switchandAgents updatewithfresh): where the agent was moved to, that the earlier conversation is in its record and not in its context, and what the caller said its next session must know (none: where to look for what it was doing). - wait_
for_ 🔒turn_ end - Wait until
block_idhas no turn running;falseafterTURN_END_WAIT. - with_
previous_ 🔒session first_message, naming the session it replaces when the harness had one, so a person can take it back from the harness.