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

Conversation

MurtazaAliCode
Copy link

This Pull Request improves the robustness of the Agent class by adding explicit runtime validation for the instructions parameter.

The issue:

  • While the type hint for instructions is str | Callable | None, the current implementation does not prevent invalid types (e.g., integers, lists) from being passed, which could lead to unexpected behavior at a later stage.

The solution:

  • A check has been added to the post_init method of the Agent class.
  • This check ensures that if instructions is provided (i.e., not None), it must be either a string or a callable object.
  • A TypeError is now raised immediately if an incorrect type is used, providing clear feedback to the developer.

Why this is important:

  • Developer Experience: This change provides immediate and helpful feedback to developers, preventing them from running into obscure errors later in their code.
  • Code Integrity: It ensures that the instructions parameter always conforms to its expected type, which is critical for the reliable functioning of the agent.

This update aligns the runtime behavior of the Agent class with its stated type hints, making the code more predictable and easier to debug.

@seratch seratch added the duplicate This issue or pull request already exists label Aug 1, 2025
@seratch
Copy link
Member

seratch commented Aug 1, 2025

Thanks for sending this. However, we're going to resolve this issue by #998

@seratch seratch closed this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants