Skip to main content

Module context

Module context 

Source
Expand description

Contexts (RFC 0026 §5): the durable, self-compacting working memory of the root agent (context/root) and of every A2A conversation (context/<contextId>). A context is a versioned record of messages, a structured summary block, the loaded skill set, the working plan (RFC 0026 §5.3), the last preflight verdict and a token estimate; the runtime is its single writer and checkpoints it after every turn.

The transcript representation here (Msg) is serializable (unlike the provider wire type) and converts to crate::wire::intel::Message at request time. Sub-modules: plan (the plan object), memory (the durable KV), compact (compaction planning + application), skills (skill catalogue/loaded set), tokens (estimates).

Modules§

compact
Compaction (RFC 0026 §5.2): when a context’s token estimate crosses context.compact_at × model_window (or context.compact is called), the older messages are summarized by a structured think into the summary block, the last keep_last messages stay verbatim, the plan stays verbatim, skill bodies not referenced in the kept window are evicted (the names stay), the version bumps and the record is checkpointed.
memory
Agent memory (RFC 0028 §3 memory.*, RFC 0025 §3.3 memory): a durable JSON key/value space in the instance’s store namespace — memory/<key> — with optional TTL, size caps, and prefix listing. Listing uses the store’s list when it has one, else the memory/_index record this module keeps (RFC 0025 §3.3). Overridable by an MCP memory server through the registry.
plan
The context plan (RFC 0026 §5.3, RFC 0028 §3 plan.*): a small ordered checklist the model owns for one context — created by the preflight or by plan.create, advanced by plan.update, cleared by plan.clear, rendered into every prompt, auto-advanced when a bound run/subagent/task reaches a terminal state. Temporary by intent (it belongs to the conversation, never to memory), durable by construction (part of the context record).
skills
Skills (RFC 0028 §7): named instruction bundles — the SKILL.md idiom — discovered from MCP servers as prompts (prompts/list = catalogue, prompts/get = body) or resources (skill://<name> URIs or mimeType: text/x-skill+markdown), referenced as @skill:<name> in the instruction, a step, or a chat message, and preloaded into the calling context (progressive disclosure: the catalogue is always visible, a body only when referenced or skills.loaded). Bodies are cached by hash, never stored; the loaded set [{name, hash}] is part of the context record.
tokens
Token estimates (RFC 0026 §5.2, §7). agentd never counts provider tokens itself — the provider’s usage is the truth once a call returns — but the governor’s reservation and the compaction trigger need a number before the call. The heuristic is the usual chars / 4 (English prose ≈ 4 chars a token; JSON and code run denser, which errs on the safe side for a reservation) plus a small per-message overhead. Deliberately simple and dependency-free; the estimate is only ever compared against generous thresholds.

Structs§

ContextState
The durable context record (RFC 0025 §3.3 context).
Contexts
The in-memory registry of contexts + their durable mirror.
SkillRef
A loaded skill reference (name + version hash), RFC 0028 §7.
Summary
The structured summary block a compaction produces (RFC 0026 §5.2).

Enums§

ContextKind
The kind of a context.
Msg
One transcript entry. ts is wall-clock ms; tool results keep the parsed JSON when the tool returned structured content (text otherwise).

Constants§

ROOT
The root context id (RFC 0025 §3.3).