examples/showcases/pydantic-ai-todos/README.md
This is a starter template for building AI agents using PydanticAI and CopilotKit. It provides a modern Next.js application with an integrated AI assistant that helps you manage a todo board with three columns: Todo, In-Progress, and Done.
Note: This repository ignores lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb) to avoid conflicts between different package managers. Each developer should generate their own lock file using their preferred package manager. After that, make sure to delete it from the .gitignore.
# Using pnpm (recommended)
pnpm install
# Using npm
npm install
# Using yarn
yarn install
# Using bun
bun install
Note: This will automatically setup the Python environment as well.
If you have manual isseus, you can run:
shnpm run install:agent
Create a .env file inside the agent folder with the following content:
# Required: Get from https://platform.openai.com/api-keys
OPENAI_API_KEY=sk-...your-openai-key-here...
# Optional: For agent observability
# Sign up at https://logfire.pydantic.dev
# Create token: https://logfire.pydantic.dev/docs/how-to-guides/create-write-tokens/
LOGFIRE_TOKEN=...your-logfire-token...
# Using pnpm
pnpm dev
# Using npm
npm run dev
# Using yarn
yarn dev
# Using bun
bun run dev
This will start both the UI and agent servers concurrently.
This app connects three technologies to create a full-stack agentic todo application:
PydanticAI (agent/src/agent.py) - Python AI agent framework
agent/src/tools.py): add_todos, update_todo, delete_todos, etc.agent/src/models.py) for type-safe stateAG-UI (agent/src/main.py) - Bridge between Python and web
agent.to_ag_ui() converts PydanticAI agent to FastAPI server (port 8000)StateSnapshotEventCopilotKit (src/app/page.tsx, src/app/api/copilotkit/route.ts) - React chat UI
useCoAgent() creates bidirectional state sync with backendHttpAgent connects to Python AG-UI servergraph TD
A[User Input] --> B[CopilotKit UI
src/app/page.tsx]
B --> C[useCoAgent Hook
State Sync]
C --> D[Next.js API Route
src/app/api/copilotkit/route.ts]
D --> E[HttpAgent
:8000 proxy]
E --> F[AG-UI Server
agent/src/main.py]
F --> G[PydanticAI Agent
agent/src/agent.py]
G --> H[Tools
agent/src/tools.py]
H --> I[StateSnapshotEvent]
I --> F
F --> E
E --> D
D --> C
C --> B
B --> J[UI Update]
style A fill:#e1f5ff
style J fill:#e1f5ff
style B fill:#a8daff
style C fill:#a8daff
style D fill:#a8daff
style F fill:#ffcba8
style G fill:#ffcba8
style H fill:#ffcba8
style I fill:#ffd700
/api/copilotkitHttpAgent to Python backend (localhost:8000)add_todos)StateSnapshotEvent with updated stateuseCoAgent updates React UI automaticallysrc/app/page.tsx - CopilotKit integration & state syncsrc/app/api/copilotkit/route.ts - Proxy to Python backendagent/src/agent.py - PydanticAI agent definitionagent/src/tools.py - Todo management toolsagent/src/models.py - Shared data modelsagent/src/main.py - AG-UI server setupThe following scripts can also be run using your preferred package manager:
dev - Starts both UI and agent servers in development modedev:debug - Starts development servers with debug logging enableddev:ui - Starts only the Next.js UI serverdev:agent - Starts only the PydanticAI agent serverbuild - Builds the Next.js application for productionstart - Starts the production serverlint - Runs ESLint for code lintinginstall:agent - Installs Python dependencies for the agentFeel free to submit issues and enhancement requests! This starter is designed to be easily extensible.
This project is licensed under the MIT License - see the LICENSE file for details.
If you see "I'm having trouble connecting to my tools", make sure:
If you encounter Python import errors:
cd agent
uv sync
uv run src/main.py