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

2026年04月15日 11:05 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”的架构无效:None 不是“array”类型。(请求ID: 20250903110948261917640BBDOPt2p)

2. 原因分析


  • 根本原因:函数self_intent_recognition_0的参数架构(Schema)中,某字段预期类型为array,但实际传入了None值。

  • 发生位置:函数参数定义(Schema)或调用传参环节——架构要求数组类型,却未正确赋值(如漏传、传None)。
  • 3.解决方案


    以Python OpenAI Function Calling为例,修复Schema定义与传参:
    from openai import OpenAI
    
    client = OpenAI()
    
    # 修复后的函数Schema(明确数组字段+默认值)
    functions = [
        {
            "name": "self_intent_recognition_0",
            "parameters": {
                "type": "object",
                "properties": {
                    "target_array_field": {  # 假设问题字段为target_array_field
                        "type": "array",
                        "items": {"type": "string"},  # 数组元素类型(按需调整)
                        "default": []  # 用空数组替代None作为默认值
                    }
                },
                "required": ["target_array_field"]
            }
        }
    ]
    
    # 调用时传数组(空数组或有效值,禁止None)
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": "测试"}],
        functions=functions,
        function_call={
            "name": "self_intent_recognition_0",
            "arguments": {"target_array_field": []}  # 传空数组而非None
        }
    )
    

    4. 预防措施


  • 最佳实践1:定义函数Schema时,用JSON Schema验证工具(如[AJV](https://ajv.js.org/))提前校验类型一致性,避免None混入数组字段。

  • 最佳实践2:调用函数前添加参数类型守卫(如Python用isinstance(param, list)检查),强制数组字段传list类型(空数组[]优于None)。
  • ---
    分析完成,如需进一步调试请提供完整Schema定义或调用代码片段。