-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: stop streamed tool execution after known input guardrail tripwire #2688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1117,6 +1117,24 @@ async def run_single_turn_streamed( | |
| reasoning_item_id_policy: ReasoningItemIdPolicy | None = None, | ||
| ) -> SingleStepResult: | ||
| """Run a single streamed turn and emit events as results arrive.""" | ||
|
|
||
| async def raise_if_input_guardrail_tripwire_known() -> None: | ||
| tripwire_result = streamed_result._triggered_input_guardrail_result | ||
| if tripwire_result is not None: | ||
| raise InputGuardrailTripwireTriggered(tripwire_result) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
|
|
||
| task = streamed_result._input_guardrails_task | ||
| if task is None or not task.done(): | ||
| return | ||
|
|
||
| guardrail_exception = task.exception() | ||
| if guardrail_exception is not None: | ||
| raise guardrail_exception | ||
|
|
||
| tripwire_result = streamed_result._triggered_input_guardrail_result | ||
| if tripwire_result is not None: | ||
| raise InputGuardrailTripwireTriggered(tripwire_result) | ||
|
|
||
| emitted_tool_call_ids: set[str] = set() | ||
| emitted_reasoning_item_ids: set[str] = set() | ||
| emitted_tool_search_fingerprints: set[str] = set() | ||
|
|
@@ -1450,6 +1468,7 @@ async def rewind_model_request() -> None: | |
| run_config=run_config, | ||
| tool_use_tracker=tool_use_tracker, | ||
| event_queue=streamed_result._event_queue, | ||
| before_side_effects=raise_if_input_guardrail_tripwire_known, | ||
| ) | ||
|
|
||
| items_to_filter = session_items_for_turn(single_step_result) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.