Send every run to LangSmith so you can see what the agent did, then score the agent against a dataset of test prompts. Both need the LangSmith extra:

pip install "harnessx[langsmith]"

Trace runs in LangSmith

Set your LangSmith key, then add LangSmithExtension to the agent:

export LANGSMITH_API_KEY="lsv2_pt_..."
export LANGSMITH_PROJECT="my-agent"   # optional
import asyncio

from harnessx import Agent, AgentConfig, LangSmithExtension, PermissionLevel


def calculate(a: float, b: float) -> str:
    """Add two numbers.

    Args:
        a: The first number.
        b: The second number.
    """
    return str(a + b)


async def main():
    agent = Agent(
        config=AgentConfig(model="claude-sonnet-4-6"),
        extensions=[LangSmithExtension(
            project_name="my-agent",
            run_name="Support assistant",
            tags=["production"],
            metadata={"customer": "acme"},
        )],
    )
    agent.tools.register_tool(calculate, permission=PermissionLevel.ALLOW)

    async with agent:
        result = await agent.run("What is 17 + 25? Use the calculate tool.")
        print(result.output)


asyncio.run(main())

If you only want the defaults, the extension needs no arguments at all: Agent(extensions=[LangSmithExtension()]) traces to the project in LANGSMITH_PROJECT.

Run it, then open the project in LangSmith. Each run shows up as one trace:

Support assistant                 one per run: the prompt in, the answer out
├─ anthropic:claude-sonnet-4-6    a model call: messages, tools, system prompt,
│                                 reply, stop reason, tokens
├─ calculate                      a tool call: its arguments and its result
└─ anthropic:claude-sonnet-4-6    the next model call
  • Model calls carry the full request and reply, plus token usage. Cache reads and writes are counted separately, and LangSmith prices the call from the model and provider names.
  • Tool calls carry their arguments and result. A tool that failed is marked as an error, so you can filter for it.
  • Specialists appear inside the delegation that started them, so a multi-agent run is one tree.
  • Fallbacks: when a call fails over to another provider, the span is labelled with the provider that actually answered.
  • Threads: every run from the same agent carries its session_id, so LangSmith shows a whole conversation as one thread.
  • Errors: if the run fails, the run and any open model or tool calls are closed with the error.

The run's metadata also includes the model and provider, plus anything you pass in metadata. Use tags and metadata to filter runs in the LangSmith UI.

Option Default What it does
project_name LANGSMITH_PROJECT, then LANGCHAIN_PROJECT, then "harnessx-agents" The LangSmith project the traces go to
run_name "<model> Agent" The name of each run's top-level trace
tags none Tags added to every run
metadata none Extra metadata added to every run
api_key, api_url from the environment Set them to send traces to another workspace or a self-hosted LangSmith. When you set these or client, closing the agent also sends any traces still queued
client none A langsmith.Client you've already configured
trace_llm True False leaves model calls out of the trace
trace_tools True False leaves tool calls out of the trace
enabled True False turns tracing off without removing the extension

Try it: uv run python examples/07-quality/tracing_with_langsmith.py (needs ANTHROPIC_API_KEY and LANGSMITH_API_KEY).

Tracing sends your prompts, tool arguments and tool results to LangSmith, so only turn it on for data you're happy to send there. Sending is best effort: if LangSmith can't be reached, the run carries on and the trace is lost. When you need a record you can rely on, use the flight recorder.

Evaluate against a dataset

The evaluation runner is built on LangSmith's evaluate. It runs your agent on each example and scores the result: which tools it picked, whether the answer contains what it should, how many steps it took, and more. You can run it locally, or upload the results to see them side by side in LangSmith. A local run still calls the model, so it costs the same; only the upload is skipped. uv run python examples/07-quality/evaluating_with_datasets.py --offline shows the whole flow without an API key.

Run an evaluation

import operator

from harnessx import Agent, AgentConfig, PermissionLevel
from harnessx.evals import build_example, contains_evaluator, evaluate_agent, tool_selection_evaluator

OPERATORS = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}

def calculate(a: float, op: str, b: float) -> str:
    """Apply one arithmetic operator to two numbers.

    Args:
        a: The left number.
        op: One of + - * /.
        b: The right number.
    """
    return str(OPERATORS[op](a, b))

def make_agent(inputs):
    agent = Agent(config=AgentConfig(model="claude-sonnet-4-6"))
    agent.tools.register_tool(calculate, permission=PermissionLevel.ALLOW, replay_policy="safe")
    return agent

dataset = [
    build_example(
        inputs={"prompt": "What is 144 / 12?"},
        outputs={"expected_tools": ["calculate"], "contains_all": ["12"], "max_allowed_iterations": 3},
    )
]

summary = evaluate_agent(
    agent=make_agent,
    dataset=dataset,
    evaluators=[tool_selection_evaluator, contains_evaluator],
    experiment_prefix="math-agent-benchmark",
    offline=True,   # Disables LangSmith upload; the agent still calls its model.
)
print(f"Pass rate: {summary.pass_rate * 100:.1f}%")

Instead of your own dataset, you can pass the name of a built-in suite: "tool_calling", "skills", "multi_agent", "guardrails", "memory", or "all". default_evaluators() is the standard set of evaluators, used when you don't pass any.

When results are uploaded (offline=False), the dataset is copied to LangSmith first. A built-in suite is uploaded as harnessx- plus its name, such as harnessx-tool-calling, and your own examples as <experiment_prefix>-dataset. Experiments are named from experiment_prefix, harnessx-eval by default. Each example's agent run is traced inside the experiment, so you can open any row and see its full trace.

Evaluate from async code

evaluate_agent_async(...) runs the same evaluation from async code. It runs in a worker thread, so pass a function that builds the agent rather than an Agent you've already created on your event loop. Once it starts it can't be cancelled, and you can't start one evaluation inside another.

from harnessx.evals import evaluate_agent_async

async def benchmark():
    summary = await evaluate_agent_async(
        agent=make_agent,      # a factory, not an Agent bound to this loop
        dataset="tool_calling",
        offline=True,
    )
    return summary.pass_rate

Run evaluations from the command line

# The scripted example, with no API keys
uv run python examples/07-quality/evaluating_with_datasets.py --offline

# A built-in suite, run locally (needs a model API key)
python -m harnessx.evals.cli --suite tool_calling --offline

# Upload the results and traces to LangSmith
export LANGSMITH_API_KEY="lsv2_pt_..."
python -m harnessx.evals.cli --suite skills --model claude-sonnet-4-6 --upload

# Every suite, two examples at a time
python -m harnessx.evals.cli --suite all --concurrency 2

Without --offline, the command uploads whenever a LangSmith key is set. After an upload it prints a link to the experiment, where you can compare scores row by row and open each run's trace.

Flag Default What it does
--suite, -s tool_calling The built-in suite to run, or all
--model, -m AGENT_MODEL, else claude-sonnet-4-6 The model to evaluate
--provider, -p AGENT_PROVIDER, else anthropic anthropic or openai
--offline off Run locally and upload nothing
--upload off Upload results even if you'd otherwise run locally
--evaluator, -e the standard set Run only the named evaluators; repeat the flag or separate names with commas
--judge off Add a model-graded judge to the evaluators
--concurrency, -c 1 How many examples run at once
--prefix eval-<suite>-<model> The experiment name prefix