---
title: >-
  A production-ready full-stack template for AI agents with Pydantic AI and
  Logfire
description: >-
  An open-source CLI that generates production-ready FastAPI and Next.js apps
  with Pydantic AI agents, WebSocket streaming, auth, and Logfire tracing built
  in.
date: '2026-06-24'
authors:
  - Antoni Kozelski
categories:
  - Pydantic AI
  - Open Source
  - Vstorm
canonical: 'https://pydantic.dev/articles/full-stack-ai-agent-template-pydantic-ai'
---

> Markdown version of [A production-ready full-stack template for AI agents with Pydantic AI and Logfire](https://pydantic.dev/articles/full-stack-ai-agent-template-pydantic-ai) — the canonical HTML page.
>
> By Antoni Kozelski · 2026-06-24 · Pydantic AI, Open Source, Vstorm
>
> Related: [When agents build agents](https://pydantic.dev/articles/when-agents-build-agents.md) · [The average run is lying to you](https://pydantic.dev/articles/logfire-agents-llms-view.md)
>
> All articles: [/articles.md](https://pydantic.dev/articles.md) · Site index: [/llms.txt](https://pydantic.dev/llms.txt)

---

:::note{title="Guest post"}
This is a guest post by Antoni Kozelski, CEO of [Vstorm](https://vstorm.co/), an AI engineering company building production agents on Pydantic AI and Logfire. The views and the open-source template are their own.
:::

Every AI application needs the same foundations: authentication logic, real-time streaming, conversation persistence (handled by a database), observability, deployment, and CI/CD pipelines. These are essential building blocks.

And yet weeks are spent on scaffolding before you can write a single line of business logic.

This Pydantic AI and Pydantic Logfire backed open-source project sets out to fix that chokepoint once and for all. Meet the [full-stack-ai-agent-template](https://github.com/vstorm-co/full-stack-fastapi-nextjs-llm-template), an open-source CLI tool that generates production-ready full-stack applications combining FastAPI, Next.js 15, and your choice of Pydantic AI or LangChain for AI agents. One command gives you WebSocket streaming, JWT authentication, database setup with Alembic migrations, Redis caching, Logfire tracing, and Docker deployment.

Here is our breakdown of an all too common chokepoint, and how we integrated Pydantic AI and Pydantic Logfire into the open source. You can read the [full write-up on our production-ready template for AI/LLM applications](https://vstorm.co/agentic-ai/production-ready-template-for-ai-llm-applications-fastapi-next-js-20-integrations/), but here are the highlights.

## Because every AI project starts the same way

Building an AI application is not just about wrapping an OpenAI or Anthropic API. When a user asks your Pydantic AI powered chatbot a question, you need to:

1. **Authenticate the request:** JWT validation, refresh tokens, or API keys.
2. **Stream the response:** WebSocket connections so users see text as it generates.
3. **Handle tool calls:** modern agents using Pydantic AI or LangChain call tools, and users need transparency.
4. **Persist conversations:** PostgreSQL or MongoDB storage so users continue where they left off.
5. **Monitor everything:** Logfire traces, Sentry errors, and Prometheus metrics for production visibility.

Each requirement demands infrastructure. JWT authentication means secure password hashing with bcrypt, token generation, refresh logic, and HTTP-only cookies. WebSocket streaming means connection lifecycle management, graceful disconnection handling, and event serialization. Database persistence means SQLAlchemy models, Alembic migrations, and the repository pattern. Observability means OpenTelemetry instrumentation across FastAPI, asyncpg, Redis, and Pydantic AI.

Teams can spend three months building this scaffold before writing their first AI feature. Startups burn runway on solving these problems. Enterprises pay consulting fees for boilerplate code that every project needs.

This was the pain we set out to eliminate with open-source tooling.

### Framework choice: Pydantic AI vs LangChain

Both frameworks are supported because they serve different needs.

[Pydantic AI](https://pydantic.dev/pydantic-ai) is our recommended choice for new projects. Built by the [Pydantic](https://pydantic.dev/) team, it offers full type safety with Pyright strict mode, native Logfire integration for observability, and a simpler mental model than graph-based frameworks. Its `iter()` method provides first-class streaming support with access to every event the model produces: text deltas, tool calls, and results.

LangChain makes sense when you need its ecosystem: the extensive tool library, LangSmith for tracing and evaluation, or familiarity for teams already using it.

The generated code structure is identical for both. Your FastAPI routes and business logic stay the same regardless of whether you choose Pydantic AI or LangChain.

### Logfire observability from day one

[Pydantic Logfire](https://pydantic.dev/logfire) is integrated throughout the stack because debugging production AI applications is hard. When a user reports "the chatbot gave a weird answer," you need to see exactly what happened.

The FastAPI lifespan handler configures instrumentation for every subsystem: FastAPI requests with full request and response bodies, PostgreSQL queries via asyncpg with SQL and parameters, Redis cache operations, external HTTP calls via HTTPX, and Pydantic AI agent reasoning including tool calls and model responses.

Every request gets a unique ID that flows through logs, traces, and error reports. When something fails, you see the complete picture: the user's message, the Pydantic AI agent's reasoning, the tool calls, the PostgreSQL queries, and the exact point of failure.

## Build production AI systems

The full-stack-ai-agent-template helps you skip solving the same problems over and over, so you can focus on what matters: your unique AI product.

## Resources

* **Pydantic AI documentation:** [pydantic.dev/docs/ai](https://pydantic.dev/docs/ai)
* **Pydantic Logfire documentation:** [pydantic.dev/docs/logfire](https://pydantic.dev/docs/logfire)
* **Pydantic Deep:** [pydantic-deepagents](https://github.com/vstorm-co/pydantic-deepagents), our deep agent framework for complex AI workflows.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "BlogPosting",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://pydantic.dev/articles/full-stack-ai-agent-template-pydantic-ai"
      },
      "headline": "A production-ready full-stack template for AI agents with Pydantic AI and Logfire",
      "description": "An open-source CLI that generates production-ready FastAPI and Next.js apps with Pydantic AI agents, WebSocket streaming, auth, and Logfire tracing built in.",
      "keywords": "Pydantic AI, full-stack AI template, FastAPI Next.js template, AI agent boilerplate, Pydantic Logfire, WebSocket streaming, LLM application template, production-ready AI agents, open source",
      "author": {
        "@type": "Person",
        "name": "Antoni Kozelski",
        "worksFor": {
          "@type": "Organization",
          "name": "Vstorm",
          "url": "https://vstorm.co/"
        }
      },
      "publisher": {
        "@type": "Organization",
        "name": "Pydantic",
        "url": "https://pydantic.dev/"
      },
      "datePublished": "2026-06-22"
    }
  ]
}
</script>
