Skip to content

Commit fccd3fa

Browse files
committed
add test
Signed-off-by: myan <[email protected]>
1 parent f1ebc69 commit fccd3fa

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

examples/basic/agent_lifecycle_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def on_handoff(self, context: RunContextWrapper, agent: Agent, source: Age
3131
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, action: Action) -> None:
3232
self.event_counter += 1
3333
print(
34-
f"### ({self.display_name}) {self.event_counter}: Agent {agent.name} started tool {action.function_tool.name}"
34+
f"### ({self.display_name}) {self.event_counter}: Agent {agent.name} started tool {action.function_tool.name} with arguments {action.tool_call.arguments}"
3535
)
3636

3737
async def on_tool_end(

src/agents/_run_impl.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from .models.interface import ModelTracing
5353
from .run_context import RunContextWrapper, TContext
5454
from .stream_events import RunItemStreamEvent, StreamEvent
55-
from .tool import ComputerTool, FunctionTool, FunctionToolResult, Tool
55+
from .tool import ComputerTool, FunctionTool, FunctionToolResult, Tool, ToolRunFunction, ToolRunComputerAction
5656
from .tracing import (
5757
SpanError,
5858
Trace,
@@ -99,19 +99,6 @@ class ToolRunHandoff:
9999
handoff: Handoff
100100
tool_call: ResponseFunctionToolCall
101101

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-
115102
@dataclass
116103
class ProcessedResponse:
117104
new_items: list[RunItem]
@@ -471,8 +458,7 @@ async def run_single_tool(action: ToolRunFunction) -> Any:
471458

472459
tasks = []
473460
for tool_run in tool_runs:
474-
function_tool = tool_run.function_tool
475-
tasks.append(run_single_tool(function_tool, tool_run))
461+
tasks.append(run_single_tool(tool_run))
476462

477463
results = await asyncio.gather(*tasks)
478464

src/agents/tool.py

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from openai.types.responses.web_search_tool_param import UserLocation
1111
from pydantic import ValidationError
1212
from typing_extensions import Concatenate, ParamSpec
13+
from openai.types.responses import (
14+
ResponseComputerToolCall,
15+
ResponseFunctionToolCall,
16+
)
1317

1418
from . import _debug
1519
from .computer import AsyncComputer, Computer
@@ -133,6 +137,19 @@ def name(self):
133137
Tool = Union[FunctionTool, FileSearchTool, WebSearchTool, ComputerTool]
134138
"""A tool that can be used in an agent."""
135139

140+
@dataclass
141+
class ToolRunFunction:
142+
tool_call: ResponseFunctionToolCall
143+
function_tool: FunctionTool
144+
145+
146+
@dataclass
147+
class ToolRunComputerAction:
148+
tool_call: ResponseComputerToolCall
149+
computer_tool: ComputerTool
150+
151+
Action = Union[ToolRunFunction, ToolRunComputerAction]
152+
"""An action that can be performed by an agent. It contains the tool call and the tool"""
136153

137154
def default_tool_error_function(ctx: RunContextWrapper[Any], error: Exception) -> str:
138155
"""The default tool error function, which just returns a generic error message."""

0 commit comments

Comments
 (0)