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, repeated tool failures) is injected into the context as a HintBlock, configured via the injection_config parameter of Agent(...). The injection covers four dimensions, each with its own timing rule: The context_buffer_ratio behind the context usage dimension lives in the context config; the other three dimensions are governed by InjectionConfig.

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 on InjectionConfig is deprecated; use the field of the same name in the context config instead. Passing it here still works and overrides the value from the context config, along with a DeprecationWarning.

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, context usage, or tool failure 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: