diff --git a/src/agents/agent.py b/src/agents/agent.py index 6c87297f1..db51257c3 100644 --- a/src/agents/agent.py +++ b/src/agents/agent.py @@ -79,7 +79,11 @@ class Agent(Generic[TContext]): """ name: str - """The name of the agent.""" + """The name of the agent. Must be a non-empty string. + Raises: + TypeError: if not a string + ValueError: if empty or only whitespace + """ instructions: ( str @@ -264,6 +268,13 @@ async def get_mcp_tools( return await MCPUtil.get_all_function_tools( self.mcp_servers, convert_schemas_to_strict, run_context, self ) + + def __post_init__(self): + if not isinstance(self.name, str): + raise TypeError(f"`name` must be a string, got {type(self.name).__name__!r}") + if not self.name.strip(): + raise ValueError("`name` cannot be empty or contain only whitespace") + async def get_all_tools(self, run_context: RunContextWrapper[Any]) -> list[Tool]: """All agent tools, including MCP tools and function tools."""