|
83 | 83 | validate_output_guardrails_with_server_managed_conversation, |
84 | 84 | validate_session_conversation_settings, |
85 | 85 | ) |
| 86 | +from .run_internal.agent_tool_configuration import agent_tool_configuration_run |
86 | 87 | from .run_internal.approvals import approvals_from_step |
87 | 88 | from .run_internal.blocked_output import ( |
88 | 89 | OUTPUT_GUARDRAIL_BLOCKED_TOOL_OUTPUT, |
|
120 | 121 | _safe_redacted_persistence_error, |
121 | 122 | cleanup_models_after_run, |
122 | 123 | finalize_max_turns_handler_output, |
123 | | - get_all_tools, |
124 | 124 | get_output_schema, |
125 | | - initialize_computer_tools, |
126 | 125 | resolve_interrupted_turn, |
127 | 126 | run_input_guardrails, |
128 | 127 | run_output_guardrails, |
@@ -563,7 +562,13 @@ async def run( |
563 | 562 | redacted_error: BaseException | None = None |
564 | 563 | try: |
565 | 564 | try: |
566 | | - return await self._run_impl(starting_agent, input, **kwargs) |
| 565 | + configuration_agent = ( |
| 566 | + input._current_agent |
| 567 | + if isinstance(input, RunState) and input._current_agent is not None |
| 568 | + else starting_agent |
| 569 | + ) |
| 570 | + with agent_tool_configuration_run(configuration_agent): |
| 571 | + return await self._run_impl(starting_agent, input, **kwargs) |
567 | 572 | except BaseException as error: |
568 | 573 | if not _is_error_data_redacted(error): |
569 | 574 | raise |
@@ -1482,11 +1487,6 @@ def _mark_response_hooks_started() -> None: |
1482 | 1487 | if not run_state._pending_input: |
1483 | 1488 | run_state._generated_items = list(generated_items) |
1484 | 1489 | run_state._session_items = list(session_items) |
1485 | | - all_tools = await get_all_tools(execution_agent, context_wrapper) |
1486 | | - all_tools = await initialize_computer_tools( |
1487 | | - tools=all_tools, context_wrapper=context_wrapper |
1488 | | - ) |
1489 | | - |
1490 | 1490 | if current_span is None: |
1491 | 1491 | if (output_schema := get_output_schema(execution_agent)) is not None: |
1492 | 1492 | output_type_name = output_schema.name() |
@@ -1699,7 +1699,6 @@ async def _save_max_turns_handler_output( |
1699 | 1699 | model_task = asyncio.create_task( |
1700 | 1700 | run_single_turn( |
1701 | 1701 | bindings=current_bindings, |
1702 | | - all_tools=all_tools, |
1703 | 1702 | original_input=original_input, |
1704 | 1703 | generated_items=items_for_model, |
1705 | 1704 | hooks=hooks, |
@@ -1774,7 +1773,6 @@ async def _save_max_turns_handler_output( |
1774 | 1773 | else: |
1775 | 1774 | turn_result = await run_single_turn( |
1776 | 1775 | bindings=current_bindings, |
1777 | | - all_tools=all_tools, |
1778 | 1776 | original_input=original_input, |
1779 | 1777 | generated_items=items_for_model, |
1780 | 1778 | hooks=hooks, |
@@ -2601,24 +2599,30 @@ def run_streamed( |
2601 | 2599 |
|
2602 | 2600 | # Kick off the actual agent loop in the background and return the streamed result object. |
2603 | 2601 | async def run_loop() -> None: |
2604 | | - await start_streaming( |
2605 | | - starting_input=input_for_result, |
2606 | | - streamed_result=streamed_result, |
2607 | | - starting_agent=starting_agent, |
2608 | | - max_turns=max_turns, |
2609 | | - hooks=hooks, |
2610 | | - context_wrapper=context_wrapper, |
2611 | | - run_config=run_config, |
2612 | | - error_handlers=error_handlers, |
2613 | | - previous_response_id=previous_response_id, |
2614 | | - auto_previous_response_id=auto_previous_response_id, |
2615 | | - conversation_id=conversation_id, |
2616 | | - session=session, |
2617 | | - run_state=run_state, |
2618 | | - trace_workflow_name=trace_workflow_name, |
2619 | | - is_resumed_state=is_resumed_state, |
2620 | | - sandbox_runtime=sandbox_runtime, |
| 2602 | + configuration_agent = ( |
| 2603 | + run_state._current_agent |
| 2604 | + if run_state is not None and run_state._current_agent is not None |
| 2605 | + else starting_agent |
2621 | 2606 | ) |
| 2607 | + with agent_tool_configuration_run(configuration_agent): |
| 2608 | + await start_streaming( |
| 2609 | + starting_input=input_for_result, |
| 2610 | + streamed_result=streamed_result, |
| 2611 | + starting_agent=starting_agent, |
| 2612 | + max_turns=max_turns, |
| 2613 | + hooks=hooks, |
| 2614 | + context_wrapper=context_wrapper, |
| 2615 | + run_config=run_config, |
| 2616 | + error_handlers=error_handlers, |
| 2617 | + previous_response_id=previous_response_id, |
| 2618 | + auto_previous_response_id=auto_previous_response_id, |
| 2619 | + conversation_id=conversation_id, |
| 2620 | + session=session, |
| 2621 | + run_state=run_state, |
| 2622 | + trace_workflow_name=trace_workflow_name, |
| 2623 | + is_resumed_state=is_resumed_state, |
| 2624 | + sandbox_runtime=sandbox_runtime, |
| 2625 | + ) |
2622 | 2626 |
|
2623 | 2627 | # Keep the outer task frame inside the boundary so it cannot retain run payloads. |
2624 | 2628 | streamed_result.run_loop_task = asyncio.create_task( |
|
0 commit comments