Skip to content

Streaming tool_call arguments lost when OpenAI-compatible proxy omits index field (e.g. Gemini) #6661

Description

@jameswangchen

What happened / 发生了什么

When using Gemini models through OpenAI-compatible proxy services (e.g. continue proxy), streaming tool_call chunks
are missing the index field required by the openai SDK's ChatCompletionStreamState. This causes tool_call
arguments to be silently dropped, resulting in None arguments and AttributeError crash in
tool_loop_agent_runner.py.

Error log:
[WARN] Saving chunk state error: Expected list delta entry to have an index key; {'id': '', 'function': {'arguments':
'{"content":"...","tags":"..."}'}, 'type': ''}
[INFO] 使用工具:memory_save,参数:None
AttributeError: 'NoneType' object has no attribute 'items'

Root cause: Standard OpenAI streaming chunks include {"index": 0, ...} in tool_call deltas. Gemini proxies omit this
field, causing ChatCompletionStreamState.handle_chunk() to reject the chunk and lose the arguments.

Impact: All tool_call arguments become None when streaming is enabled with Gemini proxy, affecting any registered tool
(plugins, MCP tools, etc).

Reproduce / 如何复现?

  1. Configure a Gemini model via an OpenAI-compatible proxy
  2. Enable streaming (webchat forces enable_streaming=True by default)
  3. Send a message that triggers any tool call
  4. Observe: tool arguments are None, tool execution crashes

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

v4.20.1

OS

Linux

Logs / 报错日志

[WARN] Saving chunk state error: Expected list delta entry to have an index key; {'id': '', 'function': {'arguments':
'{"content":"...","tags":"..."}'}, 'type': ''}
[INFO] 使用工具:memory_save,参数:None
AttributeError: 'NoneType' object has no attribute 'items'

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions