7
7
8
8
from openai .types .responses import ResponseCompletedEvent
9
9
10
+ from agents .tool import Tool
11
+
10
12
from ._run_impl import (
11
13
NextStepFinalOutput ,
12
14
NextStepHandoff ,
@@ -177,7 +179,8 @@ async def run(
177
179
# agent changes, or if the agent loop ends.
178
180
if current_span is None :
179
181
handoff_names = [h .agent_name for h in cls ._get_handoffs (current_agent )]
180
- tool_names = [t .name for t in current_agent .tools ]
182
+ all_tools = await cls ._get_all_tools (current_agent )
183
+ tool_names = [t .name for t in all_tools ]
181
184
if output_schema := cls ._get_output_schema (current_agent ):
182
185
output_type_name = output_schema .output_type_name ()
183
186
else :
@@ -217,6 +220,7 @@ async def run(
217
220
),
218
221
cls ._run_single_turn (
219
222
agent = current_agent ,
223
+ all_tools = all_tools ,
220
224
original_input = original_input ,
221
225
generated_items = generated_items ,
222
226
hooks = hooks ,
@@ -228,6 +232,7 @@ async def run(
228
232
else :
229
233
turn_result = await cls ._run_single_turn (
230
234
agent = current_agent ,
235
+ all_tools = all_tools ,
231
236
original_input = original_input ,
232
237
generated_items = generated_items ,
233
238
hooks = hooks ,
@@ -627,7 +632,7 @@ async def _run_single_turn_streamed(
627
632
system_prompt = await agent .get_system_prompt (context_wrapper )
628
633
629
634
handoffs = cls ._get_handoffs (agent )
630
-
635
+ all_tools = await cls . _get_all_tools ( agent )
631
636
model = cls ._get_model (agent , run_config )
632
637
model_settings = agent .model_settings .resolve (run_config .model_settings )
633
638
final_response : ModelResponse | None = None
@@ -640,7 +645,7 @@ async def _run_single_turn_streamed(
640
645
system_prompt ,
641
646
input ,
642
647
model_settings ,
643
- agent . tools ,
648
+ all_tools ,
644
649
output_schema ,
645
650
handoffs ,
646
651
get_model_tracing_impl (
@@ -677,6 +682,7 @@ async def _run_single_turn_streamed(
677
682
pre_step_items = streamed_result .new_items ,
678
683
new_response = final_response ,
679
684
output_schema = output_schema ,
685
+ all_tools = all_tools ,
680
686
handoffs = handoffs ,
681
687
hooks = hooks ,
682
688
context_wrapper = context_wrapper ,
@@ -691,6 +697,7 @@ async def _run_single_turn(
691
697
cls ,
692
698
* ,
693
699
agent : Agent [TContext ],
700
+ all_tools : list [Tool ],
694
701
original_input : str | list [TResponseInputItem ],
695
702
generated_items : list [RunItem ],
696
703
hooks : RunHooks [TContext ],
@@ -721,6 +728,7 @@ async def _run_single_turn(
721
728
system_prompt ,
722
729
input ,
723
730
output_schema ,
731
+ all_tools ,
724
732
handoffs ,
725
733
context_wrapper ,
726
734
run_config ,
@@ -732,6 +740,7 @@ async def _run_single_turn(
732
740
pre_step_items = generated_items ,
733
741
new_response = new_response ,
734
742
output_schema = output_schema ,
743
+ all_tools = all_tools ,
735
744
handoffs = handoffs ,
736
745
hooks = hooks ,
737
746
context_wrapper = context_wrapper ,
@@ -743,6 +752,7 @@ async def _get_single_step_result_from_response(
743
752
cls ,
744
753
* ,
745
754
agent : Agent [TContext ],
755
+ all_tools : list [Tool ],
746
756
original_input : str | list [TResponseInputItem ],
747
757
pre_step_items : list [RunItem ],
748
758
new_response : ModelResponse ,
@@ -754,6 +764,7 @@ async def _get_single_step_result_from_response(
754
764
) -> SingleStepResult :
755
765
processed_response = RunImpl .process_model_response (
756
766
agent = agent ,
767
+ all_tools = all_tools ,
757
768
response = new_response ,
758
769
output_schema = output_schema ,
759
770
handoffs = handoffs ,
@@ -853,6 +864,7 @@ async def _get_new_response(
853
864
system_prompt : str | None ,
854
865
input : list [TResponseInputItem ],
855
866
output_schema : AgentOutputSchema | None ,
867
+ all_tools : list [Tool ],
856
868
handoffs : list [Handoff ],
857
869
context_wrapper : RunContextWrapper [TContext ],
858
870
run_config : RunConfig ,
@@ -863,7 +875,7 @@ async def _get_new_response(
863
875
system_instructions = system_prompt ,
864
876
input = input ,
865
877
model_settings = model_settings ,
866
- tools = agent . tools ,
878
+ tools = all_tools ,
867
879
output_schema = output_schema ,
868
880
handoffs = handoffs ,
869
881
tracing = get_model_tracing_impl (
@@ -892,6 +904,10 @@ def _get_handoffs(cls, agent: Agent[Any]) -> list[Handoff]:
892
904
handoffs .append (handoff (handoff_item ))
893
905
return handoffs
894
906
907
+ @classmethod
908
+ async def _get_all_tools (cls , agent : Agent [Any ]) -> list [Tool ]:
909
+ return await agent .get_all_tools ()
910
+
895
911
@classmethod
896
912
def _get_model (cls , agent : Agent [Any ], run_config : RunConfig ) -> Model :
897
913
if isinstance (run_config .model , Model ):
0 commit comments