Skip to content

Commit d659a73

Browse files
authored
docs: clarify on_tool_start and on_tool_end hooks for local tools only (#2037)
1 parent 0c4f2b9 commit d659a73

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

examples/basic/agent_lifecycle_example.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +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+
# Note: The on_tool_start and on_tool_end hooks apply only to local tools.
32+
# They do not include hosted tools that run on the OpenAI server side,
33+
# such as WebSearchTool, FileSearchTool, CodeInterpreterTool, HostedMCPTool,
34+
# or other built-in hosted tools.
3135
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
3236
self.event_counter += 1
3337
print(

examples/basic/lifecycle_example.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ async def on_agent_end(self, context: RunContextWrapper, agent: Agent, output: A
7070
f"### {self.event_counter}: Agent {agent.name} ended with output {output}. Usage: {self._usage_to_str(context.usage)}"
7171
)
7272

73+
# Note: The on_tool_start and on_tool_end hooks apply only to local tools.
74+
# They do not include hosted tools that run on the OpenAI server side,
75+
# such as WebSearchTool, FileSearchTool, CodeInterpreterTool, HostedMCPTool,
76+
# or other built-in hosted tools.
7377
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
7478
self.event_counter += 1
7579
# While this type cast is not ideal,

src/agents/lifecycle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def on_tool_start(
6262
agent: TAgent,
6363
tool: Tool,
6464
) -> None:
65-
"""Called concurrently with tool invocation."""
65+
"""Called immediately before a local tool is invoked."""
6666
pass
6767

6868
async def on_tool_end(
@@ -72,7 +72,7 @@ async def on_tool_end(
7272
tool: Tool,
7373
result: str,
7474
) -> None:
75-
"""Called after a tool is invoked."""
75+
"""Called immediately after a local tool is invoked."""
7676
pass
7777

7878

@@ -113,7 +113,7 @@ async def on_tool_start(
113113
agent: TAgent,
114114
tool: Tool,
115115
) -> None:
116-
"""Called concurrently with tool invocation."""
116+
"""Called immediately before a local tool is invoked."""
117117
pass
118118

119119
async def on_tool_end(
@@ -123,7 +123,7 @@ async def on_tool_end(
123123
tool: Tool,
124124
result: str,
125125
) -> None:
126-
"""Called after a tool is invoked."""
126+
"""Called immediately after a local tool is invoked."""
127127
pass
128128

129129
async def on_llm_start(

0 commit comments

Comments
 (0)