LangChain/Advanced
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 PatternNew PatternBenefit
InjectedStateruntime.stateSame object, cleaner access
InjectedStoreruntime.storeNo separate annotation needed
InjectedConfig + config['configurable']runtime.contextTyped, validated, IDE-friendly
get_stream_writer()runtime.stream_writerAlways available, no import
N/Aruntime.tool_call_idNew — correlate tool invocations