A FastAPI sample application integrating OpenAI Agents SDK with Braintrust observability.
- uv package manager
- API keys from:
- OpenAI
- Tavily
- Braintrust
- Multi-Agent Architecture: Lead agent with reasoning capabilities (GPT-5-mini) and specialized guardrail agent (GPT-4.1-mini)
- Conversation Management: SQLite3-based conversation persistence with custom schema and thread management
- Context Engineering: Intelligent context optimization with two-level trimming strategy
- Tool call output trimming when token usage exceeds 150K tokens
- Turn-based conversation history pruning when exceeding 200K tokens
- Parallel Task Execution: Concurrent guardrail checking, metadata extraction, and follow-up questions generation
- Custom Function Tools: Integrated Tavily web search with custom context tracking
- Server-Sent Events (SSE): Real-time streaming responses with extended thinking, tool calls, and follow-up questions
- Braintrust Integration: Comprehensive observability with tracing, logging, and token usage monitoring
- External Prompt Management: Modular prompt templates stored as separate markdown files
- Token Usage Analytics: Detailed tracking of input/output/reasoning tokens and prompt cache hit ratios
- Copy environment template:
cp .env.example .env-
Edit
.envand add your API keys -
Create data directory:
mkdir -p data- Install dependencies:
uv sync- Run DB migration:
uv run python migrate_agent_db.py- Run development server:
uv run fastapi devuv run fastapi runSee https://fastapi.tiangolo.com/deployment/manually/
Set up .env first, then run:
docker compose upIf you change the app code, you need to rebuild:
docker compose build