← 返回全部急救指南
medium
✓ 实测验证日期: 2026-11-26 Gemini API v1beta / Gemini 4 Thinking
protocol google gemini-apiagygemini-cli
400 Function Call / Function Response 轮次状态不对齐
400 INVALID_ARGUMENT MALFORMED_FUNCTION_CALL
常见症状特征
- • Multi-turn agent fails with `400 INVALID_ARGUMENT` stating function response turn must immediately follow function call turn.
- • Truncating conversation history mid-tool-loop leaves an orphaned `functionCall` or `functionResponse`.
- • Missing `thought_signature` when replaying thinking-enabled function call turns.
故障根因
Gemini 要求模型的 `functionCall` 轮次必须紧跟对应的 `functionResponse` 轮次(且思考模型须原样保留 `thought_signature`)。按条数机械截断历史记录会破坏该不变量。
分步修复步骤
- 1 确保每个
functionCall轮次后紧跟名称与 ID 完全匹配的functionResponse。 - 2 裁剪或压缩会话历史时,必须按完整的
user -> model -> tool -> model事务边界切分。 - 3 回传 Gemini 4 思考模型历史消息时,原样保留包含
thought_signature在内的模型 Parts。
一键复制修复命令
Run agycraft doctor to check MCP tool schema & transcript loop health (all)
npx agycraft-mcp doctor 修完验证命令
Verify
npx agycraft-mcp doctor