Expand description
BP-3 (catalog row “Context-budget tools”, cx§1’s token_budget
feature): get_context_remaining and new_context, the MODEL’s doors
onto two mechanisms the agent already owns.
Neither tool implements accounting or clearing of its own. BP-4 built
both, for the operator’s /context and /handoff:
crate::agent::Agent::context_usage— the live context-window accounting, over the very estimates the context guard enforces, so what the model is told and what refuses an oversized turn can never disagree.GetContextRemainingToolreports exactly that struct.crate::agent::Agent::new_context— the in-session fresh window (system prompt + a handoff marker naming the objective + the curated recent tail, with the set-aside turns kept in the transcript sidecar whenever one is attached).NewContextToolasks for exactly that.
Both travel through ONE shared ContextBudget, held as an Arc on
crate::tools::ToolContext: the agent publishes the accounting when
the tool asks for it, and the tool parks its fresh-window request there
for the agent to apply the moment the tool round ends — so the very next
model request is the fresh window.
Why the park-and-apply split. A Tool::execute sees its arguments
and the ambient context, never the agent’s transcript. Keeping the
rewrite in the one place that owns history is the same reason
tool_search/expand_reduction are agent intrinsics — and it is what
keeps the model’s new_context and the operator’s /handoff running
the same code, not two drifting copies of one idea.
Structs§
- Context
Budget - The shared context accounting the two tools read and write.
- GetContext
Remaining Tool get_context_remaining— how much of the context window is left.- NewContext
Request - One parked fresh-window request, as the model stated it. The fields are
exactly
Agent::new_context’s parameters — this type carries a request across the tool/agent boundary, it does not add semantics of its own. - NewContext
Tool new_context— continue in a fresh window seeded with an objective and the curated recent tail.
Constants§
- GET_
CONTEXT_ REMAINING - Registered name of the remaining-budget tool.
- NEW_
CONTEXT - Registered name of the fresh-window tool.