weave.EvaluationLogger. You build a small customer-support agent, score task completion for single-turn and multi-turn interactions, and compare two versions of the agent.
What you’ll learn
This guide shows you how to:- Build and trace an agent as a conversation of turns and tool calls.
- Score single-turn task completion with an LLM judge.
- Organize and compare agent evaluations in the Weave UI.
- Score a multi-turn conversation.
- Extend your scorers beyond task completion.
In this tutorial, the agent runs on Claude Sonnet and the judge runs on Claude Opus. Grading with a 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
The agent answers refund requests using two tools,lookup_order and issue_refund, under a policy that allows refunds only 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:
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 that ties the preceding pieces together.task_completion()andjudge_task: the LLM judge and the task it scores, introduced in the following section.
Score task completion
Task completion asks a single question: did the agent achieve the goal? A judge model reads the transcript and decides against the task’s success criteria. It rewards the correct outcome, not a polite-sounding reply. Define a small task suite:EvaluationLogger. The key step is to run the agent inside log_prediction(...), so that the traced agent conversation links to the evaluation result:
Task completion is one signal, not the whole score. Add more signals with extra
pred.log_score(...) calls in the same block, for example tool_call_correct or instruction_following.Organize and compare evaluations
To compare two versions of your agent, run the same evaluation again with a differentmodel label:
Score a multi-turn conversation
To evaluate a turn in context, load a fixed conversation history, append one new user turn, and score how the agent handles it. In other words, given the conversation state so far, does the agent handle the next turn well? Each dataset row carries the prior turns plus the next message. In the following example, the order ID appears only in the history, so a good agent uses that context 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(name, value) call inside the prediction block.
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 more about the imperative evaluation API in the EvaluationLogger guide.