Setup
Get your keys from the Langfuse dashboard → Settings → API Keys.Install the optional dependencies:
Usage with Agent / Task
Everyagent.do() or agent.print_do() (including async versions) call is automatically traced to Langfuse when you pass instrument=langfuse.
Minimal — Keys from Environment
Full Configuration with Session & User Tracking
Usage with Evaluation
AccuracyEvaluator with Langfuse Datasets
When you passlangfuse to AccuracyEvaluator, evaluation results are automatically:
- Logged as a dataset item
- Linked to the agent’s trace via a dataset run item
- Scored on the trace with the evaluation result
AccuracyEvaluator with Multiple Iterations
Run the same query multiple times to get statistical confidence:AccuracyEvaluator Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
langfuse | Langfuse | None | Langfuse instance for dataset logging |
langfuse_dataset_name | str | "accuracy-eval" | Name of the Langfuse dataset to create/use |
langfuse_run_name | str | auto-generated | Name for the dataset run |
num_iterations | int | 1 | Number of times to run the evaluation |
Advanced APIs
For direct access to Langfuse’s scoring, datasets, and annotation queue APIs, see the Advanced Langfuse Guide.Parameters Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
public_key | str | env LANGFUSE_PUBLIC_KEY | Langfuse public key |
secret_key | str | env LANGFUSE_SECRET_KEY | Langfuse secret key |
host | str | env LANGFUSE_HOST | Custom host URL |
region | "eu" | "us" | "eu" | Cloud region (ignored if host is set) |
service_name | str | "upsonic" | Service name in traces |
sample_rate | float | 1.0 | Fraction of traces to sample (0.0–1.0) |
include_content | bool | True | Include prompts/responses in traces |
flush_on_exit | bool | True | Auto-flush on process exit |
Environment Variables
| Variable | Description |
|---|---|
LANGFUSE_PUBLIC_KEY | Langfuse public key (pk-lf-...) |
LANGFUSE_SECRET_KEY | Langfuse secret key (sk-lf-...) |
LANGFUSE_HOST | Custom Langfuse host URL |

