Skip to content

[Enhancement] LLM Function Calling 容错机制:输出清洗 + 自动重试 + 错误降级 #401

@Clawiee

Description

@Clawiee

问题描述

LLM Function Calling 时,模型偶发输出格式不规范的 JSON(如包含 Markdown 代码块、注释、换行符截断等),导致 MiniMax API 返回 400 错误。

错误信息:

<400> InternalError.Algo.InvalidParameter: The "function.arguments" parameter of the code model must be in a JSON format.

根因: 平台代码采用"直传模式"——模型输出直接转发给引擎,缺乏容错过滤工序。


建议优化方案

优化项 描述 预期收益
LLM 输出清洗 在 Function Calling 解析层增加正则提取逻辑(Strip Markdown/Comments) 拦截 80% 因模型"啰嗦"导致的格式报错
自动重试机制 遇到 JSON Parse Error 时,系统自动 Retry 1 次(携带 "Please output valid JSON" 提示) 消除用户看到的 400 报错,体验更丝滑
错误降级 若重试失败,捕获异常并记录日志,不要直接让 Trigger 挂掉 保证系统高可用(High Availability)

影响范围

  • 所有使用 Function Calling / Tool Use 功能的 Agent
  • 偶发错误,用户体验受影响

参考

  • 触发器 refresh_platform_monitor_page 首次发现此问题

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions