@@ -99,72 +99,80 @@ def setup_once() -> None:
9999 0 ,
100100 8 ,
101101 ):
102-
103- @wraps (run_loop .get_all_tools )
104- async def new_wrapped_get_all_tools (
105- agent : "agents.Agent" ,
106- context_wrapper : "agents.RunContextWrapper" ,
107- ) -> "list[agents.Tool]" :
108- return await _get_all_tools (
109- run_loop .get_all_tools , agent , context_wrapper
102+ if run_loop is not None :
103+
104+ @wraps (run_loop .get_all_tools )
105+ async def new_wrapped_get_all_tools (
106+ agent : "agents.Agent" ,
107+ context_wrapper : "agents.RunContextWrapper" ,
108+ ) -> "list[agents.Tool]" :
109+ return await _get_all_tools (
110+ run_loop .get_all_tools , agent , context_wrapper
111+ )
112+
113+ agents .run .get_all_tools = new_wrapped_get_all_tools
114+
115+ @wraps (run_loop .run_single_turn )
116+ async def new_wrapped_run_single_turn (
117+ * args : "Any" , ** kwargs : "Any"
118+ ) -> "SingleStepResult" :
119+ return await _run_single_turn (
120+ run_loop .run_single_turn , * args , ** kwargs
121+ )
122+
123+ agents .run .run_single_turn = new_wrapped_run_single_turn
124+
125+ @wraps (run_loop .run_single_turn_streamed )
126+ async def new_wrapped_run_single_turn_streamed (
127+ * args : "Any" , ** kwargs : "Any"
128+ ) -> "SingleStepResult" :
129+ return await _run_single_turn_streamed (
130+ run_loop .run_single_turn_streamed , * args , ** kwargs
131+ )
132+
133+ agents .run .run_single_turn_streamed = (
134+ new_wrapped_run_single_turn_streamed
110135 )
111136
112- agents .run .get_all_tools = new_wrapped_get_all_tools
113-
114- @wraps (turn_preparation .get_model )
115- def new_wrapped_get_model (
116- agent : "agents.Agent" , run_config : "agents.RunConfig"
117- ) -> "agents.Model" :
118- return _get_model (turn_preparation .get_model , agent , run_config )
119-
120- agents .run_internal .run_loop .get_model = new_wrapped_get_model
121-
122- @wraps (run_loop .run_single_turn )
123- async def new_wrapped_run_single_turn (
124- * args : "Any" , ** kwargs : "Any"
125- ) -> "SingleStepResult" :
126- return await _run_single_turn (run_loop .run_single_turn , * args , ** kwargs )
137+ if turn_preparation is not None :
127138
128- agents .run .run_single_turn = new_wrapped_run_single_turn
139+ @wraps (turn_preparation .get_model )
140+ def new_wrapped_get_model (
141+ agent : "agents.Agent" , run_config : "agents.RunConfig"
142+ ) -> "agents.Model" :
143+ return _get_model (turn_preparation .get_model , agent , run_config )
129144
130- @wraps (run_loop .run_single_turn_streamed )
131- async def new_wrapped_run_single_turn_streamed (
132- * args : "Any" , ** kwargs : "Any"
133- ) -> "SingleStepResult" :
134- return await _run_single_turn_streamed (
135- run_loop .run_single_turn_streamed , * args , ** kwargs
136- )
145+ agents .run_internal .run_loop .get_model = new_wrapped_get_model
137146
138- agents . run . run_single_turn_streamed = new_wrapped_run_single_turn_streamed
147+ original_execute_handoffs = turn_resolution . execute_handoffs
139148
140- original_execute_handoffs = turn_resolution .execute_handoffs
149+ @wraps (original_execute_handoffs )
150+ async def new_wrapped_execute_handoffs (
151+ * args : "Any" , ** kwargs : "Any"
152+ ) -> "SingleStepResult" :
153+ return await _execute_handoffs (
154+ original_execute_handoffs , * args , ** kwargs
155+ )
141156
142- @wraps (original_execute_handoffs )
143- async def new_wrapped_execute_handoffs (
144- * args : "Any" , ** kwargs : "Any"
145- ) -> "SingleStepResult" :
146- return await _execute_handoffs (
147- original_execute_handoffs , * args , ** kwargs
157+ agents .run_internal .turn_resolution .execute_handoffs = (
158+ new_wrapped_execute_handoffs
148159 )
149160
150- agents .run_internal .turn_resolution .execute_handoffs = (
151- new_wrapped_execute_handoffs
152- )
161+ if turn_resolution is not None :
162+ original_execute_final_output = turn_resolution .execute_final_output
153163
154- original_execute_final_output = turn_resolution .execute_final_output
164+ @wraps (turn_resolution .execute_final_output )
165+ async def new_wrapped_final_output (
166+ * args : "Any" , ** kwargs : "Any"
167+ ) -> "SingleStepResult" :
168+ return await _execute_final_output (
169+ original_execute_final_output , * args , ** kwargs
170+ )
155171
156- @wraps (turn_resolution .execute_final_output )
157- async def new_wrapped_final_output (
158- * args : "Any" , ** kwargs : "Any"
159- ) -> "SingleStepResult" :
160- return await _execute_final_output (
161- original_execute_final_output , * args , ** kwargs
172+ agents .run_internal .turn_resolution .execute_final_output = (
173+ new_wrapped_final_output
162174 )
163175
164- agents .run_internal .turn_resolution .execute_final_output = (
165- new_wrapped_final_output
166- )
167-
168176 return
169177
170178 original_get_all_tools = AgentRunner ._get_all_tools
0 commit comments