Skip to main content
Experiments connect your agent, dataset, and evaluators to produce quantitative measurements of performance. Every experiment creates a snapshot you can compare against future versions.

Anatomy of an Experiment

An experiment requires three components:
  1. Target: The agent or function to evaluate
  2. Dataset: Test cases with inputs (and optionally expected outputs)
  3. Evaluators: Functions that score the agent’s outputs
experiment_components.py

Basic Experiment

Here’s a minimal example from the OfficeFlow agent:
The evaluate function automatically runs your agent on every example in the dataset and applies all evaluators to the outputs.

Async Agents

For agents using async/await, use aevaluate:
async_experiment.py

Experiment Naming

Experiments are automatically named with timestamps. Use experiment_prefix to organize results:
named_experiments.py

Real-World Example

Here’s how the OfficeFlow course evaluates the schema-checking behavior:
run_eval.py
Creating a fresh thread_id for each example ensures test isolation - one example’s state doesn’t affect another.

Experiment Results

The evaluate function returns an ExperimentResults object:
analyze_results.py

Viewing Results

Experiments appear in the LangSmith UI with:
  • Aggregate metrics - Pass rate, average scores
  • Per-example results - See which inputs failed
  • Trace links - Debug individual runs
  • Comparison view - Compare against other experiments

Multiple Evaluators

Pass multiple evaluators to measure different aspects:
multiple_evaluators.py

Using Dataset-Bound Evaluators

You can attach evaluators directly to datasets in the LangSmith UI. These run automatically:
auto_evaluators.py
Dataset-bound evaluators are useful for organization-wide standards that should apply to all experiments on that dataset.

Best Practices

Test Isolation

Ensure each example runs independently:
test_isolation.py

Performance Optimization

For large datasets, use async evaluation:
parallel_eval.py

Reproducibility

Set seeds and model parameters for consistent results:
reproducible_eval.py

Next Steps

Code-based Eval

Write deterministic evaluators

LLM-as-Judge

Evaluate subjective criteria