feat(anthropic): instrument beta tool runner with parent chain and child tool spans - #3531
Open
Aryan-Pardeshi wants to merge 1 commit into
Open
Conversation
…ild tool spans Wraps Messages.tool_runner / AsyncMessages.tool_runner (anthropic>=0.84.0 beta surface) so a tool-runner run produces one CHAIN parent span named beta.messages.tool_runner with TOOL child spans for each tool invocation, instead of a set of disconnected single-LLM spans. Adds sync/async tests with mocked HTTP responses and a tool_runner example. Closes Arize-ai#3392
Contributor
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3392
The instrumentor wraps
completions.create,messages.create,messages.stream,messages.parseand thebeta.messagesequivalents, but not the beta tool runner. A run that lets the SDK resolve tool calls automatically therefore produces a set of disconnected single-LLM-span traces, with no span for any tool actually invoked and nothing tying the turns together.This wraps
beta.messages.tool_runner(sync and async) so a run emits a parent span for the runner with childTOOLspans for each tool invocation, using the existing OpenInference tool attribute conventions. Both wrappers follow the structure already in_wrappers.pyand are unwound in_uninstrument, so instrumenting and uninstrumenting stays symmetric.Also adds
examples/tool_runner.py, mirroring the existingend_to_end_tool_use.py, and a CHANGELOG entry.Written and verified against anthropic 0.84.0. Worth flagging that this is a beta SDK surface: the entry point was confirmed by inspecting
anthropic.resources.beta.messages.Messageson that version rather than taken from the docs, but it can move.Full package suite passes: 53 passed.
ruff checkandruff format --checkare clean across the package.