Skip to main content
An agent stays aware of its changing environment through runtime state injection: before each reasoning step, information that changes across turns (current time, plan tasks, context usage) is injected into the context as a HintBlock, configured via the injection_config parameter of Agent(...). The injection covers three dimensions, each with its own timing rule:

How Injection Works

Each injected field is wrapped as <key>value</key>, and all fields are joined and placed into the template (a <system-reminder> wrapper by default). A typical injected hint looks like:
Example Injected Hint
Three design decisions are worth knowing:
  • The injection is not ephemeral: it is appended to the persistent context on purpose, so the agent can perceive how time elapses and what it did at each step, building a sense of time.
  • The hint is attached as a HintBlock instead of mutating the system prompt, so prompt caching still works while the agent stays aware of the changing state.
  • Only information that changes within a conversation is injected. Fixed information (the agent’s identity, standing instructions) belongs in the system prompt.
When an injection happens and emit_hint_event is enabled, reply_stream also yields a HintBlockEvent, so a frontend can render the injected hint.

Configure Injection

Pass an InjectionConfig to the agent constructor to tune the injection behavior:
The fields of InjectionConfig:
context_buffer_ratio must be smaller than the trigger_ratio of the context config, so that the context usage is injected before the compression happens. Otherwise the agent constructor raises a ValueError.

Inject Custom Fields

Beyond the built-in dimensions, extra_fields injects developer-defined information, such as sensor readings or deployment metadata:
Extra fields are attached to every injection but never trigger one by themselves: they ride along whenever the time, tasks, or context dimension fires.

Customize the Template

The template field controls how the injected fields are presented to the LLM. It must contain the {runtime_state} placeholder, which is replaced by the joined <key>value</key> fields: