The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): google docstring parsing with no arguments/reserved arguments (#34861)
Louis Auneauf5252b438e57
diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.pyindex c80f43cfd9..944b552d16 100644--- a/libs/core/langchain_core/utils/function_calling.py+++ b/libs/core/langchain_core/utils/function_calling.py@@ -718,12 +718,22 @@ def _parse_google_docstring(Assumes the function docstring follows Google Python style guide.+ Args:+ docstring: The docstring to parse.+ args: The list of argument names to extract descriptions for.+ error_on_invalid_docstring: Whether to raise an error if the docstring is+ invalid.++ Returns:+ A tuple of the function description and a dictionary of argument descriptions."""if docstring:docstring_blocks = docstring.split("\n\n")if error_on_invalid_docstring:filtered_annotations = {- arg for arg in args if arg not in {"run_manager", "callbacks", "return"}+ arg+ for arg in args+ if arg not in {"run_manager", "callbacks", "runtime", "return"}}if filtered_annotations and (len(docstring_blocks) < _MIN_DOCSTRING_BLOCKS@@ -745,7 +755,7 @@ def _parse_google_docstring(descriptors.append(block)else:continue- description = " ".join(descriptors)+ description = " ".join(descriptors).strip()else:if error_on_invalid_docstring:msg = "Found invalid Google-Style docstring."diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.pyindex 649923296d..0c49cfbef5 100644--- a/libs/core/tests/unit_tests/test_tools.py+++ b/libs/core/tests/unit_tests/test_tools.py@@ -1244,6 +1244,18 @@ def test_tool_arg_descriptions() -> None:assert args_schema["description"] == expected["description"]assert args_schema["properties"] == expected["properties"]+ # Test parsing with runtime does not raise error+ def foo3_runtime(bar: str, baz: int, runtime: Any) -> str: # noqa: D417+ """The foo.++ Args:+ bar: The bar.+ baz: The baz.+ """+ return bar++ _ = tool(foo3_runtime, parse_docstring=True)+# Test parameterless tool does not raise error for missing Args section# in docstring.def foo4() -> str: