-
Notifications
You must be signed in to change notification settings - Fork 48
Surface Anthropic server_tool_use and web_search_tool_result response blocks #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e63be0d
a028a35
dda4f0a
a712772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,6 +296,55 @@ func (a *client) buildBlock(index int, v any, contents []message.Content, functi | |
| Name: v.Name, | ||
| Arguments: string(v.Input), | ||
| } | ||
| case anthropic.ServerToolUseBlock: | ||
| // Server-side tool invocations (e.g. web_search) are executed by | ||
| // Anthropic itself. Surface them as function calls so callers can | ||
| // observe the request, mirroring the client-side ToolUseBlock handling | ||
| // and the Python SDK's server_tool_use parsing. Unlike client tool | ||
| // calls these are appended in place (not via the functions map, which | ||
| // is nil on the streaming path) since Anthropic already ran them. | ||
| var args string | ||
| if v.Input != nil { | ||
| if b, err := json.Marshal(v.Input); err == nil { | ||
| args = string(b) | ||
| } | ||
| } | ||
| contents = append(contents, &message.FunctionCallContent{ | ||
| CallID: v.ID, | ||
| Name: string(v.Name), | ||
| Arguments: args, | ||
| ContentHeader: message.ContentHeader{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity gap: The upstream Python implementation sets informational_only=content_block.type == "server_tool_use",This flag tells the tool-autocall harness not to attempt re-execution — the server already ran the tool. Go's As written, the Go Suggested fix: contents = append(contents, &message.FunctionCallContent{
CallID: v.ID,
Name: string(v.Name),
Arguments: args,
InformationalOnly: true, // server already executed this; do not re-invoke locally
ContentHeader: message.ContentHeader{
RawRepresentation: v,
},
}) |
||
| RawRepresentation: v, | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity issue: The Python implementation ( This PR omits Suggested fix: contents = append(contents, &message.FunctionCallContent{
CallID: v.ID,
Name: string(v.Name),
Arguments: args,
InformationalOnly: true, // Anthropic executed this server-side; skip local dispatch
ContentHeader: message.ContentHeader{
RawRepresentation: v,
},
})Upstream reference: |
||
| }) | ||
| case anthropic.WebSearchToolResultBlock: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity gap — The upstream Python SDK sets # python/packages/anthropic/agent_framework_anthropic/_chat_client.py, ~line 1256
Content.from_function_call(
call_id=content_block.id,
name=resolved_tool_name,
arguments=content_block.input,
informational_only=content_block.type == "server_tool_use", # True for server tools
raw_representation=content_block,
)The Go Suggested fix: contents = append(contents, &message.FunctionCallContent{
CallID: v.ID,
Name: string(v.Name),
Arguments: args,
InformationalOnly: true, // server tool was already executed by Anthropic
ContentHeader: message.ContentHeader{
RawRepresentation: v,
},
}) |
||
| // The paired result for a server-side web search. Surface it as a | ||
| // function result whose citations point at each source, matching the | ||
| // Python SDK's web_search_tool_result handling. | ||
| result := &message.FunctionResultContent{ | ||
| CallID: v.ToolUseID, | ||
| ContentHeader: message.ContentHeader{ | ||
| RawRepresentation: v, | ||
| }, | ||
| } | ||
| if v.Content.Type == "web_search_tool_result_error" { | ||
| searchErr := v.Content.AsResponseWebSearchToolResultError() | ||
| result.Error = fmt.Errorf("web search failed: %s", searchErr.ErrorCode) | ||
| result.Result = string(searchErr.ErrorCode) | ||
| } else { | ||
| results := v.Content.AsWebSearchResultBlockArray() | ||
| var annotations []message.Annotation | ||
| for _, r := range results { | ||
| annotations = append(annotations, &message.CitationAnnotation{ | ||
| Title: r.Title, | ||
| URL: r.URL, | ||
| RawRepresentation: r, | ||
| }) | ||
| } | ||
| result.Annotations = annotations | ||
| result.Result = results | ||
| } | ||
| contents = append(contents, result) | ||
| } | ||
| return contents | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity note: The Python implementation maps This PR instead:
This is a richer representation, but it diverges from the upstream Go convention where If cross-SDK consistency matters here, consider aligning with Python by passing Upstream reference: |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parity issue:
InformationalOnlynot set forserver_tool_useblocksThe Python
_chat_client.pyexplicitly marks server-side tool calls as informational-only (_chat_client.pyline 1271):The Go
FunctionCallContentemitted here is missingInformationalOnly: true. Without it, the Go tool auto-call harness (autocall.go) will treat this as a locally-executable tool and try to dispatchweb_searchor other server-side tools as client-side calls — which will fail, since Anthropic already executed them.Suggested fix:
Upstream reference:
python/packages/anthropic/agent_framework_anthropic/_chat_client.pyline 1271.