> ## Documentation Index
> Fetch the complete documentation index at: https://developers.agentx.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic Claude

> Evaluate an agent built on the Anthropic Messages API

Install:

```bash theme={null}
pip install agentx-python anthropic
```

## Usage

```python theme={null}
from agentx import AgentX
import anthropic

client = AgentX.from_env()
ant = anthropic.Anthropic()

def claude_agent(case):
    msg = ant.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=1024,
        system="You are a helpful customer support agent.",
        messages=[{"role": "user", "content": case.query}],
    )
    return {"output": msg.content[0].text, "metadata": {"model": msg.model}}

run_context = (
    client.evaluations
    .run(dataset_id="...", subject={"kind": "custom_agent", "displayName": "Claude Haiku", "framework": "anthropic"})
    .execute(claude_agent)
    .finalize()
)
print(f"Average rating: {run_context.average_rating:.2f}")
```

Returning `metadata: {"model": msg.model}` records which model produced each response, powering the Sovereignty & Portability breakdown in the report.

## With tracing

Combine this with [`patch_anthropic_client`](/sdk/integrations/anthropic) to get a full Execution Timeline per result, not just a score. Wrap the patched call in `tracer.trace(..., sync=True)` so `span.trace_id` is populated before your function returns. The patch attaches to that span instead of sending its own independent trace, so you still get exactly one trace per case:

```python theme={null}
from agentx import AgentX
from agentx.integrations.anthropic import patch_anthropic_client
import anthropic

client = AgentX.from_env()
ant = anthropic.Anthropic()
patch_anthropic_client(ant, tracer=client.tracer, name="claude-support-agent")

def claude_agent(case):
    with client.tracer.trace("claude-support-agent-call", framework="anthropic", sync=True, monitor=False) as span:
        msg = ant.messages.create(
            model="claude-haiku-4-5-20251001",
            max_tokens=1024,
            system="You are a helpful customer support agent.",
            messages=[{"role": "user", "content": case.query}],
        )
        span.output = msg.content[0].text

    return {
        "output": msg.content[0].text,
        "metadata": {"model": msg.model},
        "trace_id": span.trace_id,
    }
```

<Tip>
  `patch_anthropic_client` on its own (no surrounding span) is fire-and-forget and never returns a `trace_id`; see [Decorator vs. context manager](/sdk/tracing#decorator-vs-context-manager). Wrapping it in `tracer.trace(..., sync=True)`, as shown above, is what makes the id available.
</Tip>

A complete working example is available as [`anthropic_eval.py`](https://github.com/AgentX-ai/AgentX-Python/blob/main/examples/evaluations/anthropic_eval.py) in the AgentX-Python repository.
