diff --git a/src/agents/agent.py b/src/agents/agent.py index c6f25b08f..895671484 100644 --- a/src/agents/agent.py +++ b/src/agents/agent.py @@ -24,6 +24,10 @@ from .util import _transforms from .util._types import MaybeAwaitable +# Pydantic ke liye import add kiya +from pydantic import BaseModel, Field +from typing import Union + if TYPE_CHECKING: from .lifecycle import AgentHooks from .mcp import MCPServer @@ -136,6 +140,12 @@ class Agent(AgentBase, Generic[TContext]): See `AgentBase` for base parameters that are shared with `RealtimeAgent`s. """ + name: str = field(default=..., metadata={"description": "Agent name must be a string, int or boolean will raise an error"}) + + def __post_init__(self): + if not isinstance(self.name, str): + raise TypeError("Agent name must be a string, got {} instead".format(type(self.name).__name__)) + instructions: ( str | Callable[ @@ -220,7 +230,6 @@ class Agent(AgentBase, Generic[TContext]): reset_tool_choice: bool = True """Whether to reset the tool choice to the default value after a tool has been called. Defaults to True. This ensures that the agent doesn't enter an infinite loop of tool usage.""" - def clone(self, **kwargs: Any) -> Agent[TContext]: """Make a copy of the agent, with the given arguments changed. For example, you could do: ``` diff --git a/tests/test_agent_name.py b/tests/test_agent_name.py new file mode 100644 index 000000000..cc0594811 --- /dev/null +++ b/tests/test_agent_name.py @@ -0,0 +1,15 @@ +import pytest +from src.agents import Agent + +def test_agent_name_types(): + # String name (should pass) + agent1 = Agent(name="Test", instructions="Test", model="gpt-4o") + assert agent1.name == "Test" + + # Integer name (should raise TypeError) + with pytest.raises(TypeError): + Agent(name=123, instructions="Test", model="gpt-4o") + + # Boolean name (should raise TypeError) + with pytest.raises(TypeError): + Agent(name=True, instructions="Test", model="gpt-4o") \ No newline at end of file