Skip to content

Commit 3121158

Browse files
authored
feat: Instrument Anthropic SDK tool runner (#1833)
Fixes #1827
1 parent d9ee02c commit 3121158

26 files changed

Lines changed: 2097 additions & 132 deletions

.changeset/slimy-hands-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"braintrust": minor
3+
---
4+
5+
feat: Instrument Anthropic SDK tool runner

e2e/scenarios/anthropic-instrumentation/__snapshots__/anthropic-v0712.log-payloads.json

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,167 @@
429429
"name": "anthropic.messages.create",
430430
"output": "1 - one\n2 - two\n3 - three",
431431
"type": "llm"
432+
},
433+
{
434+
"metadata": {
435+
"operation": "beta-tool-runner"
436+
},
437+
"metrics": {
438+
"end": 0,
439+
"start": 0
440+
},
441+
"name": "anthropic-beta-tool-runner-operation",
442+
"type": null
443+
},
444+
{
445+
"input": [
446+
{
447+
"content": "Use the get_weather tool exactly once for Paris, France. After you receive the tool result, reply with exactly that tool result text and do not call any tools again.",
448+
"role": "user"
449+
}
450+
],
451+
"metadata": {
452+
"anthropic_tool_runner_iterations": 2,
453+
"model": "claude-3-haiku-20240307",
454+
"operation": "toolRunner",
455+
"provider": "anthropic",
456+
"stop_reason": "end_turn",
457+
"stop_sequence": null
458+
},
459+
"metrics": {
460+
"completion_tokens": 58,
461+
"end": 0,
462+
"prompt_cache_creation_tokens": 0,
463+
"prompt_cached_tokens": 0,
464+
"prompt_tokens": 829,
465+
"start": 0,
466+
"time_to_first_token": 0,
467+
"tokens": 887
468+
},
469+
"name": "anthropic.beta.messages.toolRunner",
470+
"output": {
471+
"content": [],
472+
"role": "assistant"
473+
},
474+
"type": "task"
475+
},
476+
{
477+
"input": {
478+
"location": "Paris, France"
479+
},
480+
"metadata": {
481+
"provider": "anthropic"
482+
},
483+
"metrics": {
484+
"end": 0,
485+
"start": 0
486+
},
487+
"name": "tool: get_weather",
488+
"output": "The weather in Paris, France is 18C and sunny.",
489+
"type": "tool"
490+
},
491+
{
492+
"metadata": null,
493+
"metrics": {
494+
"end": 0,
495+
"start": 0
496+
},
497+
"name": "get_weather.lookup",
498+
"type": null
499+
},
500+
{
501+
"input": [
502+
{
503+
"content": "Use the get_weather tool exactly once for Paris, France. After you receive the tool result, reply with exactly that tool result text and do not call any tools again.",
504+
"role": "user"
505+
}
506+
],
507+
"metadata": {
508+
"model": "claude-3-haiku-20240307",
509+
"provider": "anthropic",
510+
"stop_reason": "tool_use",
511+
"stop_sequence": null
512+
},
513+
"metrics": {
514+
"completion_tokens": 55,
515+
"end": 0,
516+
"prompt_cache_creation_tokens": 0,
517+
"prompt_cached_tokens": 0,
518+
"prompt_tokens": 375,
519+
"start": 0,
520+
"time_to_first_token": 0,
521+
"tokens": 430
522+
},
523+
"name": "anthropic.messages.create",
524+
"output": {
525+
"content": [
526+
{
527+
"id": "<span:3>",
528+
"input": {
529+
"location": "Paris, France"
530+
},
531+
"name": "get_weather",
532+
"type": "tool_use"
533+
}
534+
],
535+
"role": "assistant"
536+
},
537+
"type": "llm"
538+
},
539+
{
540+
"input": [
541+
{
542+
"content": "Use the get_weather tool exactly once for Paris, France. After you receive the tool result, reply with exactly that tool result text and do not call any tools again.",
543+
"role": "user"
544+
},
545+
{
546+
"content": [
547+
{
548+
"caller": {
549+
"type": "direct"
550+
},
551+
"id": "<span:3>",
552+
"input": {
553+
"location": "Paris, France"
554+
},
555+
"name": "get_weather",
556+
"type": "tool_use"
557+
}
558+
],
559+
"role": "assistant"
560+
},
561+
{
562+
"content": [
563+
{
564+
"content": "The weather in Paris, France is 18C and sunny.",
565+
"tool_use_id": "<tool-use-id>",
566+
"type": "tool_result"
567+
}
568+
],
569+
"role": "user"
570+
}
571+
],
572+
"metadata": {
573+
"model": "claude-3-haiku-20240307",
574+
"provider": "anthropic",
575+
"stop_reason": "end_turn",
576+
"stop_sequence": null
577+
},
578+
"metrics": {
579+
"completion_tokens": 3,
580+
"end": 0,
581+
"prompt_cache_creation_tokens": 0,
582+
"prompt_cached_tokens": 0,
583+
"prompt_tokens": 454,
584+
"start": 0,
585+
"time_to_first_token": 0,
586+
"tokens": 457
587+
},
588+
"name": "anthropic.messages.create",
589+
"output": {
590+
"content": [],
591+
"role": "assistant"
592+
},
593+
"type": "llm"
432594
}
433595
]

e2e/scenarios/anthropic-instrumentation/__snapshots__/anthropic-v0712.span-events.json

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,119 @@
353353
"<span:18>"
354354
],
355355
"type": "llm"
356+
},
357+
{
358+
"has_input": false,
359+
"has_output": false,
360+
"metadata": {
361+
"operation": "beta-tool-runner"
362+
},
363+
"metric_keys": [],
364+
"name": "anthropic-beta-tool-runner-operation",
365+
"root_span_id": "<span:1>",
366+
"span_id": "<span:20>",
367+
"span_parents": [
368+
"<span:1>"
369+
],
370+
"type": null
371+
},
372+
{
373+
"has_input": true,
374+
"has_output": true,
375+
"metadata": {
376+
"anthropic_tool_runner_iterations": 2,
377+
"model": "claude-3-haiku-20240307",
378+
"operation": "toolRunner",
379+
"provider": "anthropic"
380+
},
381+
"metric_keys": [
382+
"completion_tokens",
383+
"prompt_cache_creation_tokens",
384+
"prompt_cached_tokens",
385+
"prompt_tokens",
386+
"time_to_first_token",
387+
"tokens"
388+
],
389+
"name": "anthropic.beta.messages.toolRunner",
390+
"root_span_id": "<span:1>",
391+
"span_id": "<span:21>",
392+
"span_parents": [
393+
"<span:20>"
394+
],
395+
"type": "task"
396+
},
397+
{
398+
"has_input": true,
399+
"has_output": true,
400+
"metadata": {
401+
"provider": "anthropic"
402+
},
403+
"metric_keys": [],
404+
"name": "tool: get_weather",
405+
"root_span_id": "<span:1>",
406+
"span_id": "<span:22>",
407+
"span_parents": [
408+
"<span:21>"
409+
],
410+
"type": "tool"
411+
},
412+
{
413+
"has_input": false,
414+
"has_output": false,
415+
"metadata": null,
416+
"metric_keys": [],
417+
"name": "get_weather.lookup",
418+
"root_span_id": "<span:1>",
419+
"span_id": "<span:23>",
420+
"span_parents": [
421+
"<span:22>"
422+
],
423+
"type": null
424+
},
425+
{
426+
"has_input": true,
427+
"has_output": true,
428+
"metadata": {
429+
"model": "claude-3-haiku-20240307",
430+
"provider": "anthropic"
431+
},
432+
"metric_keys": [
433+
"completion_tokens",
434+
"prompt_cache_creation_tokens",
435+
"prompt_cached_tokens",
436+
"prompt_tokens",
437+
"time_to_first_token",
438+
"tokens"
439+
],
440+
"name": "anthropic.messages.create",
441+
"root_span_id": "<span:1>",
442+
"span_id": "<span:24>",
443+
"span_parents": [
444+
"<span:21>"
445+
],
446+
"type": "llm"
447+
},
448+
{
449+
"has_input": true,
450+
"has_output": true,
451+
"metadata": {
452+
"model": "claude-3-haiku-20240307",
453+
"provider": "anthropic"
454+
},
455+
"metric_keys": [
456+
"completion_tokens",
457+
"prompt_cache_creation_tokens",
458+
"prompt_cached_tokens",
459+
"prompt_tokens",
460+
"time_to_first_token",
461+
"tokens"
462+
],
463+
"name": "anthropic.messages.create",
464+
"root_span_id": "<span:1>",
465+
"span_id": "<span:25>",
466+
"span_parents": [
467+
"<span:21>"
468+
],
469+
"type": "llm"
356470
}
357471
]

0 commit comments

Comments
 (0)