Example: using Postgres checkpointer
checkpointer.setup()
the first time you’re using Postgres checkpointerExample: using [MongoDB](https://pypi.org/project/langgraph-checkpoint-mongodb/) checkpointer
Example: using [Redis](https://pypi.org/project/langgraph-checkpoint-redis/) checkpointer
checkpointer.setup()
the first time you’re using Redis checkpointerExample: using Postgres store
store.setup()
the first time you’re using Postgres storeExample: using [Redis](https://pypi.org/project/langgraph-checkpoint-redis/) store
store.setup()
the first time you’re using Redis storeInMemoryStore
is a store that stores data in memory. In a production setting, you would typically use a database or other persistent storage. Please review the store documentation for more options. If you’re deploying with LangGraph Platform, the platform will provide a production-ready store for you.put
method. Please see the BaseStore.put API reference for more details.users
namespace to group user data.get_store
function is used to access the store. You can call it from anywhere in your code, including tools and prompts. This function returns the store that was passed to the agent when it was created.get
method is used to retrieve data from the store. The first argument is the namespace, and the second argument is the key. This will return a StoreValue
object, which contains the value and metadata about the value.store
is passed to the agent. This enables the agent to access the store when running tools. You can also use the get_store
function to access the store from anywhere in your code.InMemoryStore
is a store that stores data in memory. In a production setting, you would typically use a database or other persistent storage. Please review the store documentation for more options. If you’re deploying with LangGraph Platform, the platform will provide a production-ready store for you.UserInfo
class is a TypedDict
that defines the structure of the user information. The LLM will use this to format the response according to the schema.save_user_info
function is a tool that allows an agent to update user information. This could be useful for a chat application where the user wants to update their profile information.get_store
function is used to access the store. You can call it from anywhere in your code, including tools and prompts. This function returns the store that was passed to the agent when it was created.put
method is used to store data in the store. The first argument is the namespace, and the second argument is the key. This will store the user information in the store.user_id
is passed in the config. This is used to identify the user whose information is being updated.Long-term memory with semantic search
strategy
(e.g., keep the last maxTokens
) to use for handling the boundary.
pre_model_hook
with the trim_messages
function:Full example: trim messages
RemoveMessage
. For RemoveMessage
to work, you need to use a state key with add_messages
reducer, like MessagesState
.
To remove specific messages:
user
messageassistant
messages with tool calls to be followed by corresponding tool
result messages.Full example: delete messages
pre_model_hook
with a prebuilt SummarizationNode
abstraction:InMemorySaver
is a checkpointer that stores the agent’s state in memory. In a production setting, you would typically use a database or other persistent storage. Please review the checkpointer documentation for more options. If you’re deploying with LangGraph Platform, the platform will provide a production-ready checkpointer for you.context
key is added to the agent’s state. The key contains book-keeping information for the summarization node. It is used to keep track of the last summary information and ensure that the agent doesn’t summarize on every LLM call, which can be inefficient.checkpointer
is passed to the agent. This enables the agent to persist its state across invocations.pre_model_hook
is set to the SummarizationNode
. This node will summarize the message history before sending it to the LLM. The summarization node will automatically handle the summarization process and update the agent’s state with the new summary. You can replace this with a custom implementation if you prefer. Please see the create_react_agent API reference for more details.state_schema
is set to the State
class, which is the custom state that contains an extra context
key.Full example: summarize messages
context
fieldSummarizationNode
).call_model
node.