function_tool on a callable object uses an inherited or generated class docstring as the tool description
メンテナーはふだん 1 日以内に返信
@Narendra02053 がすでに取り組んでいます。
2026年10月27日 から。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
- 領域
- ai, backend-api-design
調査の方向性
Start with _normalize_function_tool_callable in src/agents/tool.py and generate_func_documentation in src/agents/function_schema.py; inspect how both obtain class docstrings and review test_callable_object_uses_call_docstring_when_class_docstring_missing in tests/test_function_tool_decorator.py. Add regression coverage for inherited stdlib and generated dataclass or NamedTuple docstrings, plus documented user base classes. Done when callable tool descriptions and summaries use the intended __call__ or user-written class documentation across those cases.
索引モデルが issue の本文から書いたものです。
説明
Please read this first
- Have you read the docs? Yes
- Have you searched for related issues? Yes. Callable-object tools and
_normalize_function_tool_callablecame from #3949. I didn't find anything about where a callable tool's class docstring comes from.
Describe the bug
For a callable object, _normalize_function_tool_callable reads the class docstring with inspect.getdoc(type(func)) (tool.py#L2609). When the class has no docstring of its own, inspect.getdoc falls back to the first base class that has one, and @dataclass and NamedTuple store generated text as __doc__. That text then takes priority over the __call__ docstring, so the description sent to the model is wrong:
- a tool class whose undocumented abstract base derives from
ABCgets the stdlib text "Helper class that provides a standard way to create an ABC using inheritance." (an undocumentedtyping.Genericortyping.Protocolbase does the same with those classes' docstrings) - a
@dataclassgets its constructor signature, including default values such as an internal base URL - a
NamedTuplegets'NamedTupleLookup(region,)'
A plain class with only a __call__ docstring works, which is what test_callable_object_uses_call_docstring_when_class_docstring_missing in tests/test_function_tool_decorator.py covers.
Debug information
- Agents SDK version: 0.24.0, and current
main(b040da59) - Related library versions: none
- Python version: 3.12.7, plus 3.10.4 and 3.14.6 with the 0.24.0 wheel, same output
- Operating system: macOS 26.6.2
- Model and model provider: none needed, the description is wrong before any request is sent
- Does the issue reproduce with the latest Agents SDK release? Yes
- Does the issue occur consistently or intermittently? Consistently
WeatherLookup 'Helper class that provides a standard way to create an ABC using\ninheritance.'
DataclassLookup "DataclassLookup(base_url: str = 'https://weather.internal.example', units: str = 'metric')"
NamedTupleLookup 'NamedTupleLookup(region,)'
Configured 'Look up the weather.'
Repro steps
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import NamedTuple
from agents import function_tool
class WeatherTool(ABC):
@abstractmethod
async def __call__(self, city: str) -> str: ...
class WeatherLookup(WeatherTool):
async def __call__(self, city: str) -> str:
"""Return the current weather for a city."""
return f"sunny in {city}"
@dataclass
class DataclassLookup:
base_url: str = "https://weather.internal.example"
units: str = "metric"
async def __call__(self, city: str) -> str:
"""Return the current weather for a city."""
return f"sunny in {city}"
class NamedTupleLookup(NamedTuple):
region: str = "us-east-1"
async def __call__(self, city: str) -> str:
"""Return the current weather for a city."""
return f"sunny in {city}"
class DocumentedBase:
"""Look up the weather.
Args:
city: The city to look up.
"""
async def __call__(self, city: str) -> str:
return f"sunny in {city}"
class Configured(DocumentedBase):
pass
for obj in (WeatherLookup(), DataclassLookup(), NamedTupleLookup(), Configured()):
print(f"{type(obj).__name__:17} {function_tool(obj).description!r}")
Expected behavior
The first three get 'Return the current weather for a city.'. The docstrings that stdlib bases like ABC, Generic and Protocol carry, and the text @dataclass and NamedTuple generate, weren't written for the tool and shouldn't become its description. Docstrings from the user's own classes should keep working as they do today, as Configured shows.
Suggested fix
Keep finding the class docstring through the MRO the way inspect.getdoc does, but skip two kinds of text: the docstrings of stdlib bases such as abc.ABC, typing.Generic and typing.Protocol, and text that @dataclass or NamedTuple generated. Generated text sits in the class's own __dict__ next to __dataclass_fields__ or _fields, and it starts with ClassName( (or is just ClassName when dataclasses can't build a signature on 3.11+), so a prefix check is enough. Rebuilding the string with inspect.signature(cls) doesn't reliably match on 3.14, which renders annotations with annotation_format=FORWARDREF. Docstrings from the user's own base classes and mixins would keep being used, as today.
The class summary needs the same source. When both docstrings exist, the description comes from generate_func_documentation(type(func), ...) at L2613, which calls inspect.getdoc again (function_schema.py#L260). For example, a @dataclass subclass of a documented base whose __call__ has a docstring gets "ConfiguredDataclass(units: str = 'metric')" as its description, and changing only L2609 wouldn't fix that.
- 主要言語
- Python
- スター
- 30.4k
- フォーク
- 4.9k
- 平均マージ
- 12時間 50分
- マージ済み PR(30日)
- 162
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-agents-python のほかの issue
-
fix(typing): explicitly specialize ToolContext[Any] in ToolFunctionWithToolContext再び着手できるかも @AbarnaaSree が 10 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
openai/openai-agents-python#5387 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
openai/openai-agents-python#5441 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 44/100
openai/openai-agents-python#5416 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 53/100
openai/openai-agents-python#5413 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
openai/openai-agents-python#5412 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
openai/openai-agents-python の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
521xueweihan/HelloGitHub#4150 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
aws-samples/sample-per-model-bedrock#595 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
bug connectors
難易度 1/5 1時間未満 初心者へのやさしさ 67/100
pyinfra-dev/pyinfra#2036 ·
メンテナーはふだん 9 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信