[bot] Anthropic tool_runner agentic loop not instrumented
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 58/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- ruby
调研方向
先从 lib/braintrust/contrib/anthropic/patcher.rb 和 instrumentation/beta_messages.rb 开始,然后检查 issue 中提到的 Anthropic SDK 的 tool_runner 方法。对比 lib/braintrust/contrib/ruby_llm/instrumentation/chat.rb 中嵌套的 tool span 模式。完成的标准是 runner 具有一个整体 trace,每个 BaseTool#call 都有一个子 tool span,并且所有列出的执行模式都得到覆盖。
由索引模型根据 Issue 内容生成。
描述
Summary
The Anthropic Ruby SDK provides client.beta.messages.tool_runner(...), a beta agentic loop API that automatically executes tools and manages the multi-turn conversation cycle. This surface is not instrumented. The SDK currently instruments beta.messages.create() and beta.messages.stream() (via BetaMessagesPatcher), so individual LLM calls within the runner may produce spans, but the tool executions and overall agentic run are invisible in traces.
What is missing
The tool_runner API (Anthropic::Resources::Beta::Messages#tool_runner) returns a runner object with these execution methods:
each_message { |msg| ... }— iterates through the agentic loop, auto-executing tools viaBaseTool#callbetween iterationsrun_until_finished— runs the full loop and returns all messagesnext_message— step-by-step manual iterationeach_streaming { |event| ... }— streaming variant of the agentic loop
At each iteration, the runner:
- Sends a message to Claude (this call IS traced via existing
BetaMessagesPatcher) - Detects tool_use blocks in Claude's response
- Executes
BaseTool#callon the matching tool (NOT traced) - Sends tool results back and loops
What instrumentation should capture
Parent span for the agentic run (e.g., anthropic.tool_runner):
- Input: initial messages and tool definitions
- Output: final response after all tool loops complete
- Metrics: aggregate token usage across all iterations, total duration
Child spans for each tool execution (e.g., anthropic.tool.{tool_name}):
- Input: tool name + arguments (from Claude's tool_use block)
- Output: tool result (from
BaseTool#callreturn value) - Span attributes:
{type: "tool"}
This pattern is already established in this repo — the RubyLLM integration creates ruby_llm.tool.{tool_name} child spans with braintrust.span_attributes: {type: "tool"} for each tool execution in lib/braintrust/contrib/ruby_llm/instrumentation/chat.rb.
Braintrust docs status
- Braintrust documents "tool" as a first-class span type: "A tool call made by the model — an external API, code execution, database query, etc." (tracing guide)
- Ruby-specific tool_runner instrumentation: not_found
Upstream sources
- Anthropic tool_runner documentation: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner
- Anthropic Ruby SDK helpers: https://github.com/anthropics/anthropic-sdk-ruby/blob/main/helpers.md#3-auto-looping-tool-runner-beta
- Anthropic Ruby SDK on RubyGems: https://rubygems.org/gems/anthropic
Local repo files inspected
lib/braintrust/contrib/anthropic/patcher.rb— definesMessagesPatcherandBetaMessagesPatcher; no tool_runner patcherlib/braintrust/contrib/anthropic/instrumentation/beta_messages.rb— wrapscreate()andstream()only; notool_runnerwrapper- Grep for
tool_runner,BaseTool,each_message,run_until_finishedacrosslib/— zero matches lib/braintrust/contrib/ruby_llm/instrumentation/chat.rb— demonstrates the existing pattern for tool execution tracing with nested spans
- 主要语言
- Ruby
- 星标
- 9
- 派生
- 11
- 平均合并
- 3 天 43 分钟
- 30 天内合并 PR
- 9
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
braintrustdata/braintrust-sdk-ruby 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
braintrustdata/braintrust-sdk-ruby#155 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
braintrustdata/braintrust-sdk-ruby#143 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
braintrustdata/braintrust-sdk-ruby#137 ·
维护者通常 1 天内回复
-
ruby
难度 3/5 半天 新手友好度 62/100
braintrustdata/braintrust-sdk-ruby#229 ·
维护者通常 1 天内回复
-
ruby
难度 3/5 1-2 天 新手友好度 45/100
braintrustdata/braintrust-sdk-ruby#228 ·
维护者通常 1 天内回复
查看 braintrustdata/braintrust-sdk-ruby 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 66/100
NatLabRockies/OpenStudio-HPXML#2284 ·
-
aikido security:critical
难度 2/5 1-3 小时 新手友好度 75/100
dequelabs/axe-core-gems#532 ·
-
难度 2/5 1-3 小时 新手友好度 67/100
phusion/passenger-docker#480 ·
-
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 5 天内回复
-
f:search improvement user-experience
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复