Skip to content

Conversation

seratch
Copy link
Member

@seratch seratch commented Jul 22, 2025

This pull request resolves #980

simple code snippet to do tests:

import asyncio from openai.types.responses import ResponseTextDeltaEvent from agents import Agent, ModelSettings, Runner, function_tool, set_default_openai_api set_default_openai_api("chat_completions") @function_tool def say_hello(): print("Hello, world!") return "Hello, world!" async def main(): agent = Agent( name="Joker", instructions="You are a helpful assistant.", model_settings=ModelSettings(tool_choice="say_hello"), tools=[say_hello], ) result = Runner.run_streamed(agent, input="Please tell me 5 jokes.") async for event in result.stream_events(): if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent): print(event.data.delta, end="", flush=True) if __name__ == "__main__": asyncio.run(main())
responses_tool_choice = OpenAIResponsesConverter.convert_tool_choice(
model_settings.tool_choice
)
if responses_tool_choice is None or responses_tool_choice == NOT_GIVEN:
Copy link
Member Author

@seratch seratch Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The essential changes here are 1) use Converter.convert_tool_choice 2) cover responses_tool_choice is None pattern. Added more detailed comments about why it's necessary but happy to adjust the style if necessary

@qqaatw
Copy link

qqaatw commented Jul 29, 2025

Hello, following up on this PR. Do we have an ETA to get it merged?

@seratch
Copy link
Member Author

seratch commented Jul 29, 2025

@rm-openai Can you review this before next release? I think this should be safe enough to merge.

@rm-openai rm-openai merged commit 818344c into main Aug 1, 2025
5 checks passed
@rm-openai rm-openai deleted the issue-980-chat-completions-tool-choice branch August 1, 2025 15:51
vcshih pushed a commit to veris-ai/openai-agents-python that referenced this pull request Aug 15, 2025
…oice parameter w/ streaming enabled (openai#1206) This pull request resolves openai#980 simple code snippet to do tests: ```python import asyncio from openai.types.responses import ResponseTextDeltaEvent from agents import Agent, ModelSettings, Runner, function_tool, set_default_openai_api set_default_openai_api("chat_completions") @function_tool def say_hello(): print("Hello, world!") return "Hello, world!" async def main(): agent = Agent( name="Joker", instructions="You are a helpful assistant.", model_settings=ModelSettings(tool_choice="say_hello"), tools=[say_hello], ) result = Runner.run_streamed(agent, input="Please tell me 5 jokes.") async for event in result.stream_events(): if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent): print(event.data.delta, end="", flush=True) if __name__ == "__main__": asyncio.run(main()) ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants