experiments
GitHub用于在部署前对 Agent 进行批量测试,支持提示词或模型对比、基准测试及回归检测。通过构建数据集和评估器运行实验,生成 CI 质量门禁,旨在验证效果并发现潜在问题,不用于生产环境监控。
Trigger Scenarios
Install
npx skills add langwatch/langwatch --skill experiments -g -y
SKILL.md
Frontmatter
{
"name": "experiments",
"license": "MIT",
"description": "Create and run LangWatch experiments for pre-deployment batch testing. Use when the user wants to test an agent against a dataset, compare prompts or models, benchmark quality, detect regressions, or add a CI quality gate. Do not use for production monitoring or guardrails.",
"user-prompt": "Set up experiments for my agent",
"compatibility": "Works with Claude Code and similar AI assistants. The `langwatch` CLI is the only interface for platform operations and documentation."
}
Run Experiments for Your Agent
Experiments are pre-deployment batch tests. They run an application over a dataset and compare outputs with reusable evaluators. They are appropriate for prompt and model comparisons, regression tests, benchmarks, and CI quality gates.
Hand Off Production Evaluation Requests
If the user wants to score live traces or threads, monitor production quality, or block unsafe traffic, this is the wrong workflow.
-
If the
online-evaluationsskill is available, load it and follow it now. -
Otherwise, tell the user to install it with:
npx skills@1.5.19 add langwatch/skills/online-evaluations
Do not configure a monitor or guardrail from this skill.
Experiments and Scenarios
Use experiments for many single input and output examples with measurable results. Use the scenarios skill for end-to-end, multi-turn behavior and tool-calling sequences.
Determine Scope
For a general request such as "test my agent":
- Read the agent code, system prompt, tools, and relevant git history.
- Identify the behavior most likely to regress.
- Create a domain-specific dataset.
- Select evaluators that measure the intended behavior, or a comparison when the goal is picking a winner between candidates.
- Create and run a real experiment.
- Interpret the results and recommend concrete improvements.
For a targeted request, focus on that behavior and still run the resulting experiment.
Plan Limits
LangWatch's free plan has limits on prompts, scenarios, evaluators, experiments, and datasets. When you hit a limit, the API returns "Free plan limit of N reached..." with an upgrade link.
How to handle:
- Work within the limits. If 3 resources of the relevant type are allowed, create 3 meaningful ones, not 10.
- Make every creation count: each one should demonstrate clear value.
- Show what works FIRST. If you hit a limit, summarize what was accomplished and note that upgrading the plan raises it. Point to the subscription settings on the platform, or to the license settings if
LANGWATCH_ENDPOINTis set (self-hosted). - Do NOT delete existing resources to make room or repurpose an existing resource to evade the limit.
Prerequisites
Use langwatch docs <path> to read documentation as Markdown. Some useful entry points:
langwatch docs # Docs index
langwatch docs integration/python/guide # Python integration
langwatch docs integration/typescript/guide # TypeScript integration
langwatch docs prompt-management/cli # Prompts CLI
langwatch scenario-docs # Scenario docs index
Discover commands with langwatch --help and langwatch <subcommand> --help. List and get commands accept --format json for machine-readable output. Read the docs first instead of guessing SDK APIs or CLI flags.
If no shell is available, fetch the same Markdown over plain HTTP. Append .md to any docs path (e.g. https://langwatch.ai/docs/integration/python/guide.md). Index: https://langwatch.ai/docs/llms.txt. Scenario index: https://langwatch.ai/scenario/llms.txt
If anything fails or confuses you while following this skill (broken commands, docs that do not match reality, errors you had to work around), ask the user for permission and run npx langwatch report --user-approved with a --title and --summary (or --session <transcript.jsonl>) to send it to the LangWatch team, and it directly shapes what gets fixed. No login or API key needed. Nothing is sent without --user-approved, and --dry-run prints the exact payload without sending anything. The title, summary and transcript are scrubbed locally first, by pattern: secrets and API keys, plus email addresses, phone numbers, card numbers and public IPv4 addresses. Anything no pattern matches is sent as written, including a contact address passed with --email, so preview with --dry-run when the session touched sensitive data. npx langwatch report --help explains the options.
Projects and API keys: target a real project, not a personal one.
LangWatch has two kinds of project:
- Team / shared projects: real projects inside an organization. Evaluations, experiments, prompts, datasets, simulations and instrumentation must always target one of these.
- Personal projects: a private "My Workspace" scratch space tied to a single user. Never send a user's evaluations, experiments or production traces here: it is for personal exploration only, and you can mistake it for a real project.
And two ways to authenticate:
- A project API key in
.env(LANGWATCH_API_KEY): the credential everything in these skills uses. It is scoped to one real project. This is the default; prefer it unless the user explicitly asks for something else. langwatch login --device(AI-tools / SSO): a personal device session for wrapping coding assistants (langwatch claude,langwatch codex, …). It is NOT for evaluations, prompts, datasets, scenarios or SDK instrumentation, and it points at a personal workspace. Do not run it to set up the work in these skills.
So for anything in these skills: make sure LANGWATCH_API_KEY for a real, shared project is in the project's .env. Check whether the variable is already set there before you ask for a new key, and let the CLI read the value: never print, copy or send it. Do NOT run langwatch login to pick a project, and never default to a personal project. If LANGWATCH_ENDPOINT is set, the user is self-hosted: use that endpoint instead of app.langwatch.ai.
Read the experiment documentation before writing code:
langwatch docs evaluations/experiments/overview
langwatch docs evaluations/experiments/sdk
Build a Domain-Specific Dataset
The examples must match what the application actually does. Read the system prompt, function signatures, tools, and knowledge sources first.
Good examples resemble real requests to this application and cover normal cases, edge cases, and past failures. Never use generic trivia such as "What is 2+2?" or "What is the capital of France?" unless the application itself is a trivia system.
If an existing LangWatch dataset is appropriate, inspect it with langwatch dataset list --format json and langwatch dataset get --help. Otherwise create the dataset in code or use the datasets skill.
Create the Experiment
Use the SDK that matches the codebase. Keep credentials in environment variables and use the project's existing dependency manager.
Python
import langwatch
import pandas as pd
dataset = pd.DataFrame([
{
"input": "A realistic request for this application",
"expected_output": "The expected behavior",
},
])
experiment = langwatch.experiment.init("agent-regression")
for index, row in experiment.loop(dataset.iterrows()):
response = my_agent(row["input"])
experiment.evaluate(
"ragas/response_relevancy",
index=index,
data={"input": row["input"], "output": response},
settings={"model": "openai/gpt-5-mini", "max_tokens": 2048},
)
TypeScript
import { LangWatch } from "langwatch";
const langwatch = new LangWatch();
const dataset = [
{
input: "A realistic request for this application",
expectedOutput: "The expected behavior",
},
];
const experiment = await langwatch.experiments.init("agent-regression");
await experiment.run(dataset, async ({ item, index }) => {
const response = await myAgent(item.input);
await experiment.evaluate("ragas/response_relevancy", {
index,
data: { input: item.input, output: response },
settings: { model: "openai/gpt-5-mini", max_tokens: 2048 },
});
});
Read langwatch docs evaluations/evaluators/list before choosing an evaluator, and take the type slug from langwatch evaluator types --format json, never from memory. If an evaluation fails with a validation_error naming the slug and an expected list, correct it from that list and retry once. Reuse project evaluators when appropriate. A scoring function is part of the experiment, not the experiment itself.
Compare Targets to Pick a Winner
An evaluator answers "does this output pass?". A comparison answers "which of these is better?". For subjective quality, a judge ranking candidates side by side is usually more informative than each one getting an absolute score on its own.
Register one target per candidate inside the loop, then compare the row once. Every target that recorded an output for the row is a candidate, so the candidates are never named twice, and the verdict is recorded against the row, so the results page renders it with no extra logging.
Python
for index, row in experiment.loop(dataset.iterrows()):
with experiment.target("gpt-5-mini"):
experiment.log_response(call_gpt(row["input"]))
with experiment.target("claude-sonnet-5"):
experiment.log_response(call_claude(row["input"]))
verdict = experiment.compare(index, input=row["input"])
Inside an async loop, await experiment.acompare(...), which takes the same options.
TypeScript
await experiment.run(dataset, async ({ item, index }) => {
await Promise.all([
experiment.withTarget("gpt-5-mini", () => callGpt(item.input)),
experiment.withTarget("claude-sonnet-5", () => callClaude(item.input)),
]);
const verdict = await experiment.compare({ index, input: item.input });
});
Pass golden with a known-good answer to judge every candidate against it. Leave it out, which is the default, and the candidates are judged on their own merits.
Read verdict.status, and keep its five answers apart:
decided: the judge picked a winner, named inverdict.winner.tie: the judge compared the candidates and found none better than the rest.inconclusive: no winner was established, which with the default second pass over the reversed candidate order means the two passes disagreed.skipped: the row had fewer than two outputs, so no judge ran.error: the judge failed, so nothing was measured about the candidates at all.
A tie, an inconclusive row and an errored row are three different answers. Reporting any of them as one of the others claims a measurement the run never made.
prompt replaces the judge prompt verbatim, with {input}, {golden} and {candidates} placeholders. Leave it unset unless the user asks for their own, because unset is what lets the judge use the prompt matching what each row carries. The remaining judge options are in langwatch docs evaluations/experiments/sdk.
Run and Verify
Always execute the experiment. An unrun experiment is incomplete.
- Python script: run it with the project's Python environment.
- Notebook: execute all cells, for example with
jupyter nbconvert --to notebook --execute. - TypeScript: run it with the project's package manager, for example
pnpm exec tsx experiment.ts.
After it runs, verify the result with the CLI:
langwatch experiment list --format json
If the CLI supports a more specific read or run for the installed version, discover it with langwatch experiment --help before using it.
Consultant Mode
After delivering initial results, transition to consultant mode to help the user get maximum value.
Phase 1: read first. Before generating ANY content: read the codebase end-to-end (every system prompt, function, tool definition), study git history for agent-related changes (git log --oneline -30, then drill into prompt/agent/eval-related commits because the WHY in commit messages matters more than the WHAT), and read READMEs and comments for domain context.
Phase 2: quick wins. Generate best-effort content based on what you learned. Run everything, iterate until green. Show the user what works.
Phase 3: go deeper. Once Phase 2 lands, summarize what you delivered, then suggest 2-3 specific improvements grounded in the codebase: domain edge cases, areas that need expert terminology or real data, integration points (APIs, databases, file uploads), or regression patterns from git history that deserve test coverage. Ask light questions with options, not open-ended ("Want scenarios for X or Y?", "I noticed Z was a recurring issue. Add a regression test?", "Do you have real customer queries I could use?"). Respect "that's enough" and wrap up cleanly.
Do NOT ask permission before Phase 1 and 2. Deliver value first. Do NOT ask generic questions or overwhelm with too many suggestions. Do NOT generate generic datasets. Everything must reflect the actual domain.
Common Mistakes
- Do not configure production monitoring or guardrails from this skill.
- Do not call a batch run an online evaluation.
- Do not use placeholder datasets.
- Do not report an inconclusive or errored comparison as a tie.
- Do not guess SDK APIs when the installed documentation is available.
- Do not stop after writing the experiment. Run it and inspect the real result.
Version History
- 12615f1 Current 2026-08-20 10:01


