Skip to content

Commit 86ec7f0

Browse files
yanmxaclaude
andcommitted
rollback
Signed-off-by: myan <myan@redhat.com> fix: resolve lint issues - Fix import sorting in multiple files - Remove duplicate ResponseComputerToolCall import - Organize imports according to ruff rules 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> fix: resolve lint issues - Fix import sorting in multiple files - Remove duplicate ResponseComputerToolCall import - Organize imports according to ruff rules 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> fix: restore correct context parameter for function tool hooks - Function tools should use tool_context (ToolContext) - Computer/shell tools use context_wrapper (RunContextWrapper) - This maintains consistency with original codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> chore: remove VSCode configuration files from PR - Remove .vscode/ directory and all IDE-specific configuration - These files should not be included in the repository 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent efa88f7 commit 86ec7f0

File tree

10 files changed

+46
-63
lines changed

10 files changed

+46
-63
lines changed

.vscode/launch.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/basic/agent_lifecycle_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pydantic import BaseModel
66

7-
from agents import Agent, AgentHooks, RunContextWrapper, Runner, Tool, function_tool
7+
from agents import Action, Agent, AgentHooks, RunContextWrapper, Runner, Tool, function_tool
88

99

1010
class CustomAgentHooks(AgentHooks):
@@ -28,10 +28,10 @@ async def on_handoff(self, context: RunContextWrapper, agent: Agent, source: Age
2828
f"### ({self.display_name}) {self.event_counter}: Agent {source.name} handed off to {agent.name}"
2929
)
3030

31-
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
31+
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 {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(

examples/basic/lifecycle_example.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
from pydantic import BaseModel
66

7-
from agents import Agent, RunContextWrapper, RunHooks, Runner, Tool, Usage, function_tool
7+
from agents import Action, Agent, RunContextWrapper, RunHooks, Runner, Tool, Usage, function_tool
88
from agents.items import ModelResponse, TResponseInputItem
99

10-
1110
class ExampleHooks(RunHooks):
1211
def __init__(self):
1312
self.event_counter = 0
@@ -43,10 +42,10 @@ async def on_agent_end(self, context: RunContextWrapper, agent: Agent, output: A
4342
f"### {self.event_counter}: Agent {agent.name} ended with output {output}. Usage: {self._usage_to_str(context.usage)}"
4443
)
4544

46-
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
45+
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, action: Action) -> None:
4746
self.event_counter += 1
4847
print(
49-
f"### {self.event_counter}: Tool {tool.name} started. Usage: {self._usage_to_str(context.usage)}"
48+
f"### {self.event_counter}: Tool {action.function_tool.tool.name} started. Usage: {self._usage_to_str(context.usage)}"
5049
)
5150

5251
async def on_tool_end(

src/agents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
StreamEvent,
6666
)
6767
from .tool import (
68+
Action,
6869
CodeInterpreterTool,
6970
ComputerTool,
7071
FileSearchTool,
@@ -250,6 +251,7 @@ def enable_verbose_stdout_logging():
250251
"MCPToolApprovalRequest",
251252
"MCPToolApprovalFunctionResult",
252253
"function_tool",
254+
"Action",
253255
"Usage",
254256
"add_trace_processor",
255257
"agent_span",

src/agents/_run_impl.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
LocalShellTool,
7979
MCPToolApprovalRequest,
8080
Tool,
81+
ToolRunComputerAction,
82+
ToolRunFunction,
8183
)
8284
from .tool_context import ToolContext
8385
from .tracing import (
@@ -126,19 +128,6 @@ class ToolRunHandoff:
126128
handoff: Handoff
127129
tool_call: ResponseFunctionToolCall
128130

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-
142131
@dataclass
143132
class ToolRunMCPApprovalRequest:
144133
request_item: McpApprovalRequest
@@ -557,9 +546,9 @@ async def execute_function_tool_calls(
557546
context_wrapper: RunContextWrapper[TContext],
558547
config: RunConfig,
559548
) -> list[FunctionToolResult]:
560-
async def run_single_tool(
561-
func_tool: FunctionTool, tool_call: ResponseFunctionToolCall
562-
) -> Any:
549+
async def run_single_tool(action: ToolRunFunction) -> Any:
550+
func_tool = action.function_tool
551+
tool_call = action.tool_call
563552
with function_span(func_tool.name) as span_fn:
564553
tool_context = ToolContext.from_agent_context(
565554
context_wrapper,
@@ -570,9 +559,9 @@ async def run_single_tool(
570559
span_fn.span_data.input = tool_call.arguments
571560
try:
572561
_, _, result = await asyncio.gather(
573-
hooks.on_tool_start(tool_context, agent, func_tool),
562+
hooks.on_tool_start(tool_context, agent, action),
574563
(
575-
agent.hooks.on_tool_start(tool_context, agent, func_tool)
564+
agent.hooks.on_tool_start(tool_context, agent, action)
576565
if agent.hooks
577566
else _coro.noop_coroutine()
578567
),
@@ -604,8 +593,7 @@ async def run_single_tool(
604593

605594
tasks = []
606595
for tool_run in tool_runs:
607-
function_tool = tool_run.function_tool
608-
tasks.append(run_single_tool(function_tool, tool_run.tool_call))
596+
tasks.append(run_single_tool(tool_run))
609597

610598
results = await asyncio.gather(*tasks)
611599

@@ -1066,9 +1054,9 @@ async def execute(
10661054
)
10671055

10681056
_, _, output = await asyncio.gather(
1069-
hooks.on_tool_start(context_wrapper, agent, action.computer_tool),
1057+
hooks.on_tool_start(context_wrapper, agent, action),
10701058
(
1071-
agent.hooks.on_tool_start(context_wrapper, agent, action.computer_tool)
1059+
agent.hooks.on_tool_start(context_wrapper, agent, action)
10721060
if agent.hooks
10731061
else _coro.noop_coroutine()
10741062
),

src/agents/lifecycle.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .agent import Agent, AgentBase
66
from .items import ModelResponse, TResponseInputItem
77
from .run_context import RunContextWrapper, TContext
8-
from .tool import Tool
8+
from .tool import Action, Tool
99

1010
TAgent = TypeVar("TAgent", bound=AgentBase, default=AgentBase)
1111

@@ -59,8 +59,8 @@ async def on_handoff(
5959
async def on_tool_start(
6060
self,
6161
context: RunContextWrapper[TContext],
62-
agent: TAgent,
63-
tool: Tool,
62+
agent: Agent[TContext],
63+
action: Action,
6464
) -> None:
6565
"""Called concurrently with tool invocation."""
6666
pass
@@ -110,8 +110,8 @@ async def on_handoff(
110110
async def on_tool_start(
111111
self,
112112
context: RunContextWrapper[TContext],
113-
agent: TAgent,
114-
tool: Tool,
113+
agent: Agent[TContext],
114+
action: Action,
115115
) -> None:
116116
"""Called concurrently with tool invocation."""
117117
pass

src/agents/tool.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dataclasses import dataclass
77
from typing import TYPE_CHECKING, Any, Callable, Literal, Union, overload
88

9+
from openai.types.responses import ResponseFunctionToolCall
910
from openai.types.responses.file_search_tool_param import Filters, RankingOptions
1011
from openai.types.responses.response_computer_tool_call import (
1112
PendingSafetyCheck,
@@ -294,6 +295,19 @@ def name(self):
294295
]
295296
"""A tool that can be used in an agent."""
296297

298+
@dataclass
299+
class ToolRunFunction:
300+
tool_call: ResponseFunctionToolCall
301+
function_tool: FunctionTool
302+
303+
304+
@dataclass
305+
class ToolRunComputerAction:
306+
tool_call: ResponseComputerToolCall
307+
computer_tool: ComputerTool
308+
309+
Action = Union[ToolRunFunction, ToolRunComputerAction]
310+
"""An action that can be performed by an agent. It contains the tool call and the tool"""
297311

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

tests/test_agent_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from typing_extensions import TypedDict
99

10-
from agents.agent import Agent
10+
from agents.agent import Action, Agent
1111
from agents.lifecycle import AgentHooks
1212
from agents.run import Runner
1313
from agents.run_context import RunContextWrapper, TContext
@@ -53,7 +53,7 @@ async def on_tool_start(
5353
self,
5454
context: RunContextWrapper[TContext],
5555
agent: Agent[TContext],
56-
tool: Tool,
56+
action: Action,
5757
) -> None:
5858
self.events["on_tool_start"] += 1
5959

tests/test_computer_action.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
)
2424

2525
from agents import (
26+
Action,
2627
Agent,
2728
AgentHooks,
2829
AsyncComputer,
@@ -32,9 +33,9 @@
3233
RunContextWrapper,
3334
RunHooks,
3435
)
35-
from agents._run_impl import ComputerAction, RunImpl, ToolRunComputerAction
36+
from agents._run_impl import ComputerAction, RunImpl
3637
from agents.items import ToolCallOutputItem
37-
from agents.tool import ComputerToolSafetyCheckData
38+
from agents.tool import ComputerToolSafetyCheckData, ToolRunComputerAction
3839

3940

4041
class LoggingComputer(Computer):
@@ -224,9 +225,9 @@ def __init__(self) -> None:
224225
self.ended: list[tuple[Agent[Any], Any, str]] = []
225226

226227
async def on_tool_start(
227-
self, context: RunContextWrapper[Any], agent: Agent[Any], tool: Any
228+
self, context: RunContextWrapper[Any], agent: Agent[Any], action: Action,
228229
) -> None:
229-
self.started.append((agent, tool))
230+
self.started.append((agent, action.computer_tool))
230231

231232
async def on_tool_end(
232233
self, context: RunContextWrapper[Any], agent: Agent[Any], tool: Any, result: str
@@ -243,9 +244,9 @@ def __init__(self) -> None:
243244
self.ended: list[tuple[Agent[Any], Any, str]] = []
244245

245246
async def on_tool_start(
246-
self, context: RunContextWrapper[Any], agent: Agent[Any], tool: Any
247+
self, context: RunContextWrapper[Any], agent: Agent[Any], action: Action,
247248
) -> None:
248-
self.started.append((agent, tool))
249+
self.started.append((agent, action.computer_tool))
249250

250251
async def on_tool_end(
251252
self, context: RunContextWrapper[Any], agent: Agent[Any], tool: Any, result: str

0 commit comments

Comments
 (0)