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

2026年04月15日 11:36 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

  • 具体位置:该函数的参数定义或调用时,目标字段的值未正确初始化为数组(而是None)。
  • 3.解决方案


    以Python OpenAI Function Calling 为例,修复参数 schema 和传值:
    # 修复前(错误):某字段允许None而非array
    # function_schema = {
    #     "name": "self_intent_recognition_0",
    #     "parameters": {
    #         "type": "object",
    #         "properties": {
    #             "intents": {"type": "array"},  # 实际传参时给了None
    #         },
    #         "required": ["intents"]
    #     }
    # }
    
    # 修复后(正确):确保字段为array,默认空数组
    function_schema = {
        "name": "self_intent_recognition_0",
        "parameters": {
            "type": "object",
            "properties": {
                "intents": {
                    "type": "array",
                    "items": {"type": "string"},  # 示例:数组元素类型
                    "default": []  # 默认值设为空数组,避免None
                }
            },
            "required": ["intents"]
        }
    }
    
    # 调用时传参(确保非None)
    params = {"intents": []}  # 或填充实际数组值,如["查询天气", "设置闹钟"]
    

    4. 预防措施


  • 最佳实践1:定义 function schema 时,用default指定数组字段的默认值为空数组[],禁止None

  • 最佳实践2:用[JSON Schema Validator](https://python-jsonschema.readthedocs.io/)预校验参数,提前拦截类型错误。
  • ---
    :若需更精准修复,请提供self_intent_recognition_0的完整 schema 定义。