Conversation persistence for pydantic-ai-app-factory, backed by pydantic-ai-harness StepPersistence
pip install pydantic-ai-conversations Copy PIP instructions
pydantic-ai-conversations adds persistent, multi-turn conversations to an app built with pydantic-ai-app-factory. Messages are stored through pydantic-ai-harness's Step Persistence, the harness's durable record of an agent run. This package adds what a chat product needs on top: a registry that lists, titles, deletes, and isolates conversations per tenant; a capability that loads the stored conversation into each run and records each turn, so retries, edits, and tool approvals are ordinary turns; and the /conversations routes a frontend reads.
from pydantic_ai_app_factory import UserContext, create_agent, create_agent_app from pydantic_ai_conversations import ConversationsFeature from pydantic_ai_conversations.sqlite import SqliteConversationRegistry, SqliteConversationStepStore def auth() -> UserContext: return UserContext(user_id='alice', tenant_id='t1') conversations = ConversationsFeature( registry=SqliteConversationRegistry('app.db'), step_store=SqliteConversationStepStore('app.db'), ) agent = create_agent('test', instructions='You are a support assistant.') app = create_agent_app(agent, auth=auth, features=[conversations]) Run it with fastapi dev. A conversation starts with the first request that names a conversation_id; the id is yours to choose. Every later request names the turn (one agent run) it builds on, through the previous_run_id the previous answer returned:
curl -s http://127.0.0.1:8000/run \ -H 'Content-Type: application/json' \ -d '{"prompt": "My printer is offline.", "conversation_id": "c1"}' | jq -r .run_id curl -s http://127.0.0.1:8000/run \ -H 'Content-Type: application/json' \ -d '{"prompt": "It is a Brother.", "conversation_id": "c1", "extras": {"previous_run_id": " "}}' GET /conversations lists the caller's conversations and GET /conversations/c1 returns the transcript. Over /chat, the streaming endpoint for Vercel AI SDK frontends, the chat id is the conversation, previousRunId names the previous turn, and the streamed message's id is the run id to send back.
Who the caller is, and whether they may act in a tenant or case, is the app's AuthProvider. Sanitising the messages a client sends is the endpoint's job; the app factory does it. Message durability is the harness's. This package enforces one thing: a conversation is reachable only inside the partition its caller's identity maps to.
The quick start uses a test model, a stub auth function, and SQLite. The documentation covers the rest.
Python 3.11 or later. The package depends on a narrow range of pydantic-ai-app-factory and pydantic-ai-harness versions, and the harness range fixes the pydantic-ai version with it; Operations says why, and pyproject.toml has the current ranges.
Apache-2.0. Set up with make install, run make all before a pull request, and see AGENTS.md for the module layout and boundaries.
All 2 files in this release have provenance metadata.
agent conversations fastapi persistence pydantic-ai
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
All 2 files in this release have been uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




