checkpointer
when creating an agent.
AgentState
to manage short term memory, specifically the conversation history via a messages
key.
Users can subclass AgentState
to add additional fields to the state.
This custom state can then be accessed via tools and dynamic prompt / model functions.
strategy
(e.g., keep the last maxTokens
) to use for handling the boundary.
To trim message history in an agent, use @[pre_model_hook
][create_agent] with the trim_messages
function:
RemoveMessage
.
For RemoveMessage
to work, you need to use a state key with add_messages
reducer.
The default AgentState
provides this.
To remove specific messages:
user
messageassistant
messages with tool calls to be followed by corresponding tool
result messages.pre_model_hook
][create_agent] with a prebuilt SummarizationNode
abstraction:
InjectedState
annotation.
This annotation hides the state from the tool signature (so the model doesn’t see it), but the tool can access it.