How wassim249/fastapi-langgraph-agent-production-ready-template works
This repository is a FastAPI backend template for stateful LangGraph AI agents. Its main workflow authenticates a user’s chat session, accepts a message, runs the agent with checkpointed conversation state and optional memory/tools, then returns or streams a response. Separate branches cover registration and session management, generated session titles, and production operations such as caching, rate limits, metrics, and tracing. The README also documents an evaluation framework. Some subsystem links rely on README or source-index references; unsampled implementation details are not inferred.
Main entry points: graph.py LangGraph agent · main.py FastAPI application · chatbot.py Chat endpoints · database.py Database service
Components 24
API and identity
- FastAPI application
app/main.py - API router
app/api/v1/api.py - Auth and sessions
app/api/v1/auth.py - JWT utilities
app/utils/auth.py - Chat endpoints
app/api/v1/chatbot.py - Request schemas
app/schemas/chat.py
Agent runtime
- LangGraph agent
app/core/langgraph/graph.py - Agent tools
app/core/langgraph/tools - LLM service
app/services/llm/service.py - Model registry
app/services/llm/registry.py - Session naming
app/services/session_naming.py - LLM provider
Persistence and memory
- Database service
app/services/database.py - Session model
app/models/session.py - User model
app/models/user.py - Long-term memory
app/services/memory.py - PostgreSQL
Operations
- Cache service
app/core/cache.py - Valkey or Redis
- Request middleware
app/core/middleware.py - Prometheus metrics
app/core/metrics.py - Tracing and logging
app/core/observability.py
Evaluation
- Evaluation framework
evals/evaluator.py
Other components
- API user
Connections 26
- API user → FastAPI application: sends requests
app/main.py - FastAPI application → API router: mounts router
app/main.py - API router → Auth and sessions: routes auth
app/api/v1/api.py - API router → Chat endpoints: routes chat
app/api/v1/api.py - Auth and sessions → JWT utilities: uses tokens
app/api/v1/auth.py - Auth and sessions → Database service: manages users and sessions
app/api/v1/auth.py - Database service → User model: persists users
app/services/database.py - Database service → Session model: persists sessions
app/services/database.py - Chat endpoints → Request schemas: validates messages
app/api/v1/chatbot.py - Chat endpoints → LangGraph agent: invokes agent
app/api/v1/chatbot.py - Chat endpoints → Session naming: may name session
app/api/v1/chatbot.py - LangGraph agent → LLM service: calls model service
app/core/langgraph/graph.py - LangGraph agent → Agent tools: binds tools
app/core/langgraph/graph.py - LangGraph agent → Long-term memory: searches memory
app/core/langgraph/graph.py - LangGraph agent → PostgreSQL: checkpoints state
app/core/langgraph/graph.py - LLM service → Model registry: resolves models
app/services/llm/service.py - Model registry → LLM provider: creates provider models
- Session naming → LLM service: generates title
app/services/session_naming.py - Session naming → Database service: claims and updates session
app/services/session_naming.py - Long-term memory → Cache service: uses cache
app/services/memory.py - Cache service → Valkey or Redis: uses when configured
app/core/cache.py - FastAPI application → Request middleware: installs middleware
app/main.py - Request middleware → Prometheus metrics: records request metrics
app/core/middleware.py - FastAPI application → Prometheus metrics: exposes metrics
app/main.py - LangGraph agent → Tracing and logging: integrates tracing
app/core/langgraph/graph.py - Evaluation framework → LLM provider: evaluates model outputs