--- id: summarization-pydantic-ai version: "0.1.11" license: MIT license_treatment: permissive maintenance: active --- # summarization-pydantic-ai — Automatic Conversation Summarization and History Management for Pydantic AI License: permissive · Maintenance: active · Downloads: 183.9K/mo ## What it is and what it does This library extends pydantic-ai-slim agents with automatic conversation history management, solving the problem of long-running agents hitting model context limits. It offers two strategies: intelligent LLM-based summarization that compresses older messages while preserving meaning, or a zero-cost sliding window that simply discards old messages. Both strategies protect tool call/response pairs from being broken mid-exchange. The library integrates via Pydantic AI's native Capabilities API, providing automatic token tracking, threshold-based compression triggers, and optional agent-controlled compression through a compact_conversation tool. You can configure triggers by message count, token count, or fraction of context window, and choose what to keep using the same flexible trigger system. It also offers standalone processors for custom integration and a LimitWarnerCapability to alert agents before hitting iteration or token caps. Use it for: - Long-running customer support bots that need to preserve key details across hundreds of exchanges without exceeding context limits. - Code assistant agents that keep recent code context while summarizing older design discussions to stay within token budgets. - High-throughput applications using zero-cost sliding window to trim history with minimal latency overhead. - Cost-sensitive deployments choosing between intelligent summarization (higher quality, LLM cost) and sliding window (free, lossy). - Multi-turn agents that let the model decide when to compress via the compact_conversation tool with a focus topic. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Manages conversation history for Pydantic AI agents by automatically summarizing or trimming old messages to prevent exceeding model context limits while preserving tool call/response pairs. Yes, if you are building Pydantic AI agents that run for more than a few turns or handle long documents. The library is actively maintained, has no known vulnerabilities, and solves a real problem with two pragmatic strategies. Install with conditions only if you need accurate token counting—add the tiktoken extra for that. The MIT license poses no restrictions. ## Install pip install summarization-pydantic-ai uv add summarization-pydantic-ai poetry add summarization-pydantic-ai ## Installing summarization-pydantic-ai Before you install: Low friction: single runtime dependency (pydantic-ai-slim), pure Python wheel, active maintenance with recent release. Supports Python 3.10–3.13. License in practice: MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal attribution requirements. Quickstart: pip install summarization-pydantic-ai from pydantic_ai import Agent from summarization_pydantic_ai import ContextManagerCapability agent = Agent( "anthropic:claude-sonnet-4-6", capabilities=[ContextManagerCapability(max_tokens=100_000)], ) result = await agent.run("Hello!") Requires Python 3.10 or later; optional tiktoken dependency for accurate token counting. Verify before relying: - Whether the library auto-detects context window size for all supported model providers or only specific ones. - Performance characteristics of intelligent summarization versus sliding window in production workloads. - Behavior when tool outputs exceed max_tool_output_tokens during truncation. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 183.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pydantic ai context management, conversation history summarization, llm context window overflow, long-running agent memory, sliding window conversation trimming, token limit handling, agent conversation compression, agent-framework, context-management, llm-optimization [View on SkillFed](https://skillfed.io/packages/summarization-pydantic-ai) · [View on PyPI](https://pypi.org/project/summarization-pydantic-ai/)