Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/basic/agent_lifecycle_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ async def on_handoff(self, context: RunContextWrapper, agent: Agent, source: Age
f"### ({self.display_name}) {self.event_counter}: Agent {source.name} handed off to {agent.name}"
)

# Note: The on_tool_start and on_tool_end hooks apply only to local tools.
# They do not include hosted tools that run on the OpenAI server side,
# such as WebSearchTool, FileSearchTool, CodeInterpreterTool, HostedMCPTool,
# or other built-in hosted tools.
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
self.event_counter += 1
print(
Expand Down
4 changes: 4 additions & 0 deletions examples/basic/lifecycle_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ async def on_agent_end(self, context: RunContextWrapper, agent: Agent, output: A
f"### {self.event_counter}: Agent {agent.name} ended with output {output}. Usage: {self._usage_to_str(context.usage)}"
)

# Note: The on_tool_start and on_tool_end hooks apply only to local tools.
# They do not include hosted tools that run on the OpenAI server side,
# such as WebSearchTool, FileSearchTool, CodeInterpreterTool, HostedMCPTool,
# or other built-in hosted tools.
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
self.event_counter += 1
# While this type cast is not ideal,
Expand Down
8 changes: 4 additions & 4 deletions src/agents/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def on_tool_start(
agent: TAgent,
tool: Tool,
) -> None:
"""Called concurrently with tool invocation."""
"""Called immediately before a local tool is invoked."""
pass

async def on_tool_end(
Expand All @@ -72,7 +72,7 @@ async def on_tool_end(
tool: Tool,
result: str,
) -> None:
"""Called after a tool is invoked."""
"""Called immediately after a local tool is invoked."""
pass


Expand Down Expand Up @@ -113,7 +113,7 @@ async def on_tool_start(
agent: TAgent,
tool: Tool,
) -> None:
"""Called concurrently with tool invocation."""
"""Called immediately before a local tool is invoked."""
pass

async def on_tool_end(
Expand All @@ -123,7 +123,7 @@ async def on_tool_end(
tool: Tool,
result: str,
) -> None:
"""Called after a tool is invoked."""
"""Called immediately after a local tool is invoked."""
pass

async def on_llm_start(
Expand Down