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

Add custom_metadata property to all tool types#2048

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

Draft
hayescode wants to merge2 commits intoopenai:main
base:main
Choose a base branch
Loading
fromhayescode:main

Conversation

@hayescode
Copy link

This pull request adds support for attaching optional custom metadata to all tool classes insrc/agents/tool.py. This metadata can be used to store arbitrary information relevant to each tool instance and is accessible during tool execution, including via agent hooks. Comprehensive tests are included to verify default behavior, metadata assignment, and propagation to hooks.

Why?:

  • Developers can add custom attributes to the defined tools that are custom to their implementation.
  • For example in our architecture we define things like DisplayName and Icon in our tools for use in our Frontend. Here's what I'm doing today vs. after this PR is merged.

Current

fromagents.toolimportfunction_toolfromtypingimportOptional,Literal,Union,TypeAliasMarkdownLanguage:TypeAlias=Literal["python","sql","bash","json","markdown","text"]classToolMetadata(BaseModel):type:strdefault_open:bool=Falseinput_language:Union[bool,MarkdownLanguage]="json"output_language:MarkdownLanguage="text"input_parameters:list[str]|None=Noneavatar:Optional[str]=Nonedefapply_to_tool(self,tool:Tool,access_token:str|None=None)->Tool:"""Apply validated metadata to a tool instance (mutates in place)."""ifaccess_tokenandisinstance(tool,HostedMCPTool):tool.tool_config.authorization=access_tokenforfield_nameinself.__class__.model_fields:value=getattr(self,field_name)ifvalueisnotNone:setattr(tool,field_name,value)returntool@function_toolasyncdefmultiply_by_two(x:int)->int:returnx*2metadata=ToolMetadata(display_name="Math Tool",family="computation",avatar="calculator",input_language="python")math_tool=metadata.apply_to_tool(multiply_by_two)print(f"Configured Tool:{math_tool}")print(f"Display Name:{math_tool.display_name}")

New

classToolMetadata(TypedDict):type:strdefault_open:bool=Falseinput_language:Union[bool,MarkdownLanguage]="json"output_language:MarkdownLanguage="text"input_parameters:list[str]|None=Noneavatar:Optional[str]=Nonemetadata=ToolMetadata(display_name="Math Tool",family="computation",avatar="calculator",input_language="python")@function_tool(custom_metadata=metadata)asyncdefmultiply_by_two(x:int)->int:returnx*2

Custom metadata support for tools:

  • Added acustom_metadata field to all tool classes (FunctionTool,FileSearchTool,WebSearchTool,ComputerTool,HostedMCPTool,CodeInterpreterTool,ImageGenerationTool,LocalShellTool) insrc/agents/tool.py, allowing arbitrary metadata to be attached to each tool instance.[1][2][3][4][5][6][7][8]

Testing and validation:

  • Addedtests/test_tool_custom_metadata.py with tests to ensure thatcustom_metadata defaults toNone, can be set, and is available in agent hooks during tool execution.

chatgpt-codex-connector[bot] reacted with thumbs up emoji
Copy link

@chatgpt-codex-connectorchatgpt-codex-connectorbot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When yousign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@seratch
Copy link
Member

seratch commentedNov 6, 2025
edited
Loading

Thanks for sharing this idea! However, we'd like to hold off adding this option to the core module at this moment. Your current approach looks more explicit and it should work well. So, please start with your own module for now.

EDITED: sorry my original sentence was unclear

hayescode reacted with thumbs up emoji

@seratchseratch marked this pull request as draftNovember 6, 2025 01:13
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chatgpt-codex-connectorchatgpt-codex-connector[bot]chatgpt-codex-connector[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@hayescode@seratch

[8]ページ先頭

©2009-2025 Movatter.jp