How to build a production agentic app, the Pydantic Way
Blog post from Pydantic
Marcelo Trylesinski, a maintainer of several Python projects, shares an in-depth guide on building an agentic application using the Pydantic Stack, leveraging tools like FastAPI for web framework, Pydantic AI for constructing agents, and Pydantic Logfire for application observability. The tutorial highlights the use of Pydantic AI's flexibility to work with various providers without code changes and its focus on type safety and structured outputs. To construct an agent, Marcelo suggests using Pydantic AI, which automates the agentic loop and supports provider-specific features. The post walks through setting up the environment, coding a basic agent, and enhancing it with Logfire for telemetry insights. It also explores using tools within Pydantic AI to extend the agent's capabilities, such as integrating external API calls, and discusses various methods to expose the agent, including as a CLI tool, web chat UI, or FastAPI endpoint. Testing is addressed through networkless testing with VCR to record and replay network calls, ensuring reliable testing without network reliance. Additionally, Pydantic Evals is introduced for evaluating the agent's effectiveness in subjective areas like humor and helpfulness. The comprehensive guide, with code available on GitHub, aims to help developers create robust agentic applications with systematic testing and evaluation measures.