Skip to content

fix(session): keep tool-call arguments as mappings - #2143

Open
atirna wants to merge 5 commits into
XiaomiMiMo:mainfrom
atirna:fix/subagent-messages-serialization
Open

fix(session): keep tool-call arguments as mappings#2143
atirna wants to merge 5 commits into
XiaomiMiMo:mainfrom
atirna:fix/subagent-messages-serialization

Conversation

@atirna

@atirna atirna commented Aug 17, 2026

Copy link
Copy Markdown

Issue / context

Fixes #2116

子 agent spawn 之后第一次请求就 400('int' object has no attribute 'items'),然后这个 session 里换任何模型都一样,直到新开一个。

Type of change

Bug fix

What does this PR do?

SenseNova / 其它 Python OpenAI-compatible 后端会对 tool_call.function.argumentsjson.loads.items()。tool input 如果是个数字,@ai-sdk/openai-compatibleJSON.stringify(0) 发出去变成 "0",对面 parse 成 int,这段 history 就废了。子 agent spawn 会把 parent 的 inheritedMessages 拼进第一次请求,所以一 spawn 就中。

I coerce primitive/null tool inputs to a mapping in toModelMessages ({} or { value }). ProviderTransform.message also drops stray non-object entries in the messages list and does the same input wrap, since that's the pre-send choke point on the fork path.

How did you verify your code works?

before, on current main: a numeric tool-call input ships as arguments JSON 0 (locked @ai-sdk/openai-compatible@2.0.41).

after:

  • toModelMessages turns input 0 into { value: 0 }
  • fork-style [...inheritedMessages, ...ownNew, 0] through ProviderTransform.message then a mocked compatible provider: every message is a dict, every function.arguments parses to a non-array object
bun test test/session/message-v2.test.ts test/provider/openai-compatible-messages-schema.test.ts test/provider/transform.test.ts
# 278 pass / 0 fail
bun typecheck
bun lint

Screenshots / recordings

n/a, not a UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

SenseNova and other Python OpenAI-compatible backends json.loads
function.arguments then call .items(). A primitive tool input serializes
as a JSON number and 400s every later request in the session, including
the first call after a subagent spawn.
@atirna
atirna force-pushed the fix/subagent-messages-serialization branch from f8b7f16 to 2e7b11c Compare August 17, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

子 Agent Spawn 时 messages 序列化错误导致所有模型持续 400 报错

1 participant