LangGraph/Persistence
Intermediate11 min

Runtime & Context: Dependency Injection

The Runtime object and context_schema replace config['configurable'] as LangGraph's dependency injection system — typed access to state, store, context, and stream writer from any node or tool.

Quick Reference

  • Runtime[Context] provides typed dependency injection for nodes — access state, store, context, stream_writer
  • context_schema defines immutable per-run data (user IDs, API keys, feature flags) passed at invocation
  • ToolRuntime gives tools access to runtime.state, runtime.context, runtime.store, runtime.tool_call_id
  • Replaces the old config['configurable'] pattern — typed, validated, and IDE-friendly
  • Context is immutable during a run — use state for mutable per-step data
  • Works with both Graph API (StateGraph) and Functional API (@entrypoint)

Why Runtime Replaced config['configurable']

AspectOld: config['configurable']New: Runtime[Context]
Type safetyDict — no types, no autocompleteTyped — full IDE support
ValidationNone — runtime KeyError if missingValidated at graph start
Access patternconfig['configurable']['user_id']runtime.context.user_id
Store accessInjected separatelyruntime.store (built-in)
Stream writerget_stream_writer() importruntime.stream_writer (built-in)
Tool accessInjectedState, InjectedStore, InjectedConfigSingle ToolRuntime parameter
Migration required

config['configurable'] still works but is deprecated. Migrate to Runtime + context_schema for new code. The key benefit: your IDE can autocomplete runtime.context.user_id instead of guessing dict keys.