Skip to main content
Building AI agents without evaluations is like shipping software without tests. You don’t know whether they work correctly until users complain. An evaluation framework provides a structured way to test your agents against datasets and measure their performance using custom evaluators. The SDK includes a Langfuse-based evaluation framework that lets you:
  • Test agent behavior: Run agents against predefined test cases
  • Measure performance: Use custom evaluators to score responses
  • Track experiments: All results are logged to Langfuse for analysis
  • Automate CI/CD: Integrate evaluations into your deployment pipeline
Built on Langfuse experiments. Your evaluation results are automatically visualized in your Langfuse dashboard for comparison and analysis.

Prerequisites

Before using the evaluation framework, ensure you have:
  1. Langfuse credentials configured:
    .env
  2. BB AI SDK installed in your project

Quick start

Get evaluations running in 5 steps:
1

Initialize evals folder

Run the CLI command to scaffold the evals structure:
This creates an evals/ folder with:Configure observability in evals/__init__.py (match your FastAPI app’s service_name / environment; pin bb-ai-sdk==0.1.9). The CLI scaffold may name this helper init_observability():
Install the matching [instrument-agno] (or langchain/langgraph) extra. LangChain/LangGraph can also use callback handlers — see Observability.
For more information about configuring observability, see the Observability documentation.
2

Register your agent task

Edit evals/agents.py to register your agent as a task function:
agents.py
The task name in @register_task("my_agent") must match the name field in your config file.
3

Create a custom evaluator

Edit evals/evaluators.py to define how responses are scored:
evaluators.py
The custom evaluator name in @register_evaluator("accuracy_evaluator") must match the name used in your config file.
4

Configure the experiment

Edit evals/evals_config.yaml to define your evaluation:
evals_config.yaml
5

Create a dataset

Add a CSV file at evals/datasets/my_dataset.csv:
my_dataset.csv
Run evaluations with bb-ai-sdk evals run and view results in your Langfuse dashboard!

Registering task functions

Task functions connect your agents to the evaluation framework. They define how to invoke your agent and return results.

Task function signature

All task functions must:
  • Accept keyword arguments including item (with .input attribute)
  • Return a string result

Creating custom evaluators

Evaluators score agent responses against expected outputs or custom criteria.

Evaluator function signature

Evaluators must:
  • Accept keyword arguments: input, output, expected_output, metadata
  • Return a Langfuse Evaluation object with name, value (score), and optional comment

Configuration

The evals_config.yaml file defines which agents to evaluate, their datasets, and evaluators.

Configuration structure

evals_config.yaml

Dataset format

Datasets are CSV files stored in evals/datasets/.

CSV structure

Example datasets

qa_dataset.csv

Running evaluations

Using the CLI

Using Python

How it works

The following diagram shows the evaluation framework flow:
1

Auto-discovery

The framework automatically imports evals.agents and evals.evaluators modules to discover registered functions.
2

Dataset management

For each agent, the framework checks if the dataset exists in Langfuse. If not, it uploads the CSV file automatically.
3

Experiment execution

The framework calls the task function for each dataset item and captures the results as Langfuse traces.
4

Evaluation

Each evaluator runs on the task output, and the framework logs scores to Langfuse.

Troubleshooting

Error: ValueError: Task 'my_agent' is not registeredCause: Task name in config doesn’t match the @register_task decorator.Solution: Ensure names match exactly:
Error: FileNotFoundError: CSV file not found at default pathCause: The CSV file doesn’t exist at the expected location.Solution: Ensure the CSV file exists at evals/datasets/{dataset_name}.csv:
Error: ValueError: Evaluator 'my_evaluator' is not registeredCause: Evaluator name in config doesn’t match the @register_evaluator decorator.Solution: Ensure names match exactly in evaluators.py and the configuration file.
Error: ValueError: Langfuse credentials not configuredSolution: Set environment variables:
Or in .env file:
.env
Cause: Task function returning None or empty string.Solution: Ensure your task function returns a valid string:

Next steps

Observability

Learn about tracing and monitoring your agents

AI Gateway

Connect to AI models through the gateway

CI/CD workflows

Integrate evals into your deployment pipeline

Starter kits

See evals integrated in production-ready templates