Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 23:15 UTC
feat: add autogen provider
angrybayblade committed
Jun 30, 2025 at 15:13 UTC
c62f7cc733ef3db04ff5e5d196dcbbb0a2d21b38
9 files changed
+299
-1
python/composio/sdk.py
-1
@@ -37,7 +37,6 @@ class Composio(t.Generic[TProvider], WithLogger):
37
"""
38
39
tools: Tools[TProvider]
40
- provider: TProvider
40
41
def __init__(
42
self,
python/config/mypy.ini
+6
@@ -21,3 +21,9 @@ ignore_missing_imports=true
21
22
[mypy-proto.marshal.collections.maps]
23
ignore_missing_imports=true
24
+
25
+[mypy-autogen.*]
26
+ignore_missing_imports=true
27
+
28
+[mypy-autogen_core.*]
29
+ignore_missing_imports=true
\ No newline at end of file
python/providers/autogen/README.md
new
+72
@@ -0,0 +1,72 @@
1
+## 🚀🔗 Integrating Composio with Google's Gemini SDK
2
+
3
+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.
4
+
5
+### Objective
6
+
7
+- **Automate starring a GitHub repository** using conversational instructions via Google AI Python's Function Calling feature.
8
+
9
+### Installation and Setup
10
+
11
+Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
12
+
13
+```bash
14
+# Install Composio Gemini package
15
+pip install composio-gemini
16
+
17
+# Connect your GitHub account
18
+composio add github
19
+
20
+# View available applications you can connect with
21
+composio apps
22
+```
23
+
24
+### Usage Steps
25
+
26
+#### 1. Import Base Packages
27
+
28
+Prepare your environment by initializing necessary imports from Google AI Python and setting up your client.
29
+
30
+```python
31
+from google import genai
32
+
33
+# Create google client
34
+client = genai.Client()
35
+```
36
+
37
+### Step 2: Integrating GitHub Tools with Composio
38
+
39
+This step involves fetching and integrating GitHub tools provided by Composio, enabling enhanced functionality for Google AI Python operations.
40
+```python
41
+from google.genai import types
42
+
43
+from composio_gemini import Action, ComposioToolSet
44
+
45
+# Create composio client
46
+toolset = ComposioToolSet()
47
+
48
+# Create tools
49
+tools = toolset.get_tools(
50
+ actions=[
51
+ Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
52
+ ]
53
+)
54
+
55
+# Create genai client config
56
+config = types.GenerateContentConfig(
57
+ tools=tools, # type: ignore
58
+)
59
+```
60
+
61
+### Step 3: Agent Execution
62
+
63
+This step involves configuring and executing the agent to carry out actions, such as starring a GitHub repository.
64
+
65
+```python
66
+# Use the chat interface.
67
+chat = client.chats.create(model="gemini-2.0-flash", config=config)
68
+response = chat.send_message(
69
+ "Can you star composiohq/composio repository on github",
70
+)
71
+print(response.text)
72
+```
python/providers/autogen/autogen_demo.py
new
+60
@@ -0,0 +1,60 @@
1
+import os
2
+
3
+import dotenv
4
+from autogen import AssistantAgent, UserProxyAgent
5
+from composio_autogen import AutogenProvider
6
+
7
+from composio import Composio
8
+
9
+# Load environment variables from .env
10
+dotenv.load_dotenv()
11
+
12
+
13
+def is_termination_msg(content: dict) -> bool:
14
+ """Check if a message contains termination message."""
15
+ return "TERMINATE" in (content.get("content", "") or "")
16
+
17
+
18
+def main():
19
+ # Initialize tools.
20
+ chatbot = AssistantAgent(
21
+ "chatbot",
22
+ system_message="Reply TERMINATE when the task is done or when user's content is empty",
23
+ llm_config={
24
+ "config_list": [
25
+ {"model": "gpt-4-turbo", "api_key": os.environ["OPENAI_API_KEY"]},
26
+ ]
27
+ },
28
+ )
29
+
30
+ # Create a user proxy agent
31
+ user_proxy = UserProxyAgent(
32
+ "user_proxy",
33
+ is_termination_msg=is_termination_msg,
34
+ human_input_mode="NEVER",
35
+ code_execution_config={"use_docker": False},
36
+ )
37
+
38
+ # Get composio tools
39
+ composio = Composio(provider=AutogenProvider())
40
+ tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])
41
+
42
+ # Register the preferred Applications, with right executor.
43
+ composio.provider.register_tools(
44
+ caller=chatbot,
45
+ executor=user_proxy,
46
+ tools=tools,
47
+ )
48
+
49
+ # Define task.
50
+ task = "Star a repo composiohq/composio on GitHub"
51
+
52
+ # Execute task.
53
+ response = user_proxy.initiate_chat(chatbot, message=task)
54
+
55
+ # Print response
56
+ print(response.chat_history)
57
+
58
+
59
+if __name__ == "__main__":
60
+ main()
python/providers/autogen/composio_autogen/__init__.py
new
+3
@@ -0,0 +1,3 @@
1
+from .provider import AutogenProvider
2
+
3
+__all__ = ("AutogenProvider",)
python/providers/autogen/composio_autogen/provider.py
new
+104
@@ -0,0 +1,104 @@
1
+import hashlib
2
+import types
3
+import typing as t
4
+from inspect import Signature
5
+
6
+import autogen
7
+from autogen.agentchat.conversable_agent import ConversableAgent
8
+from autogen_core.tools import FunctionTool
9
+
10
+from composio.client.types import Tool
11
+from composio.core.provider import AgenticProvider
12
+from composio.core.provider.agentic import AgenticProviderExecuteFn
13
+from composio.utils.shared import get_signature_format_from_schema_params
14
+
15
+
16
+class AutogenProvider(
17
+ AgenticProvider[FunctionTool, list[FunctionTool]],
18
+ name="autogen",
19
+):
20
+ """
21
+ Composio toolset for Autogen framework.
22
+ """
23
+
24
+ def _process_function_name_for_registration(
25
+ self,
26
+ input_string: str,
27
+ max_allowed_length: int = 64,
28
+ num_hash_char: int = 10,
29
+ ):
30
+ """
31
+ Process function name for proxy registration under given character length limitation.
32
+ """
33
+ hash_hex = hashlib.sha256(input_string.encode(encoding="utf-8")).hexdigest()
34
+ hash_chars_to_attach = hash_hex[:10]
35
+ num_input_str_char = max_allowed_length - (num_hash_char + 1)
36
+ input_str_to_attach = input_string[-num_input_str_char:]
37
+ processed_name = input_str_to_attach + "_" + hash_chars_to_attach
38
+ return processed_name
39
+
40
+ def register_tools(
41
+ self,
42
+ caller: ConversableAgent,
43
+ executor: ConversableAgent,
44
+ tools: t.List[FunctionTool],
45
+ ) -> None:
46
+ """
47
+ Register tools to the proxy agents.
48
+
49
+ :param executor: Executor agent.
50
+ :param caller: Caller agent.
51
+ :param tools: List of tools to register.
52
+ """
53
+ for tool in tools:
54
+ autogen.agentchat.register_function(
55
+ f=tool._func,
56
+ caller=caller,
57
+ executor=executor,
58
+ name=tool.name,
59
+ description=tool.description,
60
+ )
61
+
62
+ def wrap_tool(
63
+ self,
64
+ tool: Tool,
65
+ execute_tool: AgenticProviderExecuteFn,
66
+ ) -> FunctionTool:
67
+ """Wraps a composio tool as an Autogen FunctionTool."""
68
+
69
+ def execute_action(**kwargs: t.Any) -> t.Dict:
70
+ """Placeholder function for executing action."""
71
+ return execute_tool(slug=tool.slug, arguments=kwargs)
72
+
73
+ # Create function with proper signature
74
+ function = types.FunctionType(
75
+ code=execute_action.__code__,
76
+ globals=globals(),
77
+ closure=execute_action.__closure__,
78
+ name=self._process_function_name_for_registration(input_string=tool.slug),
79
+ )
80
+
81
+ # Set signature and annotations
82
+ params = get_signature_format_from_schema_params(
83
+ schema_params=tool.input_parameters,
84
+ )
85
+ function.__doc__ = tool.description
86
+ setattr(function, "__signature__", Signature(parameters=params))
87
+ setattr(
88
+ function,
89
+ "__annotations__",
90
+ {p.name: p.annotation for p in params} | {"return": t.Dict[str, t.Any]},
91
+ )
92
+ return FunctionTool(
93
+ func=function,
94
+ description=tool.description,
95
+ name=self._process_function_name_for_registration(input_string=tool.slug),
96
+ )
97
+
98
+ def wrap_tools(
99
+ self,
100
+ tools: t.Sequence[Tool],
101
+ execute_tool: AgenticProviderExecuteFn,
102
+ ) -> list[FunctionTool]:
103
+ """Wraps array of composio tools as an Autogen FunctionTool."""
104
+ return [self.wrap_tool(tool=tool, execute_tool=execute_tool) for tool in tools]
python/providers/autogen/composio_autogen/py.typed
python/providers/autogen/pyproject.toml
new
+23
@@ -0,0 +1,23 @@
1
+[project]
2
+name = "composio-autogen"
3
+version = "1.0.0-rc6"
4
+description = "Use Composio to get an array of tools with your autogen agent."
5
+readme = "README.md"
6
+requires-python = ">=3.9,<4"
7
+authors = [
8
+ { name = "Composio", email = "tech@composio.dev" }
9
+]
10
+classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: Apache Software License",
13
+ "Operating System :: OS Independent",
14
+]
15
+dependencies = [
16
+ "pyautogen>=0.2.19",
17
+ "flaml==2.2.0",
18
+ "autogen_core>=0.4.0",
19
+ "autogen_agentchat>=0.4.0"
20
+]
21
+
22
+[project.urls]
23
+Homepage = "https://github.com/ComposioHQ/composio"
python/providers/autogen/setup.py
new
+31
@@ -0,0 +1,31 @@
1
+"""
2
+Setup configuration for Composio Gemin plugin
3
+"""
4
+
5
+from pathlib import Path
6
+
7
+from setuptools import setup
8
+
9
+setup(
10
+ name="composio_autogen",
11
+ version="1.0.0-rc6",
12
+ author="Composio",
13
+ author_email="tech@composio.dev",
14
+ description="Use Composio to get an array of tools with your Autogen agent.",
15
+ long_description=(Path(__file__).parent / "README.md").read_text(encoding="utf-8"),
16
+ long_description_content_type="text/markdown",
17
+ url="https://github.com/ComposioHQ/composio",
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: Apache Software License",
21
+ "Operating System :: OS Independent",
22
+ ],
23
+ python_requires=">=3.9,<4",
24
+ install_requires=[
25
+ "pyautogen>=0.2.19",
26
+ "flaml==2.2.0",
27
+ "autogen_core>=0.4.0",
28
+ "autogen_agentchat>=0.4.0",
29
+ ],
30
+ include_package_data=True,
31
+)