Skip to content
Closed
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
72 changes: 36 additions & 36 deletions src/agents/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class RunHooksBase(Generic[TContext, TAgent]):
override the methods you need.
"""

async def on_agent_start(self, context: RunContextWrapper[TContext], agent: TAgent) -> None:
"""Called before the agent is invoked. Called each time the current agent changes."""
pass

async def on_llm_start(
self,
context: RunContextWrapper[TContext],
Expand All @@ -34,17 +38,23 @@ async def on_llm_end(
"""Called immediately after the LLM call returns for this agent."""
pass

async def on_agent_start(self, context: RunContextWrapper[TContext], agent: TAgent) -> None:
"""Called before the agent is invoked. Called each time the current agent changes."""
async def on_tool_start(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
tool: Tool,
) -> None:
"""Called concurrently with tool invocation."""
pass

async def on_agent_end(
async def on_tool_end(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
output: Any,
tool: Tool,
result: str,
) -> None:
"""Called when the agent produces a final output."""
"""Called after a tool is invoked."""
pass

async def on_handoff(
Expand All @@ -56,23 +66,13 @@ async def on_handoff(
"""Called when a handoff occurs."""
pass

async def on_tool_start(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
tool: Tool,
) -> None:
"""Called concurrently with tool invocation."""
pass

async def on_tool_end(
async def on_agent_end(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
tool: Tool,
result: str,
output: Any,
) -> None:
"""Called after a tool is invoked."""
"""Called when the agent produces a final output."""
pass


Expand All @@ -88,23 +88,23 @@ async def on_start(self, context: RunContextWrapper[TContext], agent: TAgent) ->
agent."""
pass

async def on_end(
async def on_llm_start(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
output: Any,
agent: Agent[TContext],
system_prompt: Optional[str],
input_items: list[TResponseInputItem],
) -> None:
"""Called when the agent produces a final output."""
"""Called immediately before the agent issues an LLM call."""
pass

async def on_handoff(
async def on_llm_end(
self,
context: RunContextWrapper[TContext],
agent: TAgent,
source: TAgent,
agent: Agent[TContext],
response: ModelResponse,
) -> None:
"""Called when the agent is being handed off to. The `source` is the agent that is handing
off to this agent."""
"""Called immediately after the agent receives the LLM response."""
pass

async def on_tool_start(
Expand All @@ -126,23 +126,23 @@ async def on_tool_end(
"""Called after a tool is invoked."""
pass

async def on_llm_start(
async def on_handoff(
self,
context: RunContextWrapper[TContext],
agent: Agent[TContext],
system_prompt: Optional[str],
input_items: list[TResponseInputItem],
agent: TAgent,
source: TAgent,
) -> None:
"""Called immediately before the agent issues an LLM call."""
"""Called when the agent is being handed off to. The `source` is the agent that is handing
off to this agent."""
pass

async def on_llm_end(
async def on_end(
self,
context: RunContextWrapper[TContext],
agent: Agent[TContext],
response: ModelResponse,
agent: TAgent,
output: Any,
) -> None:
"""Called immediately after the agent receives the LLM response."""
"""Called when the agent produces a final output."""
pass


Expand Down