A FastAPI chat agent built on LangGraph, with security guardrails (input sanitisation, PII detection via Presidio, language-gate, output validation), OpenSearch-backed RAG and semantic caching, LLM fallback/circuit-breaking, token-budget tracking, and SQLite-backed conversation checkpointing.
- Python 3.12+
- uv
- Docker (for OpenSearch, used by RAG and the semantic cache)
uv sync
docker compose up -d # starts OpenSearch on :9200Configuration is loaded from environment variables (see src/core/config/settings.py); a .env file is supported (see .env.example). Required variables include OpenAI/Anthropic API keys, MCP endpoint details, and app settings like app_env, log_level, and rate_limit.
uv run uvicorn api.main:app --app-dir src --reloadConversation state is checkpointed to a local checkpoints.db SQLite file.
A minimal React/TypeScript chat widget lives in web/, for manually testing the API.
cd web
yarn install # first time only
yarn devOpen http://localhost:5173 — the dev server proxies /chat, /health, /metrics, /cache, and /knowledge to the backend on :8000, so both the backend (and OpenSearch) need to be running first.
uv run pytest # unit tests
uv run pytest -m integration # real network calls (needs credentials)
uv run pytest -m regression # LLM quality regression suitesrc/api/— FastAPI app assembly (lifespan-managed agent/cache/security/metrics, exposed to routes viaapp.state+Depends()) and routes:/chat,/health,/metrics,/cache/stats,/knowledgeweb/— React/TypeScript chat widget for manually testing the API (see "Web UI" above)src/app/agents/researcher/— LangGraph researcher agent (nodes, routes, tools, state)src/app/security/— input sanitiser, PII detector (Presidio/GLiNER), language detector, output validator, and the security pipeline/guard that wires them togethersrc/app/rag/— retrieval over the OpenSearch-backed document vector storesrc/app/cache/— hash and semantic response caches (OpenSearch-backed), with periodic maintenance/evictionsrc/app/error_handling/— retry, circuit breaker, and model fallback chain around LLM callssrc/app/cost_optimisation/— token-budget estimation and enforcementsrc/app/observability/— request timing and metrics collection (also traced via LangSmith/Langfuse)src/app/mcp/— MCP client used by agent toolssrc/app/evaluation/— LLM-judge based evaluationsrc/core/— configuration, logging, models, and the OpenSearch vector storedocker-compose.yml— local OpenSearch instancetests/— unit, integration, and regression suites, mirroring thesrc/app/layout