Intermediate9 min
ToolRuntime: Unified Tool Context
ToolRuntime replaces InjectedState, InjectedStore, and InjectedConfig with a single typed parameter — giving tools access to state, context, store, stream_writer, and tool_call_id.
Quick Reference
- →ToolRuntime is the single parameter for tools to access all runtime services
- →runtime.state: current mutable graph state (short-term memory)
- →runtime.context: immutable per-run config (user IDs, API keys, feature flags)
- →runtime.store: cross-thread persistent storage (long-term memory)
- →runtime.stream_writer: emit custom streaming events to the frontend
- →runtime.tool_call_id: correlate tool invocations for debugging
Migration from InjectedState/Store/Config
Before and after — much cleaner with ToolRuntime
| Old Pattern | New Pattern | Benefit |
|---|---|---|
| InjectedState | runtime.state | Same object, cleaner access |
| InjectedStore | runtime.store | No separate annotation needed |
| InjectedConfig + config['configurable'] | runtime.context | Typed, validated, IDE-friendly |
| get_stream_writer() | runtime.stream_writer | Always available, no import |
| N/A | runtime.tool_call_id | New — correlate tool invocations |