wassim249/fastapi-langgraph-agent-production-ready-template

A production-ready FastAPI template for building AI agent applications with LangGraph integration. This template provides a robust foundation for building scalable, secure, and maintainable AI agent services.

What it solves

This project provides a production-ready backend template for AI agents, eliminating the need for developers to manually implement repetitive infrastructure concerns. It bridges the gap between a basic local agent prototype and a deployable service by integrating essential production features like state management, authentication, and observability.

How it works

The template uses FastAPI as the web framework and LangGraph to manage the agent's stateful logic and tool execution. It incorporates several specialized services:

  • Memory: Uses mem0 and pgvector for long-term, user-specific semantic memory.
  • LLM Management: A dedicated service handles model selection with a circular fallback mechanism (rotating to a backup model if the primary fails) and exponential backoff retries.
  • Observability: Integrates Langfuse for tracing LLM calls and Prometheus/Grafana for system metrics.
  • Security: Implements JWT-based authentication and session management, with rate limiting handled by slowapi.
  • Data: Uses SQLModel for ORM and Alembic for database migrations.

Who it’s for

AI engineers who need a professional, scalable foundation to build agentic backends without spending time wiring up infrastructure, auth, and monitoring from scratch.

Highlights

  • Stateful Conversations: Built-in support for checkpointing and human-in-the-loop interactions via LangGraph.
  • Resilient LLM Calls: Circular model fallback and total timeout budgets to ensure reliability.
  • Long-term Memory: Self-hosted semantic search per user via pgvector.
  • Production Tooling: Includes structured logging with request context, JWT auth, and a full monitoring stack (Prometheus/Grafana).

Related

  • Project
  • Project
  • Project
  • Project