Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(python): use inspect.cleandoc for docstring inference + add tests
Dhawal Upadhyayb39a10291503
diff --git a/python/composio/core/models/custom_tool.py b/python/composio/core/models/custom_tool.pyindex d1cc41b69..c03a290dd 100644--- a/python/composio/core/models/custom_tool.py+++ b/python/composio/core/models/custom_tool.py@@ -240,7 +240,7 @@ def _infer_tool_from_function(# Infer slugactual_slug = slug or fn.__name__.upper()actual_name = name or fn.__name__.replace("_", " ").title()- actual_description = description or (fn.__doc__ or "").strip()+ actual_description = description or inspect.cleandoc(fn.__doc__ or "")if not actual_description:raise ValidationError(diff --git a/python/tests/test_custom_tools.py b/python/tests/test_custom_tools.pyindex 0a6ab2d36..4c7c815aa 100644--- a/python/tests/test_custom_tools.py+++ b/python/tests/test_custom_tools.py@@ -166,6 +166,36 @@ class TestDecoratorTool:assert my_func.description == "Trimmed docstring."+ def test_multiline_docstring(self):+ @exp.tool()+ def multi(input: GrepInput, ctx):+ """Search for users by email.++ This tool searches the internal database for users+ matching the given pattern. Returns a list of matches.++ Supports wildcards.+ """+ return {}++ assert multi.description.startswith("Search for users by email.")+ # inspect.cleandoc strips indentation+ assert "\n " not in multi.description+ assert "Supports wildcards." in multi.description++ def test_indented_docstring_cleaned(self):+ @exp.tool()+ def indented(input: GrepInput, ctx):+ """+ Leading and trailing whitespace removed.+ Indentation normalized.+ """+ return {}++ assert indented.description == (+ "Leading and trailing whitespace removed.\nIndentation normalized."+ )+def test_missing_docstring_raises(self):with pytest.raises(ValidationError, match="description is required"):