Repository navigation
FEAT: Bound OpenAIResponseTarget's tool loop, and end the turn when a tool's infrastructure fails (part 1) - #4101
Merged
Richard Lundeen (richlundeen) merged 4 commits intoNov 9, 2026
Conversation
… tool's infrastructure fails - max_tool_rounds (default 10) bounds the previously unbounded tool loop. When it is reached, pending calls are answered as not run and the turn ends with an error response carrying a ToolLoopStop reason. - A tool raises ToolInfrastructureError(invoked=...) when its infrastructure fails; the turn ends once every call in the round has a result, and the model is told only that the tool's infrastructure failed. - ToolLoopStop and ToolLoopStopReason are exported from pyrit.models. - Malformed-argument results include the validation message. Part 1 of 5 of sandboxed code execution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
Draft
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the tool-execution limits and infrastructure-failure handling changes.
No open issues 🎉
What changed in this PR
This PR bounds OpenAIResponseTarget’s local tool execution and ends turns when tool infrastructure fails. It provides the first layer of the planned sandboxed code-execution stack while remaining useful independently.
Changes:
- Limits local tool execution to 10 rounds by default, with a configurable
max_tool_rounds. - Adds infrastructure-failure handling and structured stop metadata, answering pending calls to preserve valid history.
- Includes argument-validation details in tool results and adds regression tests and framework documentation.
| File | Description |
|---|---|
tests/unit/prompt_target/target/test_tool.py |
Checks validation messages in malformed-argument results. |
tests/unit/prompt_target/target/test_openai_response_target_function_chaining.py |
Adds coverage for round limits, failures, identifiers, and replayable history. |
pyrit/prompt_target/openai/openai_response_target.py |
Bounds tool execution and handles infrastructure failures. |
pyrit/prompt_target/common/tool_provider.py |
Defines ToolInfrastructureError with invocation status. |
pyrit/prompt_target/__init__.py |
Exports the new infrastructure exception. |
pyrit/models/target/tool_execution_metadata.py |
Defines tool-loop stop reasons and metadata. |
pyrit/models/__init__.py |
Exports the new stop-metadata types. |
doc/code/framework.md |
Documents bounded tool loops and infrastructure-failure handling. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
left a comment
Contributor
Author
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; it does not authorize merge.
Richard Lundeen (richlundeen)
added a commit
to richlundeen/PyRIT
that referenced
this pull request
Nov 9, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Behnam (behnam-o)
approved these changes
Nov 9, 2026
Richard Lundeen (richlundeen)
deleted the
richlundeen-sandbox-stack-1-tool-loop
branch
November 9, 2026 19:46
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
Part 1 of 5 of sandboxed code execution, which lets PyRIT test models that act by running code: their tool calls run in a sandbox, and a check program in the same sandbox scores what they did. This part needs no sandbox and is useful on its own. It makes
OpenAIResponseTarget's tool loop safe to leave running, and lets a tool end the turn when its own infrastructure fails.The stack, merged in order:
OpenAIResponseTarget(this PR)Sandboxinterface, with Docker as the example adapterSandboxRegistrySandboxToolProviderSandboxCheckScorerOpenAIResponseTargetruns a model's tool calls in a loop until the model stops calling tools. That loop had no bound, and a tool whose infrastructure failed could only return an error to the model, asking it to fix a problem that isn't its own.max_tool_rounds(default 10, matching the LiteLLM tool loop in FEAT: Add native Claude target and bounded tool execution #4021) bounds how many responses with tool calls one send runs. At the bound, the pending calls are answered as not run ({"error": "max_tool_rounds_exhausted"}), so the conversation's history stays valid, and the turn ends with an error response.ToolInfrastructureError(message, invoked=...): a tool raises it when its infrastructure fails. The target answers every call in the round, ends the turn with an error response instead of asking the model to fix infrastructure, and records whether anything may have run (invoked). The model is told only that the tool's infrastructure failed; the error response, which is never replayed to the model, keeps the details.ToolLoopStopandToolLoopStopReason(pyrit.models): the error response's metadata says why the loop stopped (max_tool_rounds_exhaustedortool_infrastructure_error).max_tool_roundsonly when the target runs local tools, so other targets' identifiers don't change.doc/code/framework.md.Behavior change:
OpenAIResponseTargettargets that run tools now stop after 10 tool rounds per send by default. Pass a largermax_tool_roundsfor longer agentic loops.Related: #4021 (native Claude target with a bounded tool loop, which can adopt
ToolInfrastructureErrorandToolLoopStop).🤖 Generated with Claude Code