← AUTOMATER NEWSROOM

Pydantic AI adds database-backed conversations and compaction events

Pydantic AI 2.77.0 gives Python agent teams SQLite, Postgres and MongoDB conversation stores and a way to see when an agent compacts its history.

Two routes from an agent conversation. One saves and reloads the conversation through a database. The other compacts model history and exposes start and end events.Two routes from an agent conversation. One saves and reloads the conversation through a database. The other compacts model history and exposes start and end events.
A database-backed store gives the application a saved conversation to reload. Compaction changes the history used by the model and gives the application events to observe the change.

Pydantic AI v2.77.0, released on November 27, gives Python developers two controls for agents that need to pick up work across runs. Pydantic AI Harness can now save conversations in SQLite, Postgres or MongoDB through first-party backends. The core framework also lets application code request history compaction and gives stream consumers events to observe it. For a coding agent that revisits the same investigation over several runs, the application can load the saved conversation from a database and decide when to shorten the history the model works with. Pydantic AI v2.77.0 release notes

Pydantic AI’s v2.77.0 release page on GitHub.
Pydantic’s GitHub release page for Pydantic AI v2.77.0. · Original source

Database choice changes what deletion does

The core ConversationStore previously shipped with an in-memory implementation. The three new backends live in pydantic_ai_harness.conversation_store. The implementation stores each distinct message JSON once, keyed by its SHA-256 hash, and sends large parts to the media store. Applications that already use the Pax session browser should check their imports. The older SqliteConversationStore in pydantic_ai_harness.step_persistence.conversations was renamed SqliteSessionStore, and the old name still imports with a HarnessDeprecationWarning. Conversation store implementation

Backend Save behavior Conversation deletion
SQLite or Postgres Writes the new entries and conversation record in one transaction Removes entries and messages that no other conversation uses
MongoDB Uses no transactions for these writes Removes only the conversation record

That difference matters if your application offers a delete button. Test deletion with two conversations that share messages, as they might after a fork. Include a message unique to the deleted conversation so you can verify which data the backend removes and which data it retains. Reload the surviving conversation to check that it still contains the shared messages. If your application promises erasure, inspect the remaining database records and any media stored separately. Conversation store implementation

Compaction becomes visible to the application

During a run, application code with access to RunContext can call request_compaction() and optionally supply a focus, such as preserving prior test failures and the files already ruled out. A capability’s compact_history() hook can serve that request. If no loaded capability implements the hook, the framework drops the request without a start event and warns once per run. Application code can also use compact=True to request compaction before the first model request. Core compaction implementation

Streaming applications can handle CompactionStartEvent and CompactionEndEvent. The end event carries a compaction record with information such as the reason, handler and message counts before and after. Code that exhaustively matches AgentStreamEvent needs to account for both event types, even if the application has yet to turn on compaction. During a run, the framework commits the compacted history when the model attempt is accepted. Check the run result’s compactions list to confirm which changes the run accepted. Core compaction implementation

Verify what survives a restart and a compaction

Start with a conversation whose first turn contains a decision the agent will need later. For a coding workflow, record a constraint such as keeping a legacy API response stable, alongside a recent test failure the agent still needs to fix. Save the conversation, restart the application process and reload it by its conversation ID. Verify that both details are present before asking the next question. This checks the persistence path independently of model behavior.

Then resume with a compaction capability configured and request compaction. Capture the start and end events, check the run result’s compaction record, and ask the agent what it would change next and which compatibility rule it has to preserve. Compare its answer with the original decision and verify that its plan accounts for the recent test failure. Message counts tell you how much history changed. The follow-up checks whether the resulting context still supports the work. If you already test this boundary in a coding CLI, reuse the same fixture in your Python application to compare what the agent can recover. How to save task state before Claude Code compacts

Sources

  1. Release v2.77.0 (2026-11-27) · pydantic/pydantic-ai · GitHub
  2. Add SQLite, Postgres and MongoDB backends for `ConversationStore`, and rename the Pax session store to `SqliteSessionStore` by DouweM · Pull Request #10473 · pydantic/pydantic-ai · GitHub
  3. Add a `compact_history()` capability hook, `RunContext.request_compaction()` and first-party compaction events by DouweM · Pull Request #11454 · pydantic/pydantic-ai · GitHub