[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)

未关闭
#6,480 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 apps/application/flow/tools.py 中的 _yield_mcp_response() 开始,然后按描述在整个代码树中搜索 input_json_delta 和 partial_json。复现一次流式 Anthropic 工具调用,并将其与正常工作的 OpenAI 形 provider 进行比较;当工具值能够到达答案且不出现 Anthropic BadRequestError 时即表示完成。

由索引模型根据 Issue 内容生成。

描述

Type: To Be Verified
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
  1. Register an Anthropic model (reproduced with claude-sonnet-5, model_anthropic_provider).
  2. Create a SIMPLE agent using that model.
  3. 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.'
  1. 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."
  2. Call the OpenAI-compatible endpoint with stream: true (required — with tools attached, stream: false is 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.8k
派生
3.2k
平均合并
1 小时 19 分钟
30 天内合并 PR
286

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

1Panel-dev/MaxKB 的其他 Issue

查看 1Panel-dev/MaxKB 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。