feat(context): stateful compact serving for agent context tools#869
Open
edwin-zvs wants to merge 1 commit into
Open
feat(context): stateful compact serving for agent context tools#869edwin-zvs wants to merge 1 commit into
edwin-zvs wants to merge 1 commit into
Conversation
The construct_context / agentd_context payload is now deduplicated per serving process instead of relying on the model to echo etags back: - Shared compact layer in construct_protocol::agent_context, used by both construct-mcp and smith's native tool. Smith previously bypassed all compaction and pretty-printed the full context (policies, extension registry, full memory, full program run) on every call. - The serving process remembers what it sent: repeat calls collapse unchanged memory/program content to etag markers and send static fields (instructions, widget paths, reference hint) once. known_* etag echoes are still honored for restarted serving processes. - Program-run markdown and its static run reference (run instructions, smart clips) get independent etags, so a program edit no longer resends ~4KB of static instructions. - skip_memory:true lets an agent that just wrote its memory files skip the immediate resend of content it authored. - refresh:true resends everything; smith resets serve state natively on compact/prune, since the model no longer holds served content. - Spec 0095 updated with the serving contract.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Input-token efficiency review of
construct_context/agentd_contextfound five gaps (the etag work in #865 only landed on the MCP path):agentd_contextbypassed all compaction — it pretty-printed the fullAgentdContexton every call: 17-bullet memory policy + 13-bullet widget policy (~5KB), the full 12-entry Markdown-extension registry (~6KB), full memory files, and the full program-run payload. Roughly 3k tokens of static text per call before any real content, on the harness that calls the tool most.known_*etags — unenforced and unmeasured.instructions,session_widgets, and the reference hint were resent on every call.Change
One shared compact-serving layer in
construct_protocol::agent_context, used by bothconstruct-mcpand smith's native tool:{path, etag, unchanged}markers and send static fields once.known_*echoes are still honored (covers a restarted serving process mid-conversation).skip_memory: true: omit memory content the agent already holds verbatim (e.g. it just wrote the files); paths + etags still returned, and the content is marked served.refresh: true— the compaction escape hatch: resends everything. Everything omitted stays disk-recoverable (memory by path, program viaconstruct_program_get), so a stale serve state degrades to an extra fetch, never data loss./compact, and destructive prune — the exact moments the model loses served content — closing the compaction/etag hazard on the native side entirely.known_*from the tool schema (still accepted), trimmedtruncated/remaining_bytesto truncation cases only.Not done (deliberate): version-based markdown diffs for program runs — partial markdown risks the agent forming a wrong mental model of the document; the etag split captures nearly all the win.
Spec 0095 updated with the serving contract (identical behavior across surfaces; native tools must not bypass the budget layer).
Testing
construct_protocol::agent_context.cargo test --workspace: all 19 targets green.🤖 Generated with Claude Code