Skip to content

Framework Update: Pydantic AI v2.77.0

Nov 29, 20266 min
TL;DRPydantic AI v2.77.0 turns compaction from something that just happens to you into something you can trigger yourself: a new compact_history hook, a request_compaction method, and a matching pair of start/end events. It also gives ConversationStore SQLite, Postgres and MongoDB backends, and tightens how SubAgents loads sub-agent definitions from disk — directories below operator authority are no longer read in automatically.

Look up & save

Loading dictionary…

中文版

Release Info

ItemValue
FrameworkPydantic AI
Versionv2.77.0
Previous versionv2.76.0
Released2026-11-27
Release Notesv2.77.0
GitHubpydantic/pydantic-ai
Stars21.4k

Why This Version Matters

Yesterday's release (2.76.0) changed how result.conversation behaves under a history-trimming capability, but the application layer still had no visibility into when compaction actually happened or what it did — a capability like SummarizingCompaction decided on its own whether and how much to summarize, and you just had to accept the result. This release opens that up: a new compact_history() capability hook and RunContext.request_compaction() let your own code demand a compaction right now, instead of waiting for a capability to decide the history has gotten long enough. The matching CompactionStartEvent/CompactionEndEvent make compaction visible in the event stream, so you can surface a status in the UI or just log when it happened.

The same release also shores up durability on the infrastructure side: ConversationStore gains SQLite, Postgres and MongoDB backends (it used to lean on in-memory storage or whatever you wired up yourself), and the default FallbackCompaction chain now recovers automatically from UnexpectedModelBehavior instead of letting a failed summarization take down the whole run. Separately, SubAgents tightens how it loads sub-agent definition files from disk — files in directories below operator authority no longer get read in as trusted instructions, which closes off a real gap for anyone pointing a sub-agent at someone else's repository.

Pydantic AI v2.77.0: compaction goes from passive to triggerable
Pydantic AI v2.77.0: compaction goes from passive to triggerableCompaction used to happen only when a capability decided to; compact_history, as a hook, lets the application trigger it and see it happen. Before History keeps growing Capability decides no visibility into timing or outcome Compaction succeeds or fails app only finds out after the fact After 2.77.0 History keeps growing or code decides it's time Call request_compaction() or a compact_history hook fires Compaction runs CompactionStartEvent, auto-recovers App sees the result CompactionEndEvent fires

Simplified — only the affected compaction-trigger path is shown. A run that never calls request_compaction and has no compact_history hook behaves as before.

Key Changes

  • compact_history() hook + request_compaction(): a capability can implement a compact_history() hook, and RunContext gains request_compaction() so your own code can demand a compaction → no more waiting for a built-in capability to decide history is "long enough"; trigger it at a point you actually know about, like right after a tool call or when entering a new phase
  • CompactionStartEvent/CompactionEndEvent: only emitted when something calls request_compaction() or a compact_history hook exists, so an existing run's stream is unaffected → surface a "cleaning up history" status in the UI, or just log when compaction happened
  • Three new ConversationStore backends: SQLite, Postgres, MongoDB → the store used to lean on in-memory storage or a custom integration; now the framework ships database-backed conversation storage out of the box
  • SubAgents tightens disk-definition loading: sub-agent definition files in a directory below operator authority — such as an entire workspace at authority='none' — are no longer loaded; they're skipped with a warning instead. A working_directory= delegate's workspace authority is lowered to whatever the parent grants that directory → avoids treating a file in someone else's repository as a trusted sub-agent instruction
  • FallbackCompaction auto-recovery: the default FallbackCompaction chain now recovers from UnexpectedModelBehavior automatically instead of letting a failed compaction abort the whole run → one more layer of durability, where a compaction failure no longer means a task failure
  • thinking_summary: Claude models on Anthropic and Bedrock can now return readable, summarized thinking instead of an empty thinking block (via anthropic_thinking_display/bedrock_thinking_display setting thinking.display: 'summarized') → another option if you want to see the model's reasoning without the raw thinking stream, though it can add latency before the first text token

Breaking Changes

There's no standalone "Breaking Changes" section this time, but a few items under the official " Compatibility Notes" change existing code's behavior directly:

  • Pax's session store is renamed: SqliteConversationStore/ConversationConflict (in pydantic_ai_harness.step_persistence.conversations) become SqliteSessionStore/SessionConflict
    • Impact: the old names still import, but now raise HarnessDeprecationWarning; a setup that turns warnings into errors will fail outright
  • Skills(...)'s default behavior changes: a missing or unreadable skill library or skill is now skipped with a warning by default instead of failing the whole run
    • Impact: to keep the old "a missing directory fails the run" behavior, pass missing_directories='error' explicitly; SkipReason gains a new value, so code doing an exhaustive match over it stops type-checking
  • SubAgents no longer loads sub-agent definition files from directories below operator authority
    • Impact: any setup relying on "every file in the workspace gets read as a sub-agent definition" now has those files skipped with a warning; directories you still want read need an entry in path_authority
  • Carried over from 2.76.0 as a reminder: with a history-trimming capability in place, result.conversation now re-summarizes the full history on every run instead of carrying forward just the last summary

Migration Guide

Upgrading from 2.76.x to 2.77.0

pip install --upgrade pydantic-ai==2.77.0
# Before: importing the old names from pydantic_ai_harness.step_persistence.conversations
from pydantic_ai_harness.step_persistence.conversations import (
    SqliteConversationStore,
    ConversationConflict,
)

# After: use the new names (the old ones still work, but raise HarnessDeprecationWarning)
from pydantic_ai_harness.step_persistence.conversations import (
    SqliteSessionStore,
    SessionConflict,
)
# Before: a missing skill directory was expected to make Skills(...) fail outright
skills = Skills(libraries=[missing_library_path])  # 2.76.x and earlier: raises

# After: the default is now to skip and warn; opt back into the old behavior explicitly
skills = Skills(libraries=[missing_library_path])  # 2.77.0: skips with a warning
skills = Skills(libraries=[missing_library_path], missing_directories="error")  # old behavior
# New capability: trigger a compaction yourself, without waiting for a capability to decide
async def my_tool(ctx: RunContext[...]) -> str:
    await ctx.request_compaction()
    return "compaction requested"

Everything else — the new ConversationStore backends, thinking_summary, FallbackCompaction's auto-recovery — is additive and doesn't affect existing code unless you opt in.

Comparison With Other Frameworks

Turning compaction into a first-class, hookable, event-emitting mechanism is still something only Pydantic AI is doing — LangGraph's memory/checkpoint updates have stayed focused on stacking features at the storage layer itself, and CrewAI's recent releases are still mostly bug fixes and small features on individual tools. Pydantic AI's last two releases — 2.76.0's hot-swappable realtime tools, and this release's compaction hook — show a consistent direction: behavior that used to be fixed at connection setup, or decided silently by a capability with no visibility for the developer, keeps getting pulled apart into interfaces you can intervene in and observe at runtime.

Today's Takeaway

I used to assume compaction was the capability's own business — whichever capability you picked, you accepted its timing and its summarization style, and the developer just got handed the result. Seeing request_compaction() and a matching start/end event pair made it clear that compaction timing is itself a kind of runtime state an application can decide on, not a hidden implementation detail buried inside the framework. It's the same move as UpdateTools from yesterday, really — taking behavior that used to be bolted to a lifecycle (a connection, a capability) and pulling it out into its own controllable interface.

References