diff --git a/README.md b/README.md index f5b86c2..6a46354 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ Yes. agentevals accepts OTLP over HTTP (`http/protobuf` and `http/json`, gzip in **Can I evaluate Claude Code, Codex or OpenCode?** -Partly. They do not emit GenAI semantic convention spans, so agentevals sees a turn only when something wraps it in one, as kagent does for its Claude Code harness. A Collector recipe can then map Claude Code's own spans to tool and model calls, see the [Kubernetes example](examples/kubernetes/README.md#claude-code-workaround). agentevals is built for instrumented agents whose success is measurable through tool trajectories and responses, not for scoring long coding sessions end to end. +Partly. On their own they do not emit the GenAI agent and model spans agentevals builds turns from. kagent v1.x runs Claude Code and Codex as harnesses and writes those spans for them, with tool arguments and token usage, see the [Kubernetes example](examples/kubernetes/README.md). agentevals is built for instrumented agents whose success is measurable through tool trajectories and responses, not for scoring long coding sessions end to end. **How is this different from LangSmith, Langfuse, Opik or Bedrock AgentCore evaluation?** diff --git a/docs/opentelemetry-pipeline.md b/docs/opentelemetry-pipeline.md index 05e2043..514aeb8 100644 --- a/docs/opentelemetry-pipeline.md +++ b/docs/opentelemetry-pipeline.md @@ -145,7 +145,7 @@ Notes: * `filter/not_from_agentevals` keeps agentevals' own results out of the agentevals branch. agentevals also drops them itself. * If you sample, sample whole traces and only on the backend branch. agentevals needs complete traces. * For producers that use OpenInference or OpenLLMetry attribute names, the contrib `gen_ai_normalizer` processor (alpha) can map them to GenAI conventions on the agentevals branch. -* For Claude Code under kagent, the [Kubernetes example](../examples/kubernetes/README.md#claude-code-workaround) has a `transform` recipe that maps its spans to tool and model calls. +* For Claude Code and Codex, run them as kagent v1.x harnesses, which write GenAI spans for their model and tool calls. See the [Kubernetes example](../examples/kubernetes/README.md). ## Send evaluation results from agentevals diff --git a/examples/kubernetes/README.md b/examples/kubernetes/README.md index 0f970b6..95728f7 100644 --- a/examples/kubernetes/README.md +++ b/examples/kubernetes/README.md @@ -8,24 +8,17 @@ kagent agents --> OTel Collector --> agentevals (UI on :8001) +---- scores -----+ ``` -Tested with kagent `v1.0.0-alpha12` (installed with `kagent install`), Claude Code 2.1.285 (shipped in its Claude harness), agentevals 0.11.0, Collector contrib 0.162.0, and `claude-haiku-4-5` for both agents. +Tested with kagent `v1.0.1` (installed with `kagent install`), Claude Code 2.1.285 (shipped in its Claude harness), agentevals 0.15.1, Collector contrib 0.162.0, and `claude-haiku-4-5` for both agents. -What you get depends on the kagent version: - -| kagent | Go ADK | Claude Code harness | Codex harness | -|---|---|---|---| -| `v1.0.0-alpha12` or later (tested) | Model and tool calls with arguments, results and tokens | The runtime writes `chat` and `execute_tool` spans with tool names, arguments, results and tokens | Runtime spans, not tested | -| Before `v1.0.0-alpha12` | Same | Native Claude Code spans only, see [Older kagent versions](#older-kagent-versions) | Not tested | - -The steps below need `v1.0.0-alpha12` or later, where each Agent points at a separate Harness. +You need kagent v1.x. Both agents give you model and tool calls with arguments, results and tokens. For Claude Code, the kagent harness runtime writes these as `chat` and `execute_tool` spans, and a subagent's calls show up under the `Agent` tool call that started it. The Codex harness works the same way, but is not tested here. ## Set it up -You need a cluster with kagent `v1.0.0-alpha12` or later, and a default model config on Anthropic, since the Claude harness only runs Claude models. For example: +You need a cluster with kagent v1.x, and a default model config on Anthropic, since the Claude harness only runs Claude models. For example: ```bash export ANTHROPIC_API_KEY= -KAGENT_DEFAULT_MODEL_PROVIDER=anthropic kagent install +kagent install --provider Anthropic ``` Install agentevals and the Collector: @@ -43,23 +36,20 @@ Point kagent at the Collector. `--version` keeps the kagent version you have, si export KAGENT_VERSION=$(helm get metadata kagent -n kagent -o json | jq -r .version) helm upgrade kagent oci://ghcr.io/kagent-dev/kagent/helm/kagent -n kagent \ --version "$KAGENT_VERSION" --reuse-values \ - --set otel.exporter.otlp.endpoint=http://otel-collector.agentevals.svc.cluster.local:4317 \ - --set otel.traces.enabled=true --set otel.logs.enabled=true \ - --set otel.capture.messageContent=true --wait + --set-string config.telemetry.traces.endpoint=http://otel-collector.agentevals.svc.cluster.local:4317 \ + --set-string config.runtimeDefaults.telemetry.traces.endpoint=http://otel-collector.agentevals.svc.cluster.local:4317 \ + --set-string config.runtimeDefaults.telemetry.logs.endpoint=http://otel-collector.agentevals.svc.cluster.local:4317 \ + --set config.runtimeDefaults.telemetry.captureContent=true --wait ``` -Heads up: `messageContent` puts prompts, responses and tool arguments on spans. agentevals needs them, but they can be sensitive. +`config.telemetry` covers the kagent controller, `config.runtimeDefaults.telemetry` the agents. + +Heads up: `captureContent` puts prompts, responses and tool arguments on spans. agentevals needs them, but they can be sensitive. -Create the agents. `agents.yaml` has one Harness per runtime and one Agent on each. kagent only takes harness images pinned by digest, so look them up for your release: +Create the agents. `agents.yaml` has one Agent on each of the `kagent-default` (Go ADK) and `claude-default` Harnesses that `kagent install` creates: ```bash -digest() { - docker buildx imagetools inspect "ghcr.io/kagent-dev/kagent/$1:$KAGENT_VERSION" \ - --format '{{json .Manifest}}' | jq -r .digest -} -export KAGENT_ADK_GO_IMAGE=ghcr.io/kagent-dev/kagent/golang-adk@$(digest golang-adk) -export KAGENT_CLAUDE_IMAGE=ghcr.io/kagent-dev/kagent/claude-harness@$(digest claude-harness) -envsubst < agents.yaml | kubectl apply -f - +kubectl apply -f agents.yaml ``` kagent bakes the telemetry settings into each agent revision, so wait until `DESIRED` and `LATEST` match before chatting: @@ -191,21 +181,10 @@ kagent writes a TaskStore gRPC span for every streamed chunk, so a long turn can The answer agentevals shows for a Claude Code turn is everything the harness streamed in it, so it can start with a line like *I'll use the Kubernetes tools to check...* before the actual answer. This lowers `response_match_score` a bit when the golden run is not a Claude Code session. -## Older kagent versions - -Before `v1.0.0-alpha12`, the Claude runtime exports only Claude Code's own `claude_code.*` spans, and you get just the message and the answer. The Agent API is different there too, so `agents.yaml` does not apply as is. - -The `transform/claude_code` processor in `otel-collector.yaml` fills part of the gap for Claude Code 2.1.285: - -* `claude_code.tool` becomes `execute_tool`, with `gen_ai.tool.name` taken from `tool_name` (minus the `mcp____` prefix) -* `claude_code.llm_request` becomes `chat`, with the model and token usage, cache reads and writes included - -Tool arguments stay missing, since Claude Code doesn't put them on its spans. From `v1.0.0-alpha12` on, the runtime writes its own GenAI spans and marks its resource with `kagent.genai.producer`. The recipe skips those processes, so calls are never counted twice, and you can drop it from the Collector config. - ## Clean up ```bash -envsubst < agents.yaml | kubectl delete -f - +kubectl delete -f agents.yaml helm uninstall agentevals -n agentevals kubectl delete -f otel-collector.yaml kubectl delete namespace agentevals diff --git a/examples/kubernetes/agents.yaml b/examples/kubernetes/agents.yaml index 3a4b489..38548e0 100644 --- a/examples/kubernetes/agents.yaml +++ b/examples/kubernetes/agents.yaml @@ -1,37 +1,6 @@ # Two kagent agents with the same prompt and tools: one on the Go ADK runtime, one on the -# Claude Code harness. Each runtime is a Harness; set the workload images to the ones of -# your kagent release, pinned by digest, and the worker pool and snapshot location to the -# ones of your kagent install. -apiVersion: api.kagent.dev/v1alpha3 -kind: Harness -metadata: - name: adk-go - namespace: kagent -spec: - kagent: {} - workload: - image: ${KAGENT_ADK_GO_IMAGE} - substrate: - workerPoolRef: - name: kagent-default - snapshotPolicy: - location: s3://ate-snapshots/kagent ---- -apiVersion: api.kagent.dev/v1alpha3 -kind: Harness -metadata: - name: claude - namespace: kagent -spec: - claude: {} - workload: - image: ${KAGENT_CLAUDE_IMAGE} - substrate: - workerPoolRef: - name: kagent-default - snapshotPolicy: - location: s3://ate-snapshots/kagent ---- +# Claude Code harness. kagent-default and claude-default are the Harnesses that +# `kagent install` creates in the kagent namespace. apiVersion: api.kagent.dev/v1alpha3 kind: Agent metadata: @@ -50,7 +19,7 @@ spec: kind: RemoteMCPServer name: kagent-tool-server harnessRef: - name: adk-go + name: kagent-default --- apiVersion: api.kagent.dev/v1alpha3 kind: Agent @@ -70,4 +39,4 @@ spec: kind: RemoteMCPServer name: kagent-tool-server harnessRef: - name: claude + name: claude-default diff --git a/examples/kubernetes/otel-collector.yaml b/examples/kubernetes/otel-collector.yaml index 20f49e0..c84458f 100644 --- a/examples/kubernetes/otel-collector.yaml +++ b/examples/kubernetes/otel-collector.yaml @@ -6,10 +6,6 @@ # filter/kagent_taskstore drops kagent's TaskStore gRPC spans: one per streamed chunk, up to # 99% of a turn's spans. Without it a long turn passes the 10,000 spans per trace that # agentevals keeps, and the turn loses its invoke_agent span. -# -# transform/claude_code is a workaround for Claude Code native telemetry on kagent before -# v1.0.0-alpha12, checked with Claude Code 2.1.285. It skips processes whose resource has -# kagent.genai.producer, where the runtime writes its own chat and execute_tool spans. apiVersion: v1 kind: ConfigMap metadata: @@ -35,25 +31,7 @@ data: error_mode: ignore traces: span: - - IsMatch(span.attributes["rpc.method"], "^kagent\\.api\\.v1alpha1\\.TaskStoreService/") - - transform/claude_code: - error_mode: ignore - trace_statements: - - context: span - # One condition on purpose: entries of this list are ORed. - conditions: - - instrumentation_scope.name == "com.anthropic.claude_code.tracing" and resource.attributes["kagent.genai.producer"] == nil - statements: - - set(span.attributes["gen_ai.operation.name"], "execute_tool") where span.name == "claude_code.tool" - - set(span.attributes["gen_ai.tool.name"], span.attributes["tool_name"]) where span.name == "claude_code.tool" - - replace_pattern(span.attributes["gen_ai.tool.name"], "^mcp__.+?__", "") - - set(span.attributes["gen_ai.operation.name"], "chat") where span.name == "claude_code.llm_request" - - set(span.attributes["gen_ai.response.model"], span.attributes["model"]) where span.name == "claude_code.llm_request" - - set(span.attributes["gen_ai.usage.input_tokens"], span.attributes["input_tokens"] + span.attributes["cache_read_tokens"] + span.attributes["cache_creation_tokens"]) where span.name == "claude_code.llm_request" - - set(span.attributes["gen_ai.usage.cache_read.input_tokens"], span.attributes["cache_read_tokens"]) where span.name == "claude_code.llm_request" - - set(span.attributes["gen_ai.usage.cache_write.input_tokens"], span.attributes["cache_creation_tokens"]) where span.name == "claude_code.llm_request" - - set(span.attributes["gen_ai.usage.output_tokens"], span.attributes["output_tokens"]) where span.name == "claude_code.llm_request" + - IsMatch(span.attributes["rpc.method"], "^kagent\\.runtime\\.v1\\.TaskStoreService/") filter/not_from_agentevals: error_mode: ignore @@ -77,7 +55,7 @@ data: pipelines: traces: receivers: [otlp] - processors: [memory_limiter, filter/kagent_taskstore, transform/claude_code] + processors: [memory_limiter, filter/kagent_taskstore] exporters: [otlp_http/agentevals] logs/agentevals: receivers: [otlp] @@ -104,7 +82,7 @@ spec: app: otel-collector annotations: # bump to restart the Collector after editing the ConfigMap - config-revision: "2" + config-revision: "3" spec: containers: - name: otelcol diff --git a/tests/fixtures/otlp/MANIFEST.md b/tests/fixtures/otlp/MANIFEST.md index 18340b9..9e50fea 100644 --- a/tests/fixtures/otlp/MANIFEST.md +++ b/tests/fixtures/otlp/MANIFEST.md @@ -8,7 +8,7 @@ Real and hand built telemetry with the turns agentevals must extract from it. `t |---|---| | `adk_py//.json` | Google ADK (Python 2.10) recordings, traces and logs in one OTLP/JSON document. One directory per telemetry mode (`v1_*` / `v2_*` schema, span or event content, content off, `_contrib` with the OpenAI v2 instrumentation underneath, `v2proj_*` the projected upstream shape). Scenarios S1 to S6b: single turn, tools, multi turn, AgentTool delegate, transfer, failures. | | `samples/*.json` | kagent Jaeger exports (`helm*`, `k8s`) and a Tempo export, as captured. | -| `kagent//*.json` | kagent recordings per release: Go ADK and the Claude harness, with and without the Collector recipe from `examples/kubernetes`. Each directory has a `README.md` with the commit, versions and prompts. | +| `kagent//*.json` | kagent recordings per release: Go ADK and the Claude harness, with and without the Claude Code Collector recipe that `examples/kubernetes` had before kagent v1.x. Each directory has a `README.md` with the commit, versions and prompts. | | `hand/*.json` | Hand built shapes: cycles, duplicate ids, remote parents, content off, deprecated keys, the three event name forms for evaluation results, OpenAI v2 logs with and without span ids, Strands span events, multi trace conversations, upstream parts, the MCP client and server spans of one tool call. | | `*.truth.json` | The expected turns for the fixture next to it. | diff --git a/tests/fixtures/otlp/kagent/v1.0.0-alpha9/README.md b/tests/fixtures/otlp/kagent/v1.0.0-alpha9/README.md index d3addd3..a93165f 100644 --- a/tests/fixtures/otlp/kagent/v1.0.0-alpha9/README.md +++ b/tests/fixtures/otlp/kagent/v1.0.0-alpha9/README.md @@ -13,7 +13,7 @@ Prompts: | `adk_go_2turn.json` | Go ADK | 2 | Sent through the Collector. kagent's TaskStore gRPC spans arrive before the root when batched per process. | | `claude_native_1turn_subagent.json` | Claude harness | 1 | Claude Code native spans only, with an `Agent` subagent. | | `claude_native_2turn.json` | Claude harness | 2 | Claude Code native spans only. Spans with `session.id` export before kagent's `invoke_agent`. | -| `claude_recipe_2turn.json` | Claude harness | 2 | `transform/claude_code` from `examples/kubernetes/otel-collector.yaml` applied: tool calls by name without arguments, model calls with usage. | +| `claude_recipe_2turn.json` | Claude harness | 2 | `transform/claude_code` applied, a Collector recipe that `examples/kubernetes/otel-collector.yaml` had before the example moved to kagent v1.x: tool calls by name without arguments, model calls with usage. | Changes from the download: