Repository navigation
FEAT: Run local tools with OpenAIChatTarget - #4595
Merged
Adrian Gavrila (adrian-gavrila) merged 4 commits intoNov 24, 2026
Merged
Adrian Gavrila (adrian-gavrila) merged 4 commits into
Adrian Gavrila (adrian-gavrila) merged 4 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Nested extra_body overrides bypass validation, allowing extra billed completions to be silently discarded and local tool definitions to be replaced without name-conflict checks.
2 open issues
What changed in this PR
Adds local tool execution to OpenAIChatTarget, extending the bounded tool loop introduced for Responses and LiteLLM targets to Chat Completions deployments.
Changes:
- Shares tool discovery, validation, and bounded execution between OpenAI Chat and LiteLLM, with OpenAI retries and rate limiting applied per completion.
- Preserves executable tools during OpenAI target reconstruction and suppresses tools during capability probes.
- Adds regression coverage and documents local tool configuration.
| File | Description |
|---|---|
tests/unit/prompt_target/target/test_tool.py |
Tests copying OpenAI targets with tools and providers. |
tests/unit/prompt_target/target/test_runtime_temperature.py |
Updates retry mocks for the per-completion request method. |
tests/unit/prompt_target/target/test_openai_chat_target.py |
Covers tool execution, history replay, retries, and probe suppression. |
pyrit/prompt_target/openai/openai_target.py |
Keeps real tool objects in reconstruction parameters. |
pyrit/prompt_target/openai/openai_chat_target.py |
Adds tool configuration and bounded local execution. |
pyrit/prompt_target/litellm_chat_target.py |
Delegates tool-loop handling to shared helpers. |
pyrit/prompt_target/common/discover_target_capabilities.py |
Suppresses OpenAI Chat tools during capability probes. |
pyrit/prompt_target/common/chat_completions_tool_loop.py |
Extracts shared Chat Completions tool-loop helpers. |
doc/code/targets/claude_chat_target.md |
Documents OpenAI Chat as another shared-loop target. |
doc/code/targets/1_openai_chat_target.py |
Adds local tool guidance and an example. |
doc/code/targets/1_openai_chat_target.ipynb |
Mirrors the local tool documentation in the notebook. |
Review effort: Balanced
Behnam (behnam-o)
approved these changes
Nov 24, 2026
Behnam (behnam-o)
left a comment
Collaborator
There was a problem hiding this comment.
Thank you! Looks good. A few non-blocking notes below.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adrian Gavrila (adrian-gavrila)
removed this pull request from the merge queue due to a manual request
Nov 24, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adrian Gavrila (adrian-gavrila)
deleted the
adrian-gavrila-openai-chat-tool-loop
branch
November 24, 2026 19:28
Behnam (behnam-o)
pushed a commit
to behnam-o/PyRIT
that referenced
this pull request
Nov 24, 2026
- Merge main, including microsoft#4595 (OpenAIChatTarget runs local tools); tool reporting moves into the shared Chat Completions tool-loop mixin. - Replace the stand-in class list with a declared RUNS_TOOLS_LOCALLY flag on targets, so a tool-running OpenAIChatTarget can stand in. - Keep max_attempts out of the seed's identity: it is now only a runtime argument of generate_simulated_conversation_async (default 5). - Record a preparation failure when every stand-in reply is empty. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
OpenAIChatTargetcan now run tools on the host through the same bounded tool loop thatOpenAIResponseTargetandLiteLLMChatTargetuse (#4021). Chat Completions deployments can then be used wherever a target that runs local tools is needed, without registering them again as a LiteLLM target.OpenAIChatTargettakestools,tool_providers,execute_toolsandmax_tool_rounds, with the same meaning and checks as onLiteLLMChatTarget. Running tools automatically requiresn=1.OpenAIResponseTarget, so retrying a request in a later round never runs earlier tools again. A send without tools makes the same single request as before, and the target's identifier doesn't change.pyrit/prompt_target/common/chat_completions_tool_loop.py, which both targets now use. That code builds tool definitions, reads calls from responses, checks for conflicts withextra_body_parameters, and opens provider scopes around the loop.LiteLLMChatTargetandClaudeChatTargetbehave as before.OpenAITarget.get_reconstruction_parametersput the identifier's tool descriptions in place of the realTooland provider objects, so copying anOpenAIResponseTargetthat had tools failed. Copies now keep their tools, and a copy of a target without tools can add them.This also edits
litellm_chat_target.py, as #4584 does. The two changes don't overlap and merge without conflicts.