A complete demonstration of automated testing for AI agents using Langfuse for observability and evaluation.
This project demonstrates how to:
- Build an AI agent with RAG (Retrieval-Augmented Generation) and tool calling
- Observe agent behavior using Langfuse tracing
- Automatically test agent correctness using Langfuse's Experiment Runner and DeepEval
- Monitor and evaluate agent performance in a unified dashboard
A simple but complete AI agent that:
- Uses RAG (FAISS vector store) to look up menu prices
- Uses Tools to place orders
- Integrates with Langfuse for full observability
- Can be tested with automated evaluation frameworks
- Python 3.11+
- Google Gemini API key
- Docker and Docker Compose (only if self-hosting Langfuse)
cd main/python3.11 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the main/ directory:
# Google Gemini API Key (required)
GEMINI_API_KEY=your_gemini_api_key_here
# Langfuse Configuration (required)
LANGFUSE_PUBLIC_KEY=your_langfuse_public_key
LANGFUSE_SECRET_KEY=your_langfuse_secret_key
LANGFUSE_HOST=http://localhost:3000Get your Gemini API key: https://aistudio.google.com/apikey
You have two options for Langfuse:
Langfuse Cloud is a fully managed solution hosted by the Langfuse team.
- Sign up at https://cloud.langfuse.com
- Create a new project
- Go to Settings β API Keys
- Copy your
Public KeyandSecret Keyto your.envfile - Set
LANGFUSE_HOST=https://cloud.langfuse.comin your.env
Benefits:
- No setup required
- Managed infrastructure
- Automatic updates
- Free tier available
For local development or self-hosting, use Docker Compose:
cd ../langfuse
docker-compose up -dWait for all services to start (about 30-60 seconds), then:
- Open http://localhost:3000 in your browser
- Create an account (first-time setup)
- Create a new project
- Go to Settings β API Keys
- Copy your
Public KeyandSecret Keyto your.envfile - Ensure
LANGFUSE_HOST=http://localhost:3000in your.env
Note: Self-hosting requires Docker and sufficient system resources. For production deployments, see Langfuse Self-Hosting Documentation.
Run a quick test:
python burger_agent.pyYou should see:
- Agent response printed to console
- Trace ID (if Langfuse is connected)
- Check Langfuse dashboard:
- Cloud: https://cloud.langfuse.com β Tracing
- Self-hosted: http://localhost:3000 β Tracing
Uses Langfuse's built-in Experiment Runner:
python test_langfuse_native.pyOr with pytest:
pytest test_langfuse_native.py -vWhat it does:
- Runs 4 test cases through the agent
- Evaluates outputs with custom evaluators
- Sends results to Langfuse dashboard
- View results: Langfuse β Datasets β Experiments
Uses DeepEval framework for LLM-as-a-Judge evaluation:
python test_agent.pyOr with pytest:
pytest test_agent.py -vWhat it does:
- Runs 4 test cases
- Uses Gemini LLM to evaluate correctness
- Tests: RAG accuracy, tool execution, tone
Sends DeepEval scores to Langfuse:
python test_agent_with_langfuse.pyAccess your dashboard:
- Cloud: https://cloud.langfuse.com
- Self-hosted: http://localhost:3000
-
Tracing β
/traces- See every agent execution
- View tool calls, LLM requests, token usage, costs
- Debug agent behavior
-
Datasets β
/datasets- View experiment runs
- See test case results
- Compare runs over time
-
Scores β
/scores- View evaluation scores
- Track quality metrics over time
main/
βββ burger_agent.py # The AI agent (RAG + Tools)
βββ test_langfuse_native.py # Langfuse native testing
βββ test_agent.py # DeepEval testing
βββ test_agent_with_langfuse.py # DeepEval + Langfuse integration
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (create this)
βββ README.md # This file
-
RAG System: FAISS vector store with menu data
- "Big Mac: $5"
- "Whopper: $6"
- "Fries: $2"
-
Tools:
lookup_price(query): Searches vector store for pricesplace_order(items): Returns order confirmation
-
LLM: Google Gemini 2.0 Flash
-
Observability: Langfuse CallbackHandler captures all interactions
Langfuse Native (test_langfuse_native.py):
- Uses
langfuse.run_experiment() - Custom evaluators (price accuracy, tool execution)
- Results stored in Langfuse automatically
DeepEval (test_agent.py):
- Uses
GEval(LLM-as-a-Judge) - Gemini evaluates if outputs are correct
- Semantic evaluation, not exact matching
-
Observability (Langfuse Tracing): See what happened
- Tool calls, LLM requests, costs, latency
- Always running, captures everything
-
Testing (Evaluation): Verify if it's correct
- Automated checks against test cases
- Pass/fail results
- Run on-demand or in CI/CD
- Tracing helps you debug when things go wrong
- Testing catches regressions before production
- Together: Complete visibility and quality assurance
If using Langfuse Cloud:
- Verify
LANGFUSE_HOST=https://cloud.langfuse.comin.env - Check your API keys are correct
- Verify your account is active at https://cloud.langfuse.com
If using self-hosted:
- Check Docker is running:
docker ps - Verify Langfuse is up: http://localhost:3000
- Check
.envhas correct keys andLANGFUSE_HOST=http://localhost:3000 - Restart Langfuse:
cd ../langfuse && docker-compose restart - Check logs:
cd ../langfuse && docker-compose logs
- Verify
GEMINI_API_KEYis set in.env - Check you have API credits/quota
- Run
python burger_agent.pyfirst to verify agent works
- Make sure virtual environment is activated
- Reinstall:
pip install -r requirements.txt - Check Python version:
python --version(should be 3.11+)