How pdichone/lang-production-api works
This repository implements a FastAPI chat service backed by a LangGraph agent. A client submits a chat request; the API validates its shape, sanitizes and masks input, checks the response cache, invokes the agent on a miss, validates the generated output, caches it, and returns a structured response. The service also exposes health, cache-statistics, and metrics endpoints, with rate limiting, structured logging, timing, and request metrics. The agent supports primary-model, fallback, and graceful-error paths. README content is empty, so capability coverage is based on the sampled source; external model and tracing links are shown only where source supports them.
Main entry points: main.py API routes · agent.py LangGraph agent · security.py Security pipeline · models.py Request contracts
Components 16
API
- API routes
app/main.py - Request contracts
app/models.py - Rate limiter
app/main.py
Chat processing
- Security pipeline
app/security.py - Input checks
app/security.py - Output checks
app/security.py - Response cache
app/cache.py - LangGraph agent
app/agent.py
Operations
- Runtime settings
app/config.py - Structured logger
app/monitoring.py - Request metrics
app/monitoring.py - Request timer
app/monitoring.py
Other components
- Chat client
- Primary model
- Fallback model
- LangSmith tracing
Connections 19
- Chat client → API routes: submits request
app/main.py - API routes → Request contracts: validates with
app/main.py - API routes → Rate limiter: applies limit
app/main.py - API routes → Security pipeline: checks input
app/main.py - Security pipeline → Input checks: delegates input
app/security.py - Security pipeline → Output checks: delegates output
app/security.py - API routes → Response cache: looks up and stores
app/main.py - API routes → LangGraph agent: invokes on miss
app/main.py - LangGraph agent → Runtime settings: loads settings
app/agent.py - API routes → Runtime settings: loads settings
app/main.py - LangGraph agent → Primary model: invokes
app/agent.py - LangGraph agent → Fallback model: invokes on failure
app/agent.py - API routes → Request contracts: returns response
app/main.py - API routes → Structured logger: writes events
app/main.py - API routes → Request metrics: records requests
app/main.py - API routes → Request timer: times request
app/main.py - API routes → LangSmith tracing: traces endpoint
app/main.py - LangGraph agent → LangSmith tracing: traces invocation
app/agent.py - Security pipeline → LangSmith tracing: traces checks
app/security.py