Skip to content

Commit 2bb698a

Browse files
authored
Add a reusable type alias for agent instructions callbacks
### Summary Add a reusable type alias for agent instructions callbacks and use it in `Agent.instructions` to improve readability and consistency. ### Changes Made - Added `AgentInstructionsFunction` in `src/agents/agent.py`: - `AgentInstructionsFunction = Callable[[RunContextWrapper[TContext], "Agent[TContext]"], MaybeAwaitable[str]]` - Updated `Agent.instructions` type to: - `instructions: str | AgentInstructionsFunction | None = None` - No behavioral changes; typing/clarity only.
1 parent d91e39c commit 2bb698a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/agents/agent.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class ToolsToFinalOutputResult:
5959
"""
6060

6161

62+
AgentInstructionsFunction: TypeAlias = Callable[
63+
[RunContextWrapper[TContext], "Agent[TContext]"],
64+
MaybeAwaitable[str],
65+
]
66+
67+
6268
class StopAtTools(TypedDict):
6369
stop_at_tool_names: list[str]
6470
"""A list of tool names, any of which will stop the agent from running further."""
@@ -143,14 +149,7 @@ class Agent(AgentBase, Generic[TContext]):
143149
See `AgentBase` for base parameters that are shared with `RealtimeAgent`s.
144150
"""
145151

146-
instructions: (
147-
str
148-
| Callable[
149-
[RunContextWrapper[TContext], Agent[TContext]],
150-
MaybeAwaitable[str],
151-
]
152-
| None
153-
) = None
152+
instructions: str | AgentInstructionsFunction | None = None
154153
"""The instructions for the agent. Will be used as the "system prompt" when this agent is
155154
invoked. Describes what the agent should do, and how it responds.
156155

0 commit comments

Comments
 (0)