Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Agent name validation
  • Loading branch information
EngineerAbdullahIqbal committed Jul 10, 2025
commit 148dbcbdca2f6000de6f9e4136b3470933148835
9 changes: 8 additions & 1 deletion src/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Agent(Generic[TContext]):
"""

name: str
"""The name of the agent."""
"""The name of the agent. Must be a non-empty string."""

instructions: (
str
Expand Down Expand Up @@ -264,6 +264,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("name must be a string")
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."""
Expand Down