Skip to content

PAIS — Pydantic AI Server

PAIS: Pydantic AI Server

The Python agent framework (PAIS) provides the runtime components for AI agents, built on Pydantic AI as the core agent runtime.

Design Principles

  1. Keep It Simple - Thin wrapper around Pydantic AI, minimal abstractions
  2. HTTP-First - All components communicate via HTTP
  3. OpenAI Compatible - Standard /v1/chat/completions API
  4. Kubernetes Native - Environment variable configuration, health probes

Module Structure

pydantic-ai-server/
├── pais/
│   ├── server.py       # AgentServer, create_agent_server(), HTTP routes
│   ├── serverutils.py  # AgentDeps, AgentCard, RemoteAgent, AgentServerSettings
│   ├── tools.py        # DelegationToolset, string-mode handler
│   ├── memory.py       # LocalMemory, RedisMemory, NullMemory
│   └── telemetry.py    # OpenTelemetry tracing, metrics, context propagation
├── tests/              # Test suite (96+ unit tests)
└── Dockerfile          # Container image

Component Relationships

Key Environment Variables

VariableRequiredDescription
AGENT_NAMEYesAgent name
MODEL_API_URLYesLLM API base URL (auto-appends /v1)
MODEL_NAMEYesModel name
AGENT_INSTRUCTIONSNoSystem prompt
AGENT_DESCRIPTIONNoAgent description for A2A card
MCP_SERVERSNoComma-separated MCP server names
MCP_SERVER_<NAME>_URLNoURL for each MCP server
PEER_AGENTSNoComma-separated peer agent names
PEER_AGENT_<NAME>_CARD_URLNoURL for each peer agent
MEMORY_TYPENolocal (default) or redis
MEMORY_ENABLEDNoEnable/disable memory (default: true)
MEMORY_CONTEXT_LIMITNoMax history events (default: 6)
DEBUG_MOCK_RESPONSESNoJSON array for mock testing

Architecture

The KAOS Agent wraps pydantic_ai.Agent to add:

  • Memory persistence: KAOS memory events bridged to Pydantic AI message_history
  • Sub-agent delegation: Registered as delegate_to_{name} tool functions
  • MCP tools: Passed as MCPServerStreamableHTTP toolsets
  • Telemetry: Custom OTel spans for agent runs, tool calls, delegation
  • HTTP surface: OpenAI-compatible /v1/chat/completions endpoint

The agentic loop (tool calling, retries, streaming) is handled entirely by Pydantic AI.

Further Reading

  • Agent — Core agent class and delegation
  • Agentic Loop — How Pydantic AI handles tool calling
  • Memory — Session storage and event tracking
  • MCP Tools — Tool server integration
  • Server — HTTP API and configuration

Released under the Apache 2.0 License.