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

2026年06月22日 21:47 32.84 秒 success

错误信息

[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'.
译文:函数 'self_intent_recognition_0' 的 schema 无效:None 不是“array”(数组)类型。

2. 🎯 原因分析


此错误发生在调用大语言模型(LLM)的API时,具体原因是传递给模型的 函数(function/tool)定义格式不符合OpenAI API的规范
  • 根本原因:在定义名为 self_intent_recognition_0 的函数时,其参数(parameters)的JSON Schema结构有误。根据错误信息,Schema中期望某个字段的类型是 array(数组),但实际接收到的值是 None(空值)。

  • 具体位置:错误很可能出现在定义该函数的 parameters 部分,特别是 properties 中某个参数的 type 字段被错误地设置为了 nullNone,而不是一个有效的字符串,如 "array"
  • 3. 💡 解决方案


    请检查代码中定义该函数的部分,确保 parameters 的JSON Schema完全符合OpenAI的格式要求。以下是修复示例:

    // 错误示例(可能导致问题的定义)
    {
      "name": "self_intent_recognition_0",
      "parameters": {
        "type": "object",
        "properties": {
          "user_query": {
            "type": "string",
            "description": "用户的查询"
          },
          "intent_list": {
            "type": null,  // ❌ 这里是错误根源,应为字符串 "array"
            "description": "意图列表"
          }
        }
      }
    }
    
    // 正确示例(修复后)
    {
      "name": "self_intent_recognition_0",
      "parameters": {
        "type": "object",
        "properties": {
          "user_query": {
            "type": "string",
            "description": "用户的查询"
          },
          "intent_list": {
            "type": "array",  // ✅ 使用正确的类型字符串
            "items": {        // ✅ 数组必须定义其元素的类型
              "type": "string"
            },
            "description": "意图列表"
          }
        },
        "required": ["user_query"] // 根据业务逻辑设置必填字段
      }
    }
    

    操作步骤

  • 在你的代码中找到定义 toolsfunctions 的部分。

  • 定位到名为 self_intent_recognition_0 的函数定义。

  • 仔细检查其 parameters 对象中的所有 type 字段,确保它们都是正确的字符串(如 "string", "number", "boolean", "object", "array"),而不是 nullNone 或其他无效值。

  • 特别注意,当类型为 "array" 时,必须包含一个 items 属性来定义数组元素的类型。
  • 4. 🛡️ 预防措施


  • Schema验证先行:在将函数定义发送给LLM API之前,使用本地JSON Schema验证工具(如Python的 jsonschema 库)先进行格式校验,可以及早发现结构错误。

  • 参考官方文档:严格对照你所使用的LLM服务提供商(如OpenAI)的官方API文档,来编写和校对函数定义的Schema结构,确保完全兼容。