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

feat(function_schema): Add support for pydanticField annotations in tool arguments (for tools decorated with@function_schema)#1124

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

Merged
rm-openai merged 3 commits intoopenai:mainfromgeorg-wolflein:main
Jul 15, 2025

Conversation

georg-wolflein
Copy link
Contributor

Summary

This PR allows you to use the pydanticField decorator to constrain tool arguments for tools decorated with@function_tool (more specifically, for tools usingfunction_schema to parse tool arguments). Such constrains include, e.g. limiting integers to a certain range, but in principle, this should work forany constrains supported by the API.

Specifically, it enables the following syntax:

@function_tooldefmy_tool(age:int=Field(...,gt=0))->str:    ...

Previously, one had to create a nested pydanticBaseModel to achieve this functionality.
Issue#1123 explains this feature request and the previous workaround.

Example:

importjsonfrompydanticimportFieldfromagentsimportfunction_tool@function_tooldefmy_tool(age:int=Field(...,gt=0))->str:returnf"The age is{age}"print(json.dumps(my_tool.params_json_schema,indent=2))

Output: (compare to#1123)

{  "properties": {    "age": {      "exclusiveMinimum": 0,      "title": "Age",      "type": "integer"    }  },  "required": [    "age"  ],  "title": "my_tool_args",  "type": "object",  "additionalProperties": false}

Test plan

I added unit tests intests/test_function_schema.py.

Issue number

Closes#1123.

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've runmake lint andmake format
  • I've made sure tests pass

Note: I am happy to add documentation for this; please point me to where I should do so:)

@seratchseratch added enhancementNew feature or request feature:core labelsJul 15, 2025
@georg-wolfleingeorg-wolflein changed the titleAdd support for pydanticField annotations in tool arguments (for tools decorated with@function_schema)feat(function_schema): Add support for pydanticField annotations in tool arguments (for tools decorated with@function_schema)Jul 15, 2025
@seratch
Copy link
Member

Could you check the lint error?

uv run ruff checktests/test_function_schema.py:1:1: I001 [*] Import block is un-sorted or un-formatted   | 1 | / from collections.abc import Mapping 2 | | from enum import Enum 3 | | from typing import Any, Literal 4 | | 5 | | import pytest 6 | | from pydantic import BaseModel, ValidationError, Field 7 | | from typing_extensions import TypedDict 8 | | 9 | | from agents import RunContextWrapper10 | | from agents.exceptions import UserError11 | | from agents.function_schema import function_schema12 | |13 | |   | |__^ I00114 |   def no_args_function():15 |       """This function has no args."""   |   = help: Organize importsFound 1 error.[*] 1 fixable with the `--fix` option.make: *** [Makefile:16: lint] Error 1Error: Process completed with exit code 2.

@georg-wolflein
Copy link
ContributorAuthor

georg-wolflein commentedJul 15, 2025
edited
Loading

Could you check the lint error?

Done:)@seratch

@seratchseratch requested review fromseratch andrm-openai and removed request forseratchJuly 15, 2025 10:44
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.

LGTM;@rm-openai can you take a look at this?

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.

This is so good, thanks!@georg-wolflein in a follow up would also love some docs for this

DykeF and georg-wolflein reacted with heart emoji
@rm-openairm-openai merged commit14154b7 intoopenai:mainJul 15, 2025
5 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@seratchseratchseratch approved these changes

@rm-openairm-openairm-openai approved these changes

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.

Support pydanticField annotations in tool arguments
3 participants
@georg-wolflein@seratch@rm-openai

[8]ページ先頭

©2009-2025 Movatter.jp