[Bug] Anthropic models: tool calls fail with "Input tag 'input_json_delta' ... does not match any of the expected tags" (streamed tool_use never assembled)
維護者通常 1 天內回覆
@lorenzozanee 已經在處理了。
開始於 2026年9月15日。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 68/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- ai, backend-api-design
研究方向
從 apps/application/flow/tools.py 中的 _yield_mcp_response() 開始,接著按照描述在整個程式碼樹中搜尋 input_json_delta 和 partial_json。重現一次串流的 Anthropic 工具呼叫,並將其與正常運作的 OpenAI 形狀 provider 進行比較;當工具值能夠抵達答案且不發生 Anthropic BadRequestError 時即表示完成。
由索引模型根據 Issue 內容生成。
描述
MaxKB Version
v2.10.4-lts (also reproduced on v2.10.2-lts)
Problem Description
When an application has a custom tool attached and uses an Anthropic model (model_anthropic_provider), every message that triggers a tool call fails. The Anthropic API rejects MaxKB's follow-up request:
BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error',
'message': "messages.1.content.1: Input tag 'input_json_delta' found using 'type' does not match any of the expected tags"}}
and, in the other variant:
BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error',
'message': 'messages: text content blocks must be non-empty'}}
MaxKB returns this to the caller as HTTP 200 with the error text as the answer body, so it reaches end users as the assistant's reply.
Cause
input_json_delta is an Anthropic streaming event type, not a message content type. Anthropic streams tool arguments as a series of content_block_delta events of type input_json_delta, each carrying a partial_json fragment. These must be accumulated and assembled into a completed tool_use content block before the assistant turn is replayed in messages.
MaxKB appears to replay the raw streamed deltas instead. A search of the v2.10.4-lts tree finds no handling for either field:
grep -rn "input_json_delta\|partial_json" apps/ # zero hits
_yield_mcp_response() in apps/application/flow/tools.py handles only OpenAI-shaped tool deltas (tool_call_chunks / tool_calls / invalid_tool_calls). There is no branch for Anthropic content blocks, which is consistent with both error messages: the unassembled delta is sent verbatim, and the accompanying text block is empty.
Steps to Reproduce
- Register an Anthropic model (reproduced with
claude-sonnet-5,model_anthropic_provider). - Create a SIMPLE agent using that model.
- Create a custom Python tool and attach it (
tool_enable: true), e.g.
def live_price(query):
return 'DJI Neo: 4242.42 GEL, in stock.'
- Set the system prompt so the tool is actually used, e.g. "For any question about price or stock you MUST call the live_price tool."
- Call the OpenAI-compatible endpoint with
stream: true(required — with tools attached,stream: falseis unsupported per #6300 / #4846 / #4363):
curl -N "$MAXKB/chat/api/$APP_ID/chat/completions" \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"gpt-3.5-turbo","stream":true,"messages":[{"role":"user","content":"How much is the DJI Neo?"}]}'
Expected: the answer quotes the tool's value (4242.42 GEL).
Actual: the answer is the BadRequestError text above.
The same setup works on an OpenAI-shaped provider
Identical agent, identical tool, identical prompt, only the model swapped to model_openai_provider (gpt-4o-mini): no error, and the answer contains 4242.42 GEL, confirming the tool executed. This isolates the defect to the Anthropic provider's streamed tool-call handling rather than to tools, sandboxing, or the endpoint.
Impact
Custom tools and MCP cannot be used at all with Anthropic models. Because tools require stream: true, and streaming is exactly where the assembly fails, there is no working combination for Anthropic users.
Tested on v2.10.2-lts and v2.10.4-lts (CE), Docker, single-node.
- 主要語言
- Python
- 星號
- 22.9k
- 分支
- 3.2k
- 平均合併
- 2 小時 11 分鐘
- 30 天內合併 PR
- 235
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
1Panel-dev/MaxKB 的其他 Issue
-
[Bug] ai回答和思考内容有时图片不显示可能已有人在做 @zyyfit 於 1 天前認領。 未關閉
1Panel-dev/MaxKB#7314 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[Bug] 智能体导入有引用工具,一个用户能正常导入,另一个用户再导入工具没有权限可能已有人在做 @zyyfit 於 1 天前認領。 未關閉Type: Bug
1Panel-dev/MaxKB#7302 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[Bug] 智能体中引用共享工具,导出后,另一用户再导入相同的工作空间报没权限可能已有人在做 @zyyfit 於 1 天前認領。 未關閉
1Panel-dev/MaxKB#7301 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[Bug] IAM同步的密码不支持特殊字符可能已有人在做 @zyyfit 於 5 天前認領。 未關閉Type: Bug
1Panel-dev/MaxKB#7268 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[Feature] 优化 待改进的问题可能已有人在做 @baixin513 於 6 天前認領。 未關閉
1Panel-dev/MaxKB#7247 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
相似的 Issue
-
good first issue
難度 2/5 1-3 小時 新手友好度 85/100
btclib-org/btclib-node#1955 ·
維護者通常 1 天內回覆
-
documentation v0.9.2
難度 2/5 半天 新手友好度 72/100
khuisman/mcp-gee-sweet#1033 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
ossf/cve-bin-tool#5966 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 2 天內回覆
-
write_iceberg ignores the table's write.parquet.compression-codec property可能已有人在做 @YuangGao 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
Eventual-Inc/Daft#7606 ·
維護者通常 1 天內回覆