Skip to content

Wireshark packet capture comparison, I personally determined that it was due to missing fields abount run the sdk failed. #2237

@1714801500

Description

@1714801500

sample function

class Weather(BaseModel):
    city: str = Field(description="The city name")
    temperature_range: str = Field(description="The temperature range in Celsius")
    conditions: str = Field(description="The weather conditions")

openai-agent-sdk

-request-header

POST /v1/chat/completions HTTP/1.1
Host: 192.168.64.146:40021
Accept-Encoding: gzip, deflate, zstd
Connection: keep-alive
Accept: application/json
Content-Type: application/json
User-Agent: Agents/Python 0.5.1
X-Stainless-Lang: python
X-Stainless-Package-Version: 2.8.1
X-Stainless-OS: Windows
X-Stainless-Arch: other:amd64
X-Stainless-Runtime: CPython
X-Stainless-Runtime-Version: 3.12.9
Authorization: Bearer sk-***
X-Stainless-Async: async:asyncio
x-stainless-retry-count: 0
x-stainless-read-timeout: 600
Content-Length: 770

request-payload-json

{
  "messages": [
    {
      "content": "You are a helpful agent.",
      "role": "system"
    },
    {
      "role": "user",
      "content": "What's the weather in Tokyo?"
    },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "id": "call_0fFZk6w1",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\": \"Tokyo\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_0fFZk6w1",
      "content": "city='Tokyo' temperature_range='14-20C' conditions='Sunny with wind.'"
    }
  ],
  "model": "Qwen3_32B",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather information for a specified city.",
        "parameters": {
          "properties": {
            "city": {
              "description": "The city to get the weather for",
              "title": "City",
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "title": "get_weather_args",
          "type": "object",
          "additionalProperties": false
        }
      }
    }
  ]
}

resopnse

HTTP/1.1 422 Unprocessable Content
Keep-Alive: timeout=180, max=2147483647
Content-Length: 106
Content-Type: application/json
Connection: close
RequestUUID: 78b6e18a51d44d1aba698bc773298e83

{"error":"Messages token length must be in (0, 1048576], but got 0","error_type":"Input Validation Error"}

langgraph

request-header

POST /v1/chat/completions HTTP/1.1
Host: 192.168.64.146:40021
Accept-Encoding: gzip, deflate, zstd
Connection: keep-alive
Accept: application/json
Content-Type: application/json
User-Agent: OpenAI/Python 2.8.1
X-Stainless-Lang: python
X-Stainless-Package-Version: 2.8.1
X-Stainless-OS: Windows
X-Stainless-Arch: other:amd64
X-Stainless-Runtime: CPython
X-Stainless-Runtime-Version: 3.12.9
Authorization: Bearer sk-***
X-Stainless-Async: false
x-stainless-retry-count: 0
Content-Length: 1397

####request-playload-json

{
  "messages": [
    {
      "content": "\n..........................................................................................JSON.........\n\n...............\n\n.....................\n\n........................ \"status\" ... \"results\"...\n\n\"results\" ........................................................................\n\nJSON.........\n\n..............................\"\"........................\n\n.....................................................................\n\n...........................{} ... []......\n\n.....................\n\n...........................JSON..........................................\n\n....................................................................................JSON...\n",
      "role": "system"
    },
    {
      "content": "What's the weather in Tokyo?",
      "role": "user"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "call_3eYVXJfs",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\": \"Tokyo\"}"
          }
        }
      ]
    },
    {
      "content": "city='Tokyo' temperature_range='14-20C' conditions='Sunny with wind.'",
      "role": "tool",
      "tool_call_id": "call_3eYVXJfs"
    }
  ],
  "model": "Qwen3_32B",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather information for a specified city.",
        "parameters": {
          "properties": {
            "city": {
              "description": "The city to get the weather for",
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "type": "object"
        }
      }
    }
  ]
}

####response

HTTP/1.1 200 OK
Keep-Alive: timeout=180, max=2147483647
Content-Length: 672
Content-Type: application/json
Connection: close
RequestUUID: 91c4db746cc242fb90856e4a9a8e0fe8

summary for ai

Okay, let's analyze in detail the differences between these two requests and the root cause of the error.
Conclusion first: The core of the problem lies in the fact that in the requests generated by the openai agents Python library, when the assistant role initiates tool_calls, the content field is completely omitted from the message body, while your local API server strictly requires the content field to be included in the assistant message (even if its value is null).

test -code

import asyncio
from typing import Annotated
import os
from pydantic import BaseModel, Field

from agents import Agent, Runner, function_tool, OpenAIChatCompletionsModel
from openai import AsyncOpenAI
BASE_URL = "http://192.168.64.146:40021/v1"
API_KEY = "sk-***"
MODEL_NAME = "Qwen3_32B"
client = AsyncOpenAI(base_url=BASE_URL, api_key=API_KEY)

class Weather(BaseModel):
    city: str = Field(description="The city name")
    temperature_range: str = Field(description="The temperature range in Celsius")
    conditions: str = Field(description="The weather conditions")


@function_tool
def get_weather(city: Annotated[str, "The city to get the weather for"]) -> Weather:
    """Get the current weather information for a specified city."""
    print("[debug] get_weather called")
    return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")


agent = Agent(
    name="Hello world",
    instructions="You are a helpful agent.",
    model=OpenAIChatCompletionsModel(model=MODEL_NAME, openai_client=client),
    tools=[get_weather],
)


async def main():
    result = await Runner.run(agent, input="What's the weather in Tokyo?")
    print(result.final_output)
    # The weather in Tokyo is sunny.


if __name__ == "__main__":
    asyncio.run(main())

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