Skip to content

Anthropic PTC: verbatim caller echo-back + code_execution_tool_result round-trip - #2508

Merged
topcheer merged 2 commits into
mainfrom
sa-66
Sep 18, 2026
Merged

topcheer merged 2 commits into
mainfrom
sa-66

Conversation

@topcheer

Copy link
Copy Markdown
Owner

Summary

  • Carry the verbatim caller field of Anthropic tool_use blocks (programmatic tool calling) through streaming and non-streaming paths into the persisted assistant message (ContentBlock.CallerRaw / ToolCallDelta.Caller), and restore it via toolUseBlockParam on the next request — required so the API can match client tool_results to pending programmatic calls in the code execution container.
  • Add code_execution_tool_result support to serverToolBlockParam so the in-container exchange round-trips losslessly like web_search/web_fetch results.
  • Declare ToolDefinition.AllowedCallers and document the code_execution_20260120 server tool semantics in config.

Tests

  • New anthropic_ptc_test.go: caller round-trip through convertAnthropicResponse, request-block caller restore, isProgrammaticCaller type detection, code_execution_tool_result param construction (4 passing).
  • go build -tags goolm ./... clean; provider/agent/config package tests green; GOOS=linux vet clean.

Co-Authored-By: ggcode noreply@ggcode.dev

@topcheer topcheer left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审通过 ✅(无协查报文主动复审)

容器生命周期正确:30s 安全边界(expires-30s 判死)+过期 ID omit 而非发送(API 拒未知容器不自动新建——省略字段让 API provision 新的是唯一正确路径);Chat/ChatStream 双路径捕获(message_start 事件+非流式 resp)。

tool_result-only 格式规则健壮:programmatic caller 回答消息剥非 tool_result 块(strip+log 而非 fail——泄漏文本噪声不炸请求)+system 前置注入对该类消息跳过(toolResultOnly 分支)——两处细节都防了 API 硬拒。

allowed_callers 语义:PTC 启用默认 [direct, code_execution_20260120](推荐双通道)+显式声明优先——非 PTC 端点行为零变。

code_execution 流式双形态:tool_use 载 caller 的 PTC echo-back(完整 tool_use 字段非 bare server_tool_use——续轮合法回显)+code_execution_tool_result verbatim。

非阻塞观察:beta 头用 option.WithHeader(request 层)而 #2488 context-editing 用 transport.UpdateHeaders(merge 模式 toggleBetaToken)——同时启用两 beta 特性时 request 层 Set 可能覆盖 transport 层的 anthropic-beta(丢 context-management token)。建议归属者确认 SDK merge 行为或统一走 toggleBetaToken 路径。

7 测试。CI 绿。可合并。

@topcheer

Copy link
Copy Markdown
Owner Author

复审已过(见 review:容器 30s 边界+过期 omit 让 API 新建、tool_result-only strip 不 fail+system 前置跳过、allowed_callers 默认双通道+显式优先、caller 完整 echo-back)。非阻塞观察:beta 头走 option.WithHeader(request 层)而 #2488 context-editing 走 transport merge(toggleBetaToken)——同启两 beta 特性时 request 层 Set 可能覆盖 transport 的 anthropic-beta(丢 context-management token),建议确认 SDK 行为或统一 toggleBetaToken。

与 main 冲突——#2506 先合并动了 anthropic.go 相邻区(SetServerTools 后区域)。分支 sa-66 有归属者本地 worktree 在途——请归属者 rebase main 解冲突(顺带处理 beta 头路径统一),解后 CI 绿即合并。不代解。

Junjun Zhang and others added 2 commits September 18, 2026 14:02
… round-trip (#sa-66)

Programmatic tool calling (code execution container invoking client tools)
requires the API to see the caller field and the code_execution_tool_result
block again on every continuation request, or it cannot match the client
tool_result to the pending programmatic call:

- ContentBlock.CallerRaw / ToolCallDelta.Caller carry the verbatim "caller"
  field of a tool_use block through streaming (content_block_start) and
  non-streaming (convertAnthropicResponse) paths; the agent copies it into
  the persisted assistant block.
- toolUseBlockParam restores the caller field (direct / code_execution_*)
  on the next request; without it the API rejects the tool_result.
- serverToolBlockParam now supports "code_execution_tool_result" blocks so
  the in-container exchange round-trips losslessly like web_search results.

Unit tests cover caller round-trip, request-block restore, caller-type
detection, and code_execution_tool_result param construction.

Co-Authored-By: ggcode <noreply@ggcode.dev>

Co-Authored-By: ggcode <noreply@ggcode.dev>
Co-Authored-By: ggcode <noreply@ggcode.dev>
@topcheer
topcheer merged commit 9a5e054 into main Sep 18, 2026
8 checks passed
@topcheer
topcheer deleted the sa-66 branch September 18, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant