Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
md 67 lines 2.24 KB
Rendered Raw
1 # composio-autogen
2
3 Adapts Composio tools to AutoGen `FunctionTool` objects and registers them with your caller and executor agents, so your AutoGen agents can take action across 1000+ apps.
4
5 ## Installation
6
7 ```bash
8 pip install composio composio-autogen 'ag2[openai]'
9 ```
10
11 Set `COMPOSIO_API_KEY` (from the [dashboard](https://dashboard.composio.dev/settings)) and `OPENAI_API_KEY` in your environment.
12
13 ## Quickstart
14
15 ```python
16 import os
17
18 from autogen import AssistantAgent, LLMConfig, UserProxyAgent
19 from composio import Composio
20 from composio_autogen import AutogenProvider
21
22 composio = Composio(provider=AutogenProvider())
23
24 # Each session is scoped to one of your users
25 session = composio.create(user_id="user_123")
26 tools = session.tools()
27
28 chatbot = AssistantAgent(
29 "chatbot",
30 system_message="Reply TERMINATE when the task is done or when user's content is empty",
31 llm_config=LLMConfig({
32 "api_type": "openai",
33 "model": "gpt-5.2",
34 "api_key": os.environ["OPENAI_API_KEY"],
35 }),
36 )
37
38 user_proxy = UserProxyAgent(
39 "user_proxy",
40 is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content", "") or ""),
41 human_input_mode="NEVER",
42 code_execution_config={"use_docker": False},
43 )
44
45 # Register tools with both agents
46 composio.provider.register_tools(caller=chatbot, executor=user_proxy, tools=tools)
47
48 response = user_proxy.initiate_chat(
49 chatbot,
50 message="Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'",
51 )
52
53 print(response.chat_history)
54 ```
55
56 For multi-turn use, store `session.session_id` and reuse it with `composio.use(session_id)` instead of calling `create()` again.
57
58 ## Provider specifics
59
60 AutoGen needs tools registered with two agents, not passed once. Call `composio.provider.register_tools(caller=..., executor=..., tools=tools)`: the `caller` decides which tool to invoke, and the `executor` runs it. This method is unique to the AutoGen provider.
61
62 AutoGen caps function names at 64 characters, so the provider hashes and truncates long tool slugs to stay under the limit. The registered name will not always match the original Composio slug.
63
64 ## Links
65
66 - [AutoGen provider docs](https://docs.composio.dev/docs/providers/autogen)
67 - [Composio documentation](https://docs.composio.dev)