78
78
LocalShellTool ,
79
79
MCPToolApprovalRequest ,
80
80
Tool ,
81
+ ToolRunFunction ,
82
+ ToolRunComputerAction ,
81
83
)
82
84
from .tool_context import ToolContext
83
85
from .tracing import (
@@ -126,19 +128,6 @@ class ToolRunHandoff:
126
128
handoff : Handoff
127
129
tool_call : ResponseFunctionToolCall
128
130
129
-
130
- @dataclass
131
- class ToolRunFunction :
132
- tool_call : ResponseFunctionToolCall
133
- function_tool : FunctionTool
134
-
135
-
136
- @dataclass
137
- class ToolRunComputerAction :
138
- tool_call : ResponseComputerToolCall
139
- computer_tool : ComputerTool
140
-
141
-
142
131
@dataclass
143
132
class ToolRunMCPApprovalRequest :
144
133
request_item : McpApprovalRequest
@@ -544,9 +533,9 @@ async def execute_function_tool_calls(
544
533
context_wrapper : RunContextWrapper [TContext ],
545
534
config : RunConfig ,
546
535
) -> list [FunctionToolResult ]:
547
- async def run_single_tool (
548
- func_tool : FunctionTool , tool_call : ResponseFunctionToolCall
549
- ) -> Any :
536
+ async def run_single_tool (action : ToolRunFunction ) -> Any :
537
+ func_tool = action . function_tool
538
+ tool_call = action . tool_call
550
539
with function_span (func_tool .name ) as span_fn :
551
540
tool_context = ToolContext .from_agent_context (
552
541
context_wrapper ,
@@ -557,9 +546,9 @@ async def run_single_tool(
557
546
span_fn .span_data .input = tool_call .arguments
558
547
try :
559
548
_ , _ , result = await asyncio .gather (
560
- hooks .on_tool_start (tool_context , agent , func_tool ),
549
+ hooks .on_tool_start (context_wrapper , agent , action ),
561
550
(
562
- agent .hooks .on_tool_start (tool_context , agent , func_tool )
551
+ agent .hooks .on_tool_start (context_wrapper , agent , action )
563
552
if agent .hooks
564
553
else _coro .noop_coroutine ()
565
554
),
@@ -591,8 +580,7 @@ async def run_single_tool(
591
580
592
581
tasks = []
593
582
for tool_run in tool_runs :
594
- function_tool = tool_run .function_tool
595
- tasks .append (run_single_tool (function_tool , tool_run .tool_call ))
583
+ tasks .append (run_single_tool (tool_run ))
596
584
597
585
results = await asyncio .gather (* tasks )
598
586
@@ -1039,9 +1027,9 @@ async def execute(
1039
1027
)
1040
1028
1041
1029
_ , _ , output = await asyncio .gather (
1042
- hooks .on_tool_start (context_wrapper , agent , action . computer_tool ),
1030
+ hooks .on_tool_start (context_wrapper , agent , action ),
1043
1031
(
1044
- agent .hooks .on_tool_start (context_wrapper , agent , action . computer_tool )
1032
+ agent .hooks .on_tool_start (context_wrapper , agent , action )
1045
1033
if agent .hooks
1046
1034
else _coro .noop_coroutine ()
1047
1035
),
0 commit comments