Build stateful tools that persist data across agent turns by using a checkpointer to save the entire agent state and a shared database connection accessible to your tools, which can read and write based on conversation history stored in the state.
To build stateful tools that read from or write to a database across multiple agent turns, you need two components: a persistence layer for the agent's conversation state (checkpointer) and a shared resource (database connection) that your tools can access. The checkpointer saves the entire agent state between turns, including messages and any custom fields, allowing the agent to resume exactly where it left off[citation:1]. The tools can then use a shared database connection passed via configuration or dependency injection to store user preferences, session data, or any other information that must persist across turns.