|
52 | 52 | from .models.interface import ModelTracing
|
53 | 53 | from .run_context import RunContextWrapper, TContext
|
54 | 54 | from .stream_events import RunItemStreamEvent, StreamEvent
|
55 |
| -from .tool import ComputerTool, FunctionTool, FunctionToolResult, Tool |
| 55 | +from .tool import ComputerTool, FunctionTool, FunctionToolResult, Tool, ToolRunFunction, ToolRunComputerAction |
56 | 56 | from .tracing import (
|
57 | 57 | SpanError,
|
58 | 58 | Trace,
|
@@ -99,19 +99,6 @@ class ToolRunHandoff:
|
99 | 99 | handoff: Handoff
|
100 | 100 | tool_call: ResponseFunctionToolCall
|
101 | 101 |
|
102 |
| - |
103 |
| -@dataclass |
104 |
| -class ToolRunFunction: |
105 |
| - tool_call: ResponseFunctionToolCall |
106 |
| - function_tool: FunctionTool |
107 |
| - |
108 |
| - |
109 |
| -@dataclass |
110 |
| -class ToolRunComputerAction: |
111 |
| - tool_call: ResponseComputerToolCall |
112 |
| - computer_tool: ComputerTool |
113 |
| - |
114 |
| - |
115 | 102 | @dataclass
|
116 | 103 | class ProcessedResponse:
|
117 | 104 | new_items: list[RunItem]
|
@@ -429,17 +416,17 @@ async def execute_function_tool_calls(
|
429 | 416 | context_wrapper: RunContextWrapper[TContext],
|
430 | 417 | config: RunConfig,
|
431 | 418 | ) -> list[FunctionToolResult]:
|
432 |
| - async def run_single_tool( |
433 |
| - func_tool: FunctionTool, tool_call: ResponseFunctionToolCall |
434 |
| - ) -> Any: |
| 419 | + async def run_single_tool(action: ToolRunFunction) -> Any: |
| 420 | + func_tool = action.function_tool |
| 421 | + tool_call = action.tool_call |
435 | 422 | with function_span(func_tool.name) as span_fn:
|
436 | 423 | if config.trace_include_sensitive_data:
|
437 | 424 | span_fn.span_data.input = tool_call.arguments
|
438 | 425 | try:
|
439 | 426 | _, _, result = await asyncio.gather(
|
440 |
| - hooks.on_tool_start(context_wrapper, agent, func_tool), |
| 427 | + hooks.on_tool_start(context_wrapper, agent, action), |
441 | 428 | (
|
442 |
| - agent.hooks.on_tool_start(context_wrapper, agent, func_tool) |
| 429 | + agent.hooks.on_tool_start(context_wrapper, agent, action) |
443 | 430 | if agent.hooks
|
444 | 431 | else _coro.noop_coroutine()
|
445 | 432 | ),
|
@@ -471,8 +458,7 @@ async def run_single_tool(
|
471 | 458 |
|
472 | 459 | tasks = []
|
473 | 460 | for tool_run in tool_runs:
|
474 |
| - function_tool = tool_run.function_tool |
475 |
| - tasks.append(run_single_tool(function_tool, tool_run.tool_call)) |
| 461 | + tasks.append(run_single_tool(tool_run)) |
476 | 462 |
|
477 | 463 | results = await asyncio.gather(*tasks)
|
478 | 464 |
|
@@ -831,9 +817,9 @@ async def execute(
|
831 | 817 | )
|
832 | 818 |
|
833 | 819 | _, _, output = await asyncio.gather(
|
834 |
| - hooks.on_tool_start(context_wrapper, agent, action.computer_tool), |
| 820 | + hooks.on_tool_start(context_wrapper, agent, action), |
835 | 821 | (
|
836 |
| - agent.hooks.on_tool_start(context_wrapper, agent, action.computer_tool) |
| 822 | + agent.hooks.on_tool_start(context_wrapper, agent, action) |
837 | 823 | if agent.hooks
|
838 | 824 | else _coro.noop_coroutine()
|
839 | 825 | ),
|
|
0 commit comments