Skip to content

feat(memory): add MemoryCapability with SQLite backend#263

Open
mustafabozkaya wants to merge 5 commits into
pydantic:mainfrom
mustafabozkaya:feat/memory-capability
Open

feat(memory): add MemoryCapability with SQLite backend#263
mustafabozkaya wants to merge 5 commits into
pydantic:mainfrom
mustafabozkaya:feat/memory-capability

Conversation

@mustafabozkaya
Copy link
Copy Markdown

Summary

Add persistent memory capability for Pydantic AI agents. This is the first implementation of the Persistent key-value memory feature request.

What This Adds

New Capability: MemoryCapability

Provides five tools for persistent memory management:

  • memory_store — Save information with key, value, tags, and metadata
  • memory_retrieve — Full-text search across stored memories (FTS5)
  • memory_list — List entries with glob pattern and tag filtering
  • memory_delete — Remove an entry by key
  • memory_compact — Clean up old, rarely-accessed entries

Architecture

The implementation follows the established CodeMode capability pattern:

  • _abstract.py — AbstractMemoryBackend interface for custom backends
  • _capability.py — MemoryCapability (AbstractCapability subclass)
  • _models.py — Pydantic models (MemoryEntry, input schemas)
  • _sqlite.py — SQLiteMemoryBackend (default backend with FTS5)
  • _toolset.py — MemoryToolset (tool implementations)

Key Features

  • SQLite backend with FTS5 full-text search
  • AbstractMemoryBackend interface for custom storage engines
  • Tag-based filtering and glob pattern matching
  • Access tracking with automatic compaction
  • Lazy initialization of database connection
  • 18 tests covering models, backend, and edge cases

Usage

from pydantic_ai import Agent
from pydantic_ai_harness import MemoryCapability

agent = Agent('openai:gpt-5', capabilities=[MemoryCapability()])
result = agent.run_sync('Remember that my favorite color is blue')
result = agent.run_sync('What is my favorite color?')  # blue

Checklist

  • Follows CodeMode capability pattern
  • Ruff lint clean
  • 18 tests passing
  • README.md with examples
  • Abstract interface for extensibility

Closes #179

mustafa bozkaya added 5 commits May 31, 2026 12:10
Add persistent memory capability for Pydantic AI agents. This capability
provides five tools: memory_store, memory_retrieve, memory_list,
memory_delete, and memory_compact.

Key features:
- SQLite backend with FTS5 full-text search
- AbstractMemoryBackend interface for custom storage engines
- Tag-based filtering and glob pattern matching
- Access tracking and automatic compaction
- 18 tests covering models, backend, and edge cases

Implements: pydantic#179 (Persistent key-value memory)
Add guardrails capability for Pydantic AI agents. This capability
provides input and output validation using callable guards.

Key features:
- InputGuard: validate prompts before model requests
- OutputGuard: validate outputs after model processing
- GuardResult: fine-grained control (allow, block, replace, retry)
- llm_input_guard/llm_output_guard: factory helpers for LLM-based classification
- Fail-open on LLM errors (safe default)
- 20 tests covering primitives, integration, and LLM guards

Implements: pydantic#248 (prepackaged LLM guardrails)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant