Skip to main content
Injected state lets tools receive hidden context — session ID, agent ID, previous results — without users or the LLM ever seeing those parameters in the tool schema.
The user asks a question; hidden state is injected into the tool without appearing in the schema. The LLM sees only query in the schema. The agent automatically fills state before calling the tool.

Quick Start

1

Simplest form — bare Injected

Bare Injected behaves like Injected[dict] — excluded from the tool schema and resolved to state.to_dict().
2

Create a tool with injected state

The state parameter never appears in tool descriptions shown to the LLM — only query does.
3

Use AgentState for typed access


How It Works

When a tool parameter is annotated with Injected, Injected[T], or bare Injected, the SDK:
  1. Strips that parameter from the schema sent to the LLM
  2. Captures the current AgentState at call time
  3. Injects the state value automatically before the tool runs

Configuration Options

AgentState fields available at runtime:

Injected Tools TypeScript Reference

TypeScript injected state configuration

Tools Rust Reference

Rust tool configuration

Common Patterns

Multi-turn memory access in a tool:
Testing with a manual injection context:
Validating the tool schema has no injected params:

Best Practices

Bare Injected and Injected[dict] both return state.to_dict(). Use Injected[AgentState] when you need memory, learn_manager, or previous_tool_results objects directly.
The LLM builds its understanding from the docstring. Documenting injected parameters confuses the model — describe only the user-facing parameters.
Direct unit tests cannot rely on an agent to set up injection context. Wrap calls with with_injection_context(state) to test tools in isolation without spinning up a full agent.
get_current_state() returns None when called outside an agent context. resolve_injected_value falls back to an empty dict. Design tools to handle empty state gracefully.

Tools

Creating and registering tools with agents

Middleware

Intercept tool calls before and after execution