Skip to content

Commit a726a9c

Browse files
fix: Preserve parameter descriptions in Args-only docstrings (#5302)
1 parent d27abe8 commit a726a9c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/agents/function_schema.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ def generate_func_documentation(
267267
doc = _ensure_blank_line_before_google_sections(doc)
268268

269269
with _suppress_griffe_logging():
270-
docstring = Docstring(doc, lineno=1, parser=resolved_style)
270+
# Griffe runs cleandoc again. A leading newline keeps the already-cleaned first
271+
# line in its indentation calculation, preserving an initial Args: section's body.
272+
docstring = Docstring("\n" + doc, lineno=1, parser=resolved_style)
271273
parsed = docstring.parse()
272274

273275
description: str | None = next(

‎tests/test_function_schema.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,25 @@ def weather(city: str, units: str) -> str:
11671167
assert "Args:" not in (weather.description or "")
11681168

11691169

1170+
@pytest.mark.parametrize("style", [None, "google"])
1171+
def test_google_docstring_without_summary(style):
1172+
def weather(city: str, units: str) -> str:
1173+
"""
1174+
Args:
1175+
city: The city to get
1176+
weather for.
1177+
units: Temperature units to use.
1178+
"""
1179+
return f"{city} {units}"
1180+
1181+
weather_tool = tool(weather, docstring_style=style)
1182+
properties = weather_tool.params_json_schema["properties"]
1183+
assert properties["city"]["description"] == "The city to get\nweather for."
1184+
assert properties["units"]["description"] == "Temperature units to use."
1185+
assert weather_tool.description == ""
1186+
assert function_schema(weather, docstring_style=style).description is None
1187+
1188+
11701189
def section_body_before_args_google_function(city: str, units: str):
11711190
"""Get the weather for a city.
11721191

0 commit comments

Comments
 (0)