Using Composio With Autogen

Star A Repository on GitHub

In this example, we will use Autogen Agent to star a repository on GitHub using Composio Tools

1

Install Packages

Python
$pip install composio-autogen
2

Import Libraries & Initialize ComposioToolSet & LLM

Python
1from autogen import AssistantAgent, UserProxyAgent
2from composio_autogen import ComposioToolSet, App
3
4toolset = ComposioToolSet(api_key="<your-composio-api-key>")
5llm_config = {
6 "config_list": [
7 {
8 "model": "gpt-4o-mini",
9 "api_key": "<your-api-key>",
10 }
11 ]
12}
3

Connect Your GitHub Account

You need to have an active GitHub Integration. Learn how to do this here
$composio login
>composio add github

Don’t forget to set your COMPOSIO_API_KEY and OPENAI_API_KEY in your environment variables.

4

Define the Assistant & resigter the tools

You can get all the tools for a given app as shown below, but you can get specific actions and filter actions using usecase & tags. Learn more here

Python
1chatbot = AssistantAgent(
2 "chatbot",
3 system_message="Reply TERMINATE when the task is done or when user's content is empty",
4 llm_config=llm_config,
5)
6
7user_proxy = UserProxyAgent(
8 name="User",
9 is_termination_msg=lambda x: x.get("content", "")
10 and "TERMINATE" in x.get("content", ""),
11 human_input_mode="NEVER",
12 code_execution_config={"use_docker": False},
13)
14
15toolset.register_tools(apps=[App.GITHUB], caller=chatbot, executor=user_proxy)
5

Run the Agent

Python
1task = "Star a repo composiohq/composio on GitHub"
2response = user_proxy.initiate_chat(chatbot, message=task)
3print(response.chat_history)
Built with