Skip to content

fix: normalize empty tool_call arguments to "{}" before serialization#1764

Open
Haroldhhhh wants to merge 1 commit intoMoonshotAI:mainfrom
Haroldhhhh:fix/normalize-tool-call-arguments
Open

fix: normalize empty tool_call arguments to "{}" before serialization#1764
Haroldhhhh wants to merge 1 commit intoMoonshotAI:mainfrom
Haroldhhhh:fix/normalize-tool-call-arguments

Conversation

@Haroldhhhh
Copy link
Copy Markdown

@Haroldhhhh Haroldhhhh commented Apr 5, 2026

Summary

When a tool has no parameters (e.g. list_files with empty params model), the streaming response may leave ToolCall.function.arguments as None or "". On the next LLM call, model_dump(exclude_none=True) either drops the arguments field entirely or keeps the empty string.

OpenAI-compatible proxies that forward to Anthropic then fail to convert it into the required tool_use.input dict, causing a 400 error:

messages.N.content.M.tool_use.input: Input should be a valid dictionary

This patch normalizes arguments to "{}" in _convert_message before serialization, ensuring all proxies receive a parseable JSON object.

Reproduction

  1. Use OpenAILegacy provider with an OpenAI-compatible proxy that forwards to Anthropic (e.g. openai-proxy.org)
  2. In a multi-turn conversation, trigger a tool call for a zero-parameter tool
  3. The second LLM call (with tool call history) returns 400

Changes

  • packages/kosong/src/kosong/contrib/chat_provider/openai_legacy.py: Added normalization of empty arguments to "{}" in _convert_message after model_copy

Open with Devin

When a tool has no parameters (e.g. `list_files`), the streaming response
may leave `arguments` as `None` or `""`. On the second LLM call,
`model_dump(exclude_none=True)` either drops the field or keeps the empty
string. OpenAI-compatible proxies that forward to Anthropic then fail to
convert it into the required `tool_use.input` dict, causing a 400 error:
`messages.N.content.M.tool_use.input: Input should be a valid dictionary`.

This patch normalizes `arguments` to `"{}"` in `_convert_message` before
serialization, ensuring all proxies receive a parseable JSON object.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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.

2 participants