The three mechanisms work in concert: injection adds what the model needs to know now, compression removes what it no longer needs verbatim, and offloading keeps the removed content one file-read away.
Assemble Context
Before each model call, the agent assembles a single API input from three layers. The structure below shows what flows into that call:Model API Input
System Prompt
Base system prompt
Skill instructions (from Toolkit)
on_system_prompt middleware transforms
Summary (compressed history, if any)
Context (recent uncompressed messages)
- System prompt: starts from the
system_promptpassed at agent creation, then appends skill instructions (each skill’s name and description, sourced from the toolkit), then runs everyon_system_promptmiddleware hook in order. - Summary: the compressed digest of older messages, present only after a compression has occurred.
- Context: the recent uncompressed messages (user inputs, assistant responses, tool calls, tool results). This is also where injected runtime-state hints live.
Next Steps
Environment Awareness
Inject time, tasks, and context usage so the agent stays oriented.
Compress Context
Keep the context length within the preset limit.
Offload Context
Persist dropped content so the agent can read it back on demand.
Workspace
Built-in offloader implementations and the agent’s working environment.