Repository navigation
Conversation
Devin rejects a history sequence where several assistant messages each carry a single toolCall followed by their results. The OpenAI Responses protocol emits each call as its own function_call item, and the adapter turned every item into a separate AssistantMessage, so a turn with parallel tool calls produced exactly that illegal sequence and upstream answered: invalid_argument: There is an issue with this request, please try a different model. Devin expects all tool calls issued in one generation to sit in a single assistant message with a toolCalls array. Append a function_call to the preceding assistant message when that message is a tool-use turn, instead of starting a new one. The guard on StopReason == StopReasonToolUse keeps text-only assistant turns from absorbing a later call, so serial tool-call history is unchanged. Fixes leookun#7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
当一轮里模型并行调用多个工具时,第二次及以后的请求会被 Devin 上游拒绝:
上游给出的提示具有误导性,它并不是真的建议换个模型。
根因
两侧对「一次生成发出的多个工具调用」的消息结构要求不同:
function_callitemtoolCalls数组里appendInputItem的function_call分支为每个 item新建一条AssistantMessage,于是并行调用被转成了「多条 assistant 各带一个 toolCall,后面跟多个结果」这种序列,上游判定为非法。串行调用不受影响,所以问题只在并行时暴露——这也是它不容易被发现的原因。
复现
修复前返回 400
invalid_argument,修复后返回 200,且模型能正确读到两条工具结果。修复
在
function_call分支里,若上一条消息是 tool-use 轮次的 assistant 消息,就把本次调用并入其Content,而不是新建一条消息。守卫条件
assistant.StopReason == llm.StopReasonToolUse是关键:纯文本 assistant 消息(StopReason为零值)不会被后续调用吞并,因此串行历史完全不变。reasoningitem 走default分支被忽略,不参与合并。验证
TestDecodeRequestMergesParallelFunctionCalls:断言并行调用合并成一条 assistant 消息、Content持有全部调用、且每个call_id仍能解析出工具名(function_call_output的处理依赖它)go test ./...全部 12 个包通过,无回归call,out,call,call,out,out)、三路并行,修复后全部 200toolCalls的消息未运行
gofmt -w:HEAD 版本即不符合 gofmt(Windows checkout 的 CRLF 所致),全量格式化会重写整个文件并污染 diff。本次改动自身格式干净。Fixes #7