Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added runtime validation for Agent name field#998

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
DanielHashmi wants to merge25 commits intoopenai:main
base:main
Choose a base branch
Loading
fromDanielHashmi:main

Conversation

DanielHashmi
Copy link
Contributor

@DanielHashmiDanielHashmi commentedJul 3, 2025
edited by seratch
Loading

Add__post_init__ validation to ensure Agent name is a string

The Agent class previously only used type hints for the name field without
runtime validation, allowing non-string values like integers to be passed.
This caused downstream errors during JSON serialization, tracing, and other
operations that expect the name to be a string.

Changes:

  • Add__post_init__ method to Agent class withisinstance check
  • Raise TypeError with descriptive message for non-string names
  • Validation occurs at instantiation time to fail fast

Fixes issue whereAgent(name=1) would succeed but cause errors later
in the execution pipeline.

Fixes#996

@seratch
Copy link
Member

seratch commentedJul 8, 2025
edited
Loading

Related to#996; if we add this, we may want to have validation logic for other arguments too@rm-openai any opinion?

DanielHashmi reacted with thumbs up emoji

@DanielHashmi
Copy link
ContributorAuthor

Thanks for the feedback! You're right that this could be part of a broader validation pattern. Looking at the Agent class, several other fields could benefit from similar runtime validation:

  • instructions: Should validate str, callable, or None
  • tools: Should validate list of Tool objects
  • handoffs: Should validate list of Agent/Handoff objects
  1. Should we implement validation incrementally or all at once?
  2. Prefer individualisinstance checks in__post_init__ or a structured validation framework?
  3. Any specific validation patterns you'd like as the SDK standard?

I'm happy if I can expand this PR to include other critical fields or use this as a foundation for incremental validation. What approach works best for the team?

@seratch
Copy link
Member

Should we implement validation incrementally or all at once?

Agent class currently has 16 fields, so adding all of them may take some time. If you're fine with it, your contribution would be appreciated. Otherwise, we can later add validations to the rest of the fields after merging this PR only with name.

Prefer individual isinstance checks inpost_init or a structured validation framework?

Simply writing all logic in__post_init__ should be fine for now. Perhaps, most code would be combination ofif XXX is not None andif isinstance(V, T).

Any specific validation patterns you'd like as the SDK standard?

Checking if a value is not None and then check the type of the value would be enough. I don't think we should scan all the elements of an array and nested property values (i.e., no need to check internal values ofModelSettings, each element ofhandoffs etc.). We may want to do similar to other data classes, but in this PR, we can focus on the Agent class.

DanielHashmi reacted with thumbs up emoji

@seratch
Copy link
Member

I just noticed@rm-openai started refactoring of the class -#1044 ; aligning with this change and/or working on this PR after the refactoring is done would be appreciated 🙏

DanielHashmi reacted with thumbs up emoji

@DanielHashmi
Copy link
ContributorAuthor

Ok! will work on this after refactoring 👍

@seratch
Copy link
Member

@DanielHashmi The refactoring is done, and we've been receiving the same feedback from a few users. If you have time and interest to resume this PR work, it'd be appreciated! (Otherwise, I am happy to work on the rest 👋 )

DanielHashmi reacted with thumbs up emoji

@DanielHashmi
Copy link
ContributorAuthor

I have added validations and some tests, Can you review it and tell me what should be my next step?

@seratchseratch requested review fromrm-openai andCopilot and removed request forCopilotJuly 16, 2025 22:54
Copilot

This comment was marked as resolved.

Copy link
Member

@seratchseratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks great to me
@rm-openai we've been receiving the same feedback about the lack of validation of inti params for Agent almost every day. Can you take a look at this change and include it in the upcoming release?

Copy link
Collaborator

@rm-openairm-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could certainly add this, but I do wonder what the underlying issue is? Why are callsites setting non-string params?

@seratch
Copy link
Member

@rm-openai people are not trying to intentionally pass non-string to the name property, but a few people reported that they are confused with unexpected runtime error later on when they set invalid ones. You can find the list of issues linked here:#996 Thus, having validation for Agent initialization should make sense.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@rm-openairm-openairm-openai requested changes

@seratchseratchseratch approved these changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
enhancementNew feature or requestfeature:core
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

No validation on the Agent constructor arguments
3 participants
@DanielHashmi@seratch@rm-openai

[8]ページ先頭

©2009-2025 Movatter.jp