Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(anthropic-responses-bridge): tool_result 图像占位文案说明协议限制并禁止臆测 (#829)
fico-hub510b468b18fa
diff --git a/packages/anthropic-responses-bridge/src/__tests__/translate-request.test.ts b/packages/anthropic-responses-bridge/src/__tests__/translate-request.test.tsindex ecf4d6cc58..e40144ad3d 100644--- a/packages/anthropic-responses-bridge/src/__tests__/translate-request.test.ts+++ b/packages/anthropic-responses-bridge/src/__tests__/translate-request.test.ts@@ -179,6 +179,40 @@ describe('translateRequest', () => {expect(out.input).toEqual([{ type: 'function_call_output', call_id: 'c1', output: 'r1\nr2' }]);});+ it('tool_result 图像块降级为带说明的占位文案,图像数据不外泄 (#795)', () => {+ const req: AnthropicMessagesRequest = {+ model: 'gpt-5.5',+ messages: [+ {+ role: 'user',+ content: [+ {+ type: 'tool_result',+ tool_use_id: 'c1',+ content: [+ { type: 'text', text: 'screenshot below' },+ { type: 'image', source: { type: 'base64', media_type: 'image/png', data: 'AAAABBBB' } },+ ],+ },+ ],+ },+ ],+ };+ const out = translateRequest(req, { model: 'gpt-5.5' });+ // 先断言长度再取元素:input 缺失时给出清晰断言失败而不是 TypeError。+ expect(out.input).toHaveLength(1);+ const item = out.input![0] as { type: string; output: string };+ expect(item.type).toBe('function_call_output');+ expect(item.output).toContain('screenshot below');+ // 占位文案要素:确认有图、说明送不到是路由限制、禁止臆测、给出改走 user 消息的出路。+ expect(item.output).toContain('[image omitted:');+ expect(item.output).toContain('Do NOT guess');+ expect(item.output).toContain('attach the image');+ // 图像字节与旧版裸占位符都不应出现。+ expect(item.output).not.toContain('AAAABBBB');+ expect(item.output).not.toContain('[image]');+ });+it('serverSideTools 恒定追加在 function tools 之后(位置固定 → 前缀稳定)', () => {const req: AnthropicMessagesRequest = {model: 'xai/grok-4.5',diff --git a/packages/anthropic-responses-bridge/src/translate-request.ts b/packages/anthropic-responses-bridge/src/translate-request.tsindex 2d726a81e9..60f8f12241 100644--- a/packages/anthropic-responses-bridge/src/translate-request.ts+++ b/packages/anthropic-responses-bridge/src/translate-request.ts@@ -58,7 +58,19 @@ function toolResultToString(content: unknown): string {if (rec.type === 'text' && typeof rec.text === 'string') return rec.text;// 工具结果里嵌图片等非文本内容:Responses 的 function_call_output 只吃字符串,// 退化成占位描述,不丢整条(模型仍知道该工具产出过内容)。- if (rec.type === 'image') return '[image]';+ // 占位文案必须说明「有图但送不到、不要猜」:字符串限制是协议层的,与模型+ // 是否具备视觉能力无关;不带说明的 '[image]' 会被模型当作空结果,诱发反复+ // 重读或臆测图像内容。图像走 user 消息路径仍可正常送达(input_image)。+ if (rec.type === 'image') {+ return (+ '[image omitted: this tool returned an image, but tool results on this '+ + 'provider route are delivered as plain text only, so the image data could '+ + 'not be included. Do NOT guess or fabricate what the image contains. '+ + 'Tell the user the image could not be delivered on the current route, and '+ + 'ask them to paste the relevant content as text or attach the image '+ + 'directly to a chat message instead.]'+ );+ }return JSON.stringify(rec);}return String(b);