Skip to content

[Feature] AstrBot 在调用 Moonshot (Kimi K2.5) API 时的空消息报错解决建议 #7200

@kaixinyujue

Description

@kaixinyujue

Description / 描述

AstrBot 在调用 Moonshot (Kimi K2.5) API 时发生报错,请求体中的对话历史包含了一条内容为空的助手消息,导致Kimi K2.5返回Error code: 400。

[2026-03-30 21:26:16.292] [Core] [WARN] [v4.22.2] [runners.tool_loop_agent_runner:350]: Chat Model moonshot/kimi-k2.5 request error: Error code: 400 - {'error': {'message': "Invalid request: the message at position 8 with role 'assistant' must not be empty", 'type': 'invalid_request_error'}}
[2026-03-30 21:32:10.426] [Core] [WARN] [v4.22.2] [runners.tool_loop_agent_runner:350]: Chat Model moonshot/kimi-k2.5 request error: Error code: 400 - {'error': {'message': "Invalid request: the message at position 8 with role 'assistant' must not be empty", 'type': 'invalid_request_error'}}

解决建议:
在 Provider 层(openai_source.py)添加消息清洗逻辑,在 HTTP 出口处过滤掉"assistant"的空消息

Use Case / 使用场景

这样修改后所有 OpenAI 兼容的模型(Moonshot、DeepSeek、GPT 等)都能受益,特别是严格限制role: assistant消息非空的模型。

Willing to Submit PR? / 是否愿意提交PR?

  • Yes, I am willing to submit a PR. / 是的,我愿意提交 PR。

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions