Skip to content

refactor: Add runtime type validation for Agent 'instructions'Update agent.py #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class Agent(AgentBase, Generic[TContext]):
"""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 __post_init__(self):
if self.instructions is not None and not (
isinstance(self.instructions, str) or callable(self.instructions)
):
raise TypeError(
f"The 'instructions' must be a string or a callable, but received {type(self.instructions).__name__}."
)

def clone(self, **kwargs: Any) -> Agent[TContext]:
"""Make a copy of the agent, with the given arguments changed. For example, you could do:
```
Expand Down