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
feat: add autogen provider
angrybaybladec62f7cc733ef
diff --git a/python/composio/sdk.py b/python/composio/sdk.pyindex bcad29fda..165e051cf 100644--- a/python/composio/sdk.py+++ b/python/composio/sdk.py@@ -37,7 +37,6 @@ class Composio(t.Generic[TProvider], WithLogger):"""tools: Tools[TProvider]- provider: TProviderdef __init__(self,diff --git a/python/config/mypy.ini b/python/config/mypy.iniindex 0706bc071..3cb55f6ab 100644--- a/python/config/mypy.ini+++ b/python/config/mypy.ini@@ -21,3 +21,9 @@ ignore_missing_imports=true[mypy-proto.marshal.collections.maps]ignore_missing_imports=true++[mypy-autogen.*]+ignore_missing_imports=true++[mypy-autogen_core.*]+ignore_missing_imports=true\ No newline at end of filediff --git a/python/providers/autogen/README.md b/python/providers/autogen/README.mdnew file mode 100644index 000000000..55ee8bc5c--- /dev/null+++ b/python/providers/autogen/README.md@@ -0,0 +1,72 @@+## 🚀🔗 Integrating Composio with Google's Gemini SDK++Streamline the integration of Composio with Google AI Python to enhance the capabilities of Gemini models, allowing them to interact directly with external applications and expanding their operational scope.++### Objective++- **Automate starring a GitHub repository** using conversational instructions via Google AI Python's Function Calling feature.++### Installation and Setup++Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.++```bash+# Install Composio Gemini package+pip install composio-gemini++# Connect your GitHub account+composio add github++# View available applications you can connect with+composio apps+```++### Usage Steps++#### 1. Import Base Packages++Prepare your environment by initializing necessary imports from Google AI Python and setting up your client.++```python+from google import genai++# Create google client+client = genai.Client()+```++### Step 2: Integrating GitHub Tools with Composio++This step involves fetching and integrating GitHub tools provided by Composio, enabling enhanced functionality for Google AI Python operations.+```python+from google.genai import types++from composio_gemini import Action, ComposioToolSet++# Create composio client+toolset = ComposioToolSet()++# Create tools+tools = toolset.get_tools(+ actions=[+ Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,+ ]+)++# Create genai client config+config = types.GenerateContentConfig(+ tools=tools, # type: ignore+)+```++### Step 3: Agent Execution++This step involves configuring and executing the agent to carry out actions, such as starring a GitHub repository.++```python+# Use the chat interface.+chat = client.chats.create(model="gemini-2.0-flash", config=config)+response = chat.send_message(+ "Can you star composiohq/composio repository on github",+)+print(response.text)+```diff --git a/python/providers/autogen/autogen_demo.py b/python/providers/autogen/autogen_demo.pynew file mode 100644index 000000000..99d90f1e9--- /dev/null+++ b/python/providers/autogen/autogen_demo.py@@ -0,0 +1,60 @@+import os++import dotenv+from autogen import AssistantAgent, UserProxyAgent+from composio_autogen import AutogenProvider++from composio import Composio++# Load environment variables from .env+dotenv.load_dotenv()+++def is_termination_msg(content: dict) -> bool:+ """Check if a message contains termination message."""+ return "TERMINATE" in (content.get("content", "") or "")+++def main():+ # Initialize tools.+ chatbot = AssistantAgent(+ "chatbot",+ system_message="Reply TERMINATE when the task is done or when user's content is empty",+ llm_config={+ "config_list": [+ {"model": "gpt-4-turbo", "api_key": os.environ["OPENAI_API_KEY"]},+ ]+ },+ )++ # Create a user proxy agent+ user_proxy = UserProxyAgent(+ "user_proxy",+ is_termination_msg=is_termination_msg,+ human_input_mode="NEVER",+ code_execution_config={"use_docker": False},+ )++ # Get composio tools+ composio = Composio(provider=AutogenProvider())+ tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])++ # Register the preferred Applications, with right executor.+ composio.provider.register_tools(+ caller=chatbot,+ executor=user_proxy,+ tools=tools,+ )++ # Define task.+ task = "Star a repo composiohq/composio on GitHub"++ # Execute task.+ response = user_proxy.initiate_chat(chatbot, message=task)++ # Print response+ print(response.chat_history)+++if __name__ == "__main__":+ main()diff --git a/python/providers/autogen/composio_autogen/__init__.py b/python/providers/autogen/composio_autogen/__init__.pynew file mode 100644index 000000000..8c38eaefd--- /dev/null+++ b/python/providers/autogen/composio_autogen/__init__.py@@ -0,0 +1,3 @@+from .provider import AutogenProvider++__all__ = ("AutogenProvider",)diff --git a/python/providers/autogen/composio_autogen/provider.py b/python/providers/autogen/composio_autogen/provider.pynew file mode 100644index 000000000..2fe96b24e--- /dev/null+++ b/python/providers/autogen/composio_autogen/provider.py@@ -0,0 +1,104 @@+import hashlib+import types+import typing as t+from inspect import Signature++import autogen+from autogen.agentchat.conversable_agent import ConversableAgent+from autogen_core.tools import FunctionTool++from composio.client.types import Tool+from composio.core.provider import AgenticProvider+from composio.core.provider.agentic import AgenticProviderExecuteFn+from composio.utils.shared import get_signature_format_from_schema_params+++class AutogenProvider(+ AgenticProvider[FunctionTool, list[FunctionTool]],+ name="autogen",+):+ """+ Composio toolset for Autogen framework.+ """++ def _process_function_name_for_registration(+ self,+ input_string: str,+ max_allowed_length: int = 64,+ num_hash_char: int = 10,+ ):+ """+ Process function name for proxy registration under given character length limitation.+ """+ hash_hex = hashlib.sha256(input_string.encode(encoding="utf-8")).hexdigest()+ hash_chars_to_attach = hash_hex[:10]+ num_input_str_char = max_allowed_length - (num_hash_char + 1)+ input_str_to_attach = input_string[-num_input_str_char:]+ processed_name = input_str_to_attach + "_" + hash_chars_to_attach+ return processed_name++ def register_tools(+ self,+ caller: ConversableAgent,+ executor: ConversableAgent,+ tools: t.List[FunctionTool],+ ) -> None:+ """+ Register tools to the proxy agents.++ :param executor: Executor agent.+ :param caller: Caller agent.+ :param tools: List of tools to register.+ """+ for tool in tools:+ autogen.agentchat.register_function(+ f=tool._func,+ caller=caller,+ executor=executor,+ name=tool.name,+ description=tool.description,+ )++ def wrap_tool(+ self,+ tool: Tool,+ execute_tool: AgenticProviderExecuteFn,+ ) -> FunctionTool:+ """Wraps a composio tool as an Autogen FunctionTool."""++ def execute_action(**kwargs: t.Any) -> t.Dict:+ """Placeholder function for executing action."""+ return execute_tool(slug=tool.slug, arguments=kwargs)++ # Create function with proper signature+ function = types.FunctionType(+ code=execute_action.__code__,+ globals=globals(),+ closure=execute_action.__closure__,+ name=self._process_function_name_for_registration(input_string=tool.slug),+ )++ # Set signature and annotations+ params = get_signature_format_from_schema_params(+ schema_params=tool.input_parameters,+ )+ function.__doc__ = tool.description+ setattr(function, "__signature__", Signature(parameters=params))+ setattr(+ function,+ "__annotations__",+ {p.name: p.annotation for p in params} | {"return": t.Dict[str, t.Any]},+ )+ return FunctionTool(+ func=function,+ description=tool.description,+ name=self._process_function_name_for_registration(input_string=tool.slug),+ )++ def wrap_tools(+ self,+ tools: t.Sequence[Tool],+ execute_tool: AgenticProviderExecuteFn,+ ) -> list[FunctionTool]:+ """Wraps array of composio tools as an Autogen FunctionTool."""+ return [self.wrap_tool(tool=tool, execute_tool=execute_tool) for tool in tools]diff --git a/python/providers/autogen/composio_autogen/py.typed b/python/providers/autogen/composio_autogen/py.typednew file mode 100644index 000000000..e69de29bbdiff --git a/python/providers/autogen/pyproject.toml b/python/providers/autogen/pyproject.tomlnew file mode 100644index 000000000..6123458e3--- /dev/null+++ b/python/providers/autogen/pyproject.toml@@ -0,0 +1,23 @@+[project]+name = "composio-autogen"+version = "1.0.0-rc6"+description = "Use Composio to get an array of tools with your autogen agent."+readme = "README.md"+requires-python = ">=3.9,<4"+authors = [+ { name = "Composio", email = "[email protected]" }+]+classifiers = [+ "Programming Language :: Python :: 3",+ "License :: OSI Approved :: Apache Software License",+ "Operating System :: OS Independent",+]+dependencies = [+ "pyautogen>=0.2.19",+ "flaml==2.2.0",+ "autogen_core>=0.4.0",+ "autogen_agentchat>=0.4.0"+]++[project.urls]+Homepage = "https://github.com/ComposioHQ/composio"diff --git a/python/providers/autogen/setup.py b/python/providers/autogen/setup.pynew file mode 100644index 000000000..4622d8f44--- /dev/null+++ b/python/providers/autogen/setup.py@@ -0,0 +1,31 @@+"""+Setup configuration for Composio Gemin plugin+"""++from pathlib import Path++from setuptools import setup++setup(+ name="composio_autogen",+ version="1.0.0-rc6",+ author="Composio",+ author_email="[email protected]",+ description="Use Composio to get an array of tools with your Autogen agent.",+ long_description=(Path(__file__).parent / "README.md").read_text(encoding="utf-8"),+ long_description_content_type="text/markdown",+ url="https://github.com/ComposioHQ/composio",+ classifiers=[+ "Programming Language :: Python :: 3",+ "License :: OSI Approved :: Apache Software License",+ "Operating System :: OS Independent",+ ],+ python_requires=">=3.9,<4",+ install_requires=[+ "pyautogen>=0.2.19",+ "flaml==2.2.0",+ "autogen_core>=0.4.0",+ "autogen_agentchat>=0.4.0",+ ],+ include_package_data=True,+)