Skip to content

Python: OpenAI SDK rejects allow_multiple_tool_calls when used in ChatAgent (possible argument name mismatch with OpenAI) #2852

@jspv

Description

@jspv

allow_multiple_tool_calls is a documented option for OpenAIChatClient create_agent(). It appears this is passed verbatim to the openai completions create method, that method does not support allow_mutiple_tool_calls as an option.

Note: it does have parallel_tool_calls as an option.

openai 2.11.0 (latest)

  File "/Users/justin/src/s_test/.venv/lib/python3.13/site-packages/agent_framework/openai/_chat_client.py", line 76, in _inner_get_response
    await client.chat.completions.create(stream=False, **options_dict), chat_options
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/src/s_test/.venv/lib/python3.13/site-packages/openai/_utils/_utils.py", line 286, in wrapper
    return func(*args, **kwargs)
TypeError: AsyncCompletions.create() got an unexpected keyword argument 'allow_multiple_tool_calls'

example code:

"""Minimal Microsoft Agent Framework example with allow_multiple_tool_calls=True.

Run to reproduce the OpenAI SDK kwarg error when the installed SDK lacks support
for `allow_multiple_tool_calls`.

Usage:
  OPENAI_API_KEY=... python scripts/demo_allow_multiple_tool_calls.py
"""

from __future__ import annotations

import asyncio
import os

from agent_framework import ChatAgent, ai_function
from agent_framework.openai import OpenAIChatClient


@ai_function(name="echo_tool", description="Echo the provided text.")
def echo_tool(text: str) -> str:
    return text


async def _run() -> None:
    api_key = os.getenv("OPENAI_API_KEY")
    if not api_key:
        raise OSError("Set OPENAI_API_KEY before running this demo.")

    chat_client = OpenAIChatClient(
        model_id=os.getenv("OPENAI_MODEL_ID", "gpt-4o-mini"),
        api_key=api_key,
    )

    agent = ChatAgent(
        chat_client=chat_client,
        instructions="Return a short reply; you may call tools.",
        tools=[echo_tool],
        allow_multiple_tool_calls=True,
    )

    thread = agent.get_new_thread()
    # This call raises if the OpenAI SDK rejects allow_multiple_tool_calls.
    result = await agent.run(messages="Say hi using a tool call.", thread=thread)
    print(result.response_text)


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

Metadata

Metadata

Assignees

Labels

agentsIssues related to single agentsbugSomething isn't workingpython

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions