|
1 |
| -from typing import Any, Generic |
| 1 | +from typing import Any, Generic, List |
2 | 2 |
|
3 | 3 | from typing_extensions import TypeVar
|
4 | 4 |
|
5 | 5 | from .agent import Agent, AgentBase
|
6 | 6 | from .run_context import RunContextWrapper, TContext
|
7 | 7 | from .tool import Tool
|
| 8 | +from .items import TResponseInputItem, ModelResponse |
8 | 9 |
|
9 |
| -TAgent = TypeVar("TAgent", bound=AgentBase, default=AgentBase) |
10 | 10 |
|
| 11 | +TAgent = TypeVar("TAgent", bound=AgentBase, default=AgentBase) |
11 | 12 |
|
12 | 13 | class RunHooksBase(Generic[TContext, TAgent]):
|
13 | 14 | """A class that receives callbacks on various lifecycle events in an agent run. Subclass and
|
14 | 15 | override the methods you need.
|
15 | 16 | """
|
16 | 17 |
|
17 |
| - async def on_agent_start(self, context: RunContextWrapper[TContext], agent: TAgent) -> None: |
| 18 | + async def on_llm_start( |
| 19 | + self, |
| 20 | + context: RunContextWrapper[TContext], |
| 21 | + agent: TAgent, |
| 22 | + system_prompt: str | None, |
| 23 | + input_items: List[TResponseInputItem] |
| 24 | + ) -> None: |
| 25 | + """Called just before invoking the LLM for this agent.""" |
| 26 | + pass |
| 27 | + |
| 28 | + async def on_llm_end( |
| 29 | + self, |
| 30 | + context: RunContextWrapper[TContext], |
| 31 | + agent: TAgent, |
| 32 | + response: ModelResponse |
| 33 | + ) -> None: |
| 34 | + """Called immediately after the LLM call returns for this agent.""" |
| 35 | + pass |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + async def on_agent_start( |
| 41 | + self, context: RunContextWrapper[TContext], agent: TAgent |
| 42 | + ) -> None: |
18 | 43 | """Called before the agent is invoked. Called each time the current agent changes."""
|
19 | 44 | pass
|
20 | 45 |
|
|
0 commit comments