8000 Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. · Issue #873 · openai/openai-agents-python · GitHub
[go: up one dir, main page]

Skip to content
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. #873
Open
@AllenKaixuan

Description

@AllenKaixuan

Describe the bug

Hello, I run a simple test for function tools calling with gpt-4o. However, I met a bug "Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. " . It seems like the orders of message is wrong. And I have found last year OpenAI updates have introduced a specific requirement that a tool call response must directly follow the message where it was initiated.

Debug information

  • Agents SDK version: 0.0.17
  • Python 3.10

Repro steps

  external_client = AsyncOpenAI(
      api_key="xxxx",
      base_url="xxxx",
  )
  
  set_default_openai_client(external_client)
  
  model = OpenAIChatCompletionsModel(
      model="gpt-4o",
      openai_client=external_client
  )
  
  @function_tool
  def get_weather(city: str) -> str:
      return f"The weather in {city} is sunny"
  
  
  agent = Agent(
      name="Haiku agent",
      instructions="Always respond in haiku form",
      model=model,
       tools=[get_weather],
  )

async def main():
    user_input = "What is the weather in Paris?"
    

    result = await Runner.run(
        agent, 
        input=user_input, 
    )
    print(result.final_output())

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

Expected behavior

I was wondering whether openai agents framework supported this update or not? And I also tried other LLM, doesn't met this bug.
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0