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']
| Aspect | Old: config['configurable'] | New: Runtime[Context] |
|---|---|---|
| Type safety | Dict — no types, no autocomplete | Typed — full IDE support |
| Validation | None — runtime KeyError if missing | Validated at graph start |
| Access pattern | config['configurable']['user_id'] | runtime.context.user_id |
| Store access | Injected separately | runtime.store (built-in) |
| Stream writer | get_stream_writer() import | runtime.stream_writer (built-in) |
| Tool access | InjectedState, InjectedStore, InjectedConfig | Single 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.