Part of Pydantic Deep Agents — the open-source Claude Code alternative & Python agent framework. Use this library standalone, or get everything wired together in one create_deep_agent() call.
Summarization for Pydantic AI keeps your Pydantic AI agents running through long conversations without ever exceeding model context limits. Choose intelligent LLM summarization or zero-cost sliding-window trimming — both preserve tool-call pairs.
Use Cases
What You Want to Build
How This Library Helps
Long-Running Agent
Automatically compress history when context fills up
Customer Support Bot
Preserve key details while discarding routine exchanges
The agent can call compact_conversation(focus="preserve API design decisions") to trigger compression with a focus topic. Compression is deferred to the next model request.
from pydantic_ai import Agent
from pydantic_ai_summarization import create_summarization_processor
processor = create_summarization_processor(
trigger=("tokens", 100000),
keep=("messages", 20),
)
agent = Agent("openai:gpt-4.1", history_processors=[processor])
Available Processors
Processor
LLM Cost
Latency
Context Preservation
ContextManagerCapability
Per compression
Low tracking
Intelligent summary + tool truncation
SummarizationProcessor
High
High
Intelligent summary
SlidingWindowProcessor
Zero
~0ms
Discards old messages
LimitWarnerProcessor
Zero
~0ms
Full history + warning injection
Intelligent Summarization
Uses an LLM to create summaries of older messages:
from pydantic_ai_summarization import create_summarization_processor
processor = create_summarization_processor(
trigger=("tokens", 100000), # When to summarize
keep=("messages", 20), # What to keep
)
Zero-Cost Sliding Window
Simply discards old messages — no LLM calls:
from pydantic_ai_summarization import create_sliding_window_processor
processor = create_sliding_window_processor(
trigger=("messages", 100), # When to trim
keep=("messages", 50), # What to keep
)
Limit Warnings
Warn the agent before requests, context usage, or total tokens hit a cap:
Zero to production AI app in 30 minutes — FastAPI + Next.js 15, RAG, 6 AI frameworks.
Want it all wired together?Pydantic Deep Agents ships every library above integrated — planning, filesystem, subagents, memory, context management, and guardrails — behind a single function call. Browse everything at oss.vstorm.co.
Contributing
git clone https://github.com/vstorm-co/summarization-pydantic-ai.git
cd summarization-pydantic-ai
make install
make test # 100% coverage required
Star History
If this library saved you from wiring an agent harness by hand — give it a ⭐. It's the single biggest thing that helps the project grow.
We're Vstorm — an Applied Agentic AI Engineering Consultancy with 30+ production agent implementations. Pydantic Deep Agents is what we build them with.