Repository navigation
[bug] llm-deepseek: user text serializes before role:tool messages, breaking the tool_calls adjacency requirement #3046
kharkilirov1
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Affected: master @
0.1.0-rc.7—packages/llm/llm-deepseek/src/serialize.ts,serializeMessagesuser-role branch (~L129)Symptom
The OpenAI/DeepSeek chat API requires every
role:"tool"message to immediately follow the assistanttool_callsturn it answers (the documented tool-call flow isassistant(tool_calls) → tool → next requeston every tool sub-turn). When one harness user message carries bothtool-resultblocks and trailing text, the serializer emits theusertext message first and therole:"tool"messages after.Reproduction
Unit-level and deterministic: call
serializeMessageswith a conversation whose last user message carries onetool-resultblock followed by a text block (i.e. every turn where tool results accompany a user reply).Expected wire:
Actual wire:
Root cause
In the user-role branch, the flattened text is pushed onto the wire before the tool-result blocks are expanded into
role:"tool"messages.Fix
Emit the
role:"tool"blocks first and the text as the trailing user message. The harness user-message structure and the session log are unchanged — only the wire emission order moves, so this is a pure adapter fix.A tested patch (ordering regression test in
serialize.spec.ts) is available in my fork:Happy to adapt it to the maintainers' preferred format.
All reactions