diff --git a/src/agents/lifecycle.py b/src/agents/lifecycle.py index 438f25d7a..324a401af 100644 --- a/src/agents/lifecycle.py +++ b/src/agents/lifecycle.py @@ -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], @@ -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( @@ -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 @@ -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( @@ -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