query in the schema. The agent automatically fills state before calling the tool.
Quick Start
1
Simplest form — bare Injected
Injected behaves like Injected[dict] — excluded from the tool schema and resolved to state.to_dict().2
Create a tool with injected state
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 withInjected, Injected[T], or bare Injected, the SDK:
- Strips that parameter from the schema sent to the LLM
- Captures the current
AgentStateat call time - 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:Best Practices
Prefer bare Injected or Injected[dict] for simple access
Prefer bare Injected or Injected[dict] for simple access
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.Never add injected params to tool docstrings
Never add injected params to tool docstrings
The LLM builds its understanding from the docstring. Documenting injected parameters confuses the model — describe only the user-facing parameters.
Use with_injection_context in tests
Use with_injection_context in tests
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.Keep injected parameters optional-safe
Keep injected parameters optional-safe
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.Related
Tools
Creating and registering tools with agents
Middleware
Intercept tool calls before and after execution

