How cobanov/pydantic-agent-template works
This is a small FastAPI template for an LLM chat agent, with a health endpoint and optional API-key authentication. The main workflow is an HTTP client sending a chat request, the chat route verifying the key and invoking the Pydantic AI agent, then returning the model output. Startup configures the app, creates database tables from the imported model metadata, and provides the agent an HTTP client dependency; the chat route does not persist conversations. Source excerpts establish these links, but do not show agent-side use of the HTTP client or database persistence.
Main entry points: chat.py Chat route · main.py FastAPI app · core.py Pydantic AI agent · health.py Health route
Components 13
API
- FastAPI app
app/main.py - Chat route
app/routers/chat.py - Health route
app/health.py - API-key check
app/auth.py - API schemas
app/schemas.py - Version config
app/config.py
Agent
- Agent dependencies
app/agent/context.py - Pydantic AI agent
app/agent/core.py - System prompt
app/agent/prompts.py
Database
- Async database
app/database.py - Conversation model
app/models.py
Other components
- HTTP client
- OpenAI model
Connections 15
- HTTP client → Chat route: sends request
app/routers/chat.py - Chat route → API-key check: checks key
app/routers/chat.py - Chat route → Agent dependencies: creates dependencies
app/routers/chat.py - Chat route → Pydantic AI agent: runs agent
app/routers/chat.py - Chat route → API schemas: uses request/response
app/routers/chat.py - Pydantic AI agent → Agent dependencies: declares dependency type
app/agent/core.py - Pydantic AI agent → System prompt: sets system prompt
app/agent/core.py - Pydantic AI agent → OpenAI model: configures model
app/agent/core.py - FastAPI app → Chat route: registers route
app/main.py - FastAPI app → Health route: registers route
app/main.py - FastAPI app → Async database: creates tables
app/main.py - FastAPI app → Conversation model: imports metadata model
app/main.py - Health route → API schemas: returns health schema
app/health.py - Health route → Version config: uses version
app/health.py - Async database → Conversation model: provides model base
app/models.py