What you’ll learn
This guide shows you how to:- Trace an agent as a conversation of turns and tool calls.
- Score each run with an LLM judge.
- Compare two agent versions side-by-side.
- Score a turn in a multi-turn conversation.
- Grow a single score into a scorecard.
In this tutorial, the agent runs on Claude Sonnet and the judge runs on Claude Opus. Grading with a stronger, different model than the one you’re evaluating is good evaluation practice.
Prerequisites
This tutorial requires the following:- A W&B account.
- Python 3.10+.
- Required packages installed:
pip install weave anthropic. - An Anthropic API key set as the
ANTHROPIC_API_KEYenvironment variable.
Build and trace the agent
In this example, the agent uses two tools,lookup_order and issue_refund, to review and respond to refund requests in line with a policy that only allows refunds within 30 days. The full agent, including the tool definitions, the model loop, and message conversion, is in the accompanying notebook. This section focuses on the Weave-specific part.
First, initialize Weave with your W&B team and project. Replace [YOUR-TEAM] and [YOUR-PROJECT] with your own values:
implicitly_patch_integrations) on would trace your conversations twice: once as your Conversation span and once as a traced Op.
Trace the agent using weave.conversation. A conversation contains turns, and each turn contains the model call and any tool calls:
convo_idandnew_id(): a unique ID for each conversation, such as a UUID.user_message: the user’s input for the turn.anthropic_client: an initialized Anthropic client.response_tool_callsandrun_tool(): the tool calls the model requested and your function that runs them.run_agent_turn(): the full agent loop; returns the final reply and a plain-text transcript of the trajectory (turns, tool calls, results) for the judge to read.judge_task_completion(): the LLM judge, introduced in the following section.
Score the agent with an LLM judge
Using a judge model, the scorer evaluates how well the agent completed the task based on the task’s success criteria, rewarding the correct outcome rather than a polite-sounding reply. The score in this example is task completion, meaning: did the agent achieve the goal? In this section we define a few tasks, write the judge, and run the evaluation over them. Define a small task suite:transcript (the plain-text trajectory run_agent_turn returns) against the task’s success_criteria and returns a {"passed", "reason"} dict:
EvaluationLogger. Run the agent inside log_prediction(...), so the traced conversation links to the eval row:
passed column showing the judge’s verdict, and the Evaluation tab has a View spans button that opens the Agents page with the traced spans linked to this evaluation.
Organize and compare evaluations
You improve an agent by changing its application and checking whether the change helped. The system prompt, the tools, the control flow, and the underlying LLM are all considered part of the model version. To compare two versions, run the evaluation again on the changed agent, labeled as a new version. Re-run with a differentmodel label:
Score a multi-turn conversation
Real conversations span several turns, and a capable agent carries context forward. It shouldn’t re-ask for an order ID the user already gave. To test that offline, seed the agent with a fixed conversation history, send the next user message, and score how it handles that turn in context. Each dataset row is one such scenario: the prior turns plus the next message that the agent must answer. Below, the order ID appears only in the history, so a good agent reuses it instead of asking again:This approach scores the next turn against a fixed history, which is the practical offline method. Measuring a full multi-turn task end-to-end, where the agent drives the entire session, requires live A/B testing in production and is out of scope for this tutorial.
Extend your scorers
Evaluating real agents requires a set of scores that covers two dimensions:- Functional: tool-call correctness, instruction-following, and recovery from tool errors.
- Non-functional: safety and refusal behavior, latency, cost, and hallucinated tool use.
pred.log_score(...) call in the same step. For the scorer types Weave provides, including ready-made and class-based scorers, and guidance on writing your own, see Scoring overview.
Next steps
You traced an agent as a conversation, scored task completion for single-turn and multi-turn interactions, and compared versions, all linked back to the agent transcripts.- Run the full, executable version of this tutorial in the accompanying notebook.
- Learn other ways to link an agent’s traces to its evaluation results, including for agents that run in a separate service or use their own OTel instrumentation, in Link agent traces to evaluations.