Difference between InjectedStore, InjectedState, ToolRuntime, Runtime Context

Hello there!
Can you please explain the difference between InjectedStore, InjectedState, ToolRuntime, Runtime Context ?
im really confused

hi @Sanctious

good question, thanks!

  • InjectedState (tools): An annotation to inject the current graph state (or a specific field from it) into a tool argument. It’s hidden from the LLM schema and filled in by the system right before the tool executes.

  • InjectedStore (tools): An annotation to inject a graph BaseStore (persistent memory) into a tool argument, so tools can read/write cross-session data. Also hidden from the LLM schema; requires compiling the graph with a store.

  • ToolRuntime (tools; LangChain ToolNode integration): A single parameter that gives tools access to state, context, store, stream_writer, config, and tool_call_id in one object. You can add runtime: ToolRuntime in a tool signature (no Annotated needed). This is defined on the LangChain side of the ToolNode and used with LangGraph-powered agents.

  • Runtime context (nodes/models): The run-scoped Runtime object that LangGraph passes to your node functions and dynamic model selectors. Its .context field holds immutable per-run data (e.g., user_id, db handles), and it also carries .store, .stream_writer, and .previous.

When to use which

  • Use InjectedState when a tool needs the current graph state (chat history, computed fields). You can inject the whole state or a specific key: Annotated[dict, InjectedState("messages")].

  • Use InjectedStore when a tool must read/write persistent memory. Be sure to compile the graph with a store, or you’ll get an error.

  • Use ToolRuntime (LangChain ToolNode) if you prefer one consolidated parameter in your tool to access state, context, store, config, stream writer, and tool_call_id without juggling multiple annotations.

  • Use Runtime context inside nodes and dynamic model resolvers to consult per-run information (for example, choosing a model based on runtime.context.user_id, or looking up data via runtime.store).

2 Likes

Appreciate it :heart:

1 Like