Alpha Notice: These docs cover the v1-alpha release. Content is incomplete and subject to change.For the latest stable version, see the current LangGraph Python or LangGraph JavaScript docs.
- By mutability:
- Static context: Immutable data that doesn’t change during execution (e.g., user metadata, database connections, tools)
- Dynamic context: Mutable data that evolves as the application runs (e.g., conversation history, intermediate results, tool call observations)
- By lifetime:
- Runtime context: Data scoped to a single run or invocation
- Cross-conversation context: Data that persists across multiple conversations or sessions
Runtime context vs LLM context
Runtime context refers to local context: data and dependencies your code needs to run. It does not refer to:
- The LLM context, which is the data passed into the LLM’s prompt.
- The “context window”, which is the maximum number of tokens that can be passed to the LLM.
Context type | Description | Mutability | Lifetime | Access method |
---|---|---|---|---|
Static runtime context | User metadata, tools, db connections passed at startup | Static | Single run | context argument to invoke /stream |
Dynamic runtime context (state) | Mutable data that evolves during a single run | Dynamic | Single run | LangGraph state object |
Dynamic cross-conversation context (store) | Persistent data shared across conversations | Dynamic | Cross-conversation | LangGraph store |
Static runtime context
Static runtime context represents immutable data like user metadata, tools, and database connections that are passed to an application at the start of a run via thecontext
argument to invoke
/stream
. This data does not change during execution.
New in LangGraph v0.6:
context
replaces config['configurable']
Runtime context is now passed to the context
argument of invoke
/stream
,
which replaces the previous pattern of passing application configuration to config['configurable']
.- This is the invocation of the agent or graph. The
invoke
method runs the underlying graph with the provided input. - This example uses messages as an input, which is common, but your application may use different input structures.
- This is where you pass the runtime data. The
context
parameter allows you to provide additional dependencies that the agent can use during its execution.
- See Agents for details.
The
Runtime
object can be used to access static context and other utilities like the active store and stream writer.
See the [Runtime][langgraph.runtime.Runtime] documentation for details.Dynamic runtime context
Dynamic runtime context represents mutable data that can evolve during a single run and is managed through the LangGraph state object. This includes conversation history, intermediate results, and values derived from tools or LLM outputs. In LangGraph, the state object acts as short-term memory during a run.Example shows how to incorporate state into an agent prompt.State can also be accessed by the agent’s tools, which can read or update the state as needed. See tool calling guide for details.
- Define a custom state schema that extends
AgentState
orMessagesState
. - Pass the custom state schema to the agent. This allows the agent to access and modify the state during execution.
Turning on memory
Please see the memory guide for more details on how to enable memory. This is a powerful feature that allows you to persist the agent’s state across multiple invocations. Otherwise, the state is scoped only to a single run.