Skip to content

FEAT: Add tool call to OpenAI Response Target - #1006

Merged
Justin Song (jsong468) merged 18 commits into
microsoft:mainfrom
KutalVolkan:feat/openai_response_target_tool_use
Sep 8, 2025
Merged

Justin Song (jsong468) merged 18 commits into
microsoft:mainfrom
KutalVolkan:feat/openai_response_target_tool_use

Conversation

@KutalVolkan

@KutalVolkan Volkan Kutal (KutalVolkan) commented Jul 16, 2025 •

Copy link
Copy Markdown
Contributor

Overview

  • Adds support for OpenAI /v1/responses API with full agentic (function/tool) calling in PyRIT.
  • Supports web search and all OpenAI tools via extra_body_parameters.

Testing / Validation

  • Pytest included yet.

  • Manually tested:

    • Agentic Python function-call scenario (get_current_weather tool)
    • OpenAI built-in web search tool (web_search_preview)

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added one main comment, will take a very detailed look after we resolve that. I did try out tool calling with the OpenAI SDK last night actually so I'm familiar with the pattern 🤣 see #1005.

So your approach is exactly what I'd do except for the comment

@KutalVolkan Volkan Kutal (KutalVolkan) changed the title FEAT: Add tool call to OpenAI Resonse Target FEAT: Add tool call to OpenAI Response Target Jul 16, 2025
@KutalVolkan

Volkan Kutal (KutalVolkan) commented Jul 22, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi Roman Lutz (@romanlutz),

After recent updates to support the OpenAI Response API with function calling in OpenAIResponseTarget, I'm running into a persistent HTTP 400 Bad Request when trying to use custom Python functions like get_current_weather.

Interestingly, the web_search tool works fine, so the base integration is functional.

When I comment out the agentic loop (the custom send_prompt_async override in openai_response_target.py) and fall back to the base OpenAIChatTargetBase.send_prompt_async, I do receive a valid function_call response like:

0 | assistant: {"id":"fc_687f9c0d6484819a8fdb5d55f156bffe07f3310844a7ca28","type":"function_call","status":"completed","arguments":"{\"location\":\"Boston\",\"unit\":\"celsius\"}","call_id":"call_9NsJHV5rK5SpR7GbU5rnwMss","name":"get_current_weather"}

But once I re-enable the agentic loop to handle the function call and return a follow-up message (via _make_tool_message), I hit a 400 Bad Request.

Do you happen to have any quick pointers on how the follow-up message should be structured for the response API? Maybe I’m mislabeling the response piece or missing something in the tool return format. If not, no worries. I’ll dig in further over the weekend.

@romanlutz

Copy link
Copy Markdown
Contributor

I will have to check the responses API. You may be faster than me 🙂

@KutalVolkan

Volkan Kutal (KutalVolkan) commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor Author

Hello Team,

I haven’t had time to work on it yet, but I’ll try to finish it by 31.08.2025, at least the functionality. Pytest will depend on available time. The web search, as described, is working, but function calling has somehow broken. I’ll figure it out. ;)

@KutalVolkan

Copy link
Copy Markdown
Contributor Author

Hello Team,

I refactored OpenAIResponseTarget to use the proper Responses API schema. Tool calls are now top-level, the body uses response_format, and I extended piece types + fixed the agentic loop so outputs pair with their call_id. This removed the 400s and function + web search now work end-to-end.

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good, just the one comment :)

@jsong468
Justin Song (jsong468) merged commit db7b63b into microsoft:main Sep 8, 2025
@KutalVolkan
Volkan Kutal (KutalVolkan) deleted the feat/openai_response_target_tool_use branch June 10, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants