Skip to content

Commit 2823d27

Browse files
authored
Fix type annotation, avoid input shadowing, and clarify tool behavior docs
This commit improves type safety by replacing Any with the correct generic type TContext in the get\_all\_tools method. It also avoids confusion by renaming the input parameter in the run\_agent function to user\_input because input is a built-in function in Python. Lastly, it updates the documentation of tool\_use\_behavior to clearly describe the use of the StopAtTools object instead of a plain list of tool names. These changes make the code more accurate, easier to understand, and better aligned with best practices.
1 parent 818344c commit 2823d27

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/agents/agent.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def get_mcp_tools(self, run_context: RunContextWrapper[TContext]) -> list[
101101
self.mcp_servers, convert_schemas_to_strict, run_context, self
102102
)
103103

104-
async def get_all_tools(self, run_context: RunContextWrapper[Any]) -> list[Tool]:
104+
async def get_all_tools(self, run_context: RunContextWrapper[TContext]) -> list[Tool]:
105105
"""All agent tools, including MCP tools and function tools."""
106106
mcp_tools = await self.get_mcp_tools(run_context)
107107

@@ -201,14 +201,16 @@ class Agent(AgentBase, Generic[TContext]):
201201
tool_use_behavior: (
202202
Literal["run_llm_again", "stop_on_first_tool"] | StopAtTools | ToolsToFinalOutputFunction
203203
) = "run_llm_again"
204-
"""This lets you configure how tool use is handled.
204+
"""
205+
This lets you configure how tool use is handled.
205206
- "run_llm_again": The default behavior. Tools are run, and then the LLM receives the results
206207
and gets to respond.
207208
- "stop_on_first_tool": The output of the first tool call is used as the final output. This
208209
means that the LLM does not process the result of the tool call.
209-
- A list of tool names: The agent will stop running if any of the tools in the list are called.
210-
The final output will be the output of the first matching tool call. The LLM does not
211-
process the result of the tool call.
210+
- A StopAtTools object: The agent will stop running if any of the tools listed in
211+
`stop_at_tool_names` is called.
212+
The final output will be the output of the first matching tool call.
213+
The LLM does not process the result of the tool call.
212214
- A function: If you pass a function, it will be called with the run context and the list of
213215
tool results. It must return a `ToolsToFinalOutputResult`, which determines whether the tool
214216
calls result in a final output.
@@ -262,7 +264,7 @@ def as_tool(
262264
name_override=tool_name or _transforms.transform_string_function_style(self.name),
263265
description_override=tool_description or "",
264266
)
265-
async def run_agent(context: RunContextWrapper, input: str) -> str:
267+
async def run_agent(context: RunContextWrapper, user_input: str) -> str:
266268
from .run import Runner
267269

268270
output = await Runner.run(

0 commit comments

Comments
 (0)