/MainProcess] 22208184909825/agent-e80a0 agent invoke chat to retry again llm er...

2026年04月15日 09:08 processing

错误信息

[2025-09-03 11:10:25,969: ERROR/MainProcess] 22208184909825/agent-e80a0 agent invoke chat to retry again llm error: Error code: 400 - {'error': {'message': "Invalid schema for function 'self_intent_recognition_0': None is not of type 'array'. (request id: 20250903110948261917640BBDOPt2p)", 'type': 'openai_error', 'param': '', 'code': 'invalid_function_parameters'}}

AI 解决方案

报错分析报告

1.错误翻译


原文:Invalid schema for function 'self_intent_recognition_0': None is not of type 'array'. (request id: 20250903110948261917640BBDOPt2p)
译文:函数'self_intent_recognition_0'的schema无效:None不是array类型。(请求ID: 20250903110948261917640BBDOPt2p)

2. 原因分析


  • 根本原因:函数self_intent_recognition_0的参数schema定义中,某字段预期为array类型,但实际传入了None值。

  • 发生位置:函数schema定义或调用LLM时的参数传递环节,上下文是Agent调用LLM的function重试失败。
  • 3.解决方案


    需确保函数参数为非空array类型(或设置默认空数组)。以下是修复示例:

    #### 方案1:修正Function Schema(JSON Schema)

    {
      "name": "self_intent_recognition_0",
      "description": "自意图识别函数",
      "parameters": {
        "type": "object",
        "properties": {
          "intents": {
            "type": "array",          // 明确类型为array
            "items": { "type": "string" },
            "default": []             // 避免None,设默认空数组
          }
        },
        "required": ["intents"]         // 标记为必填(按需调整)
      }
    }
    

    #### 方案2:修正调用参数(Python示例)

    # 调用LLM Function时传递合法array参数(而非None)
    import openai
    
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0613",
        messages=[{"role": "user", "content": "测试"}],
        functions=[{
            "name": "self_intent_recognition_0",
            "parameters": {
                "type": "object",
                "properties": {
                    "intents": {"type": "array", "items": {"type": "string"}}
                }
            }
        }],
        function_call={"name": "self_intent_recognition_0"},
        function_arguments={"intents": []}  # 传空数组或实际值(如["查询订单"])
    )
    

    4. 预防措施


  • Schema校验:用JSON Schema验证工具(如[AJV](https://ajv.js.org/))预检查function参数类型,避免None混入array字段。

  • 参数守卫:调用前用类型检查库(如Python的[Pydantic](https://docs.pydantic.dev/))强制转换参数,确保array字段非空。