Using Composio With CrewAI

Star A Repository on GitHub

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

1

Install Packages

Python
$pip install composio_crewai crewai langchain_openai
2

Import Libraries & Initialize ComposioToolSet & LLM

Python
$from composio_crewai import ComposioToolSet, App
>from crewai import Agent, Task, Crew
>from langchain_openai import ChatOpenAI
>
>toolset = ComposioToolSet(api_key="<your-composio-api-key>")
>llm = ChatOpenAI(api_key="<your-openai-api-key>")
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

Get All GitHub 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
1tools = toolset.get_tools(apps=[App.GITHUB])
5

Define the Agent, Task & Crew

Python
1crewai_agent = Agent(
2 role="GitHub Agent",
3 goal="You take action on GitHub using GitHub APIs",
4 backstory="You are AI agent that is responsible for taking actions on GitHub on behalf of users using GitHub APIs",
5 verbose=True,
6 tools=tools,
7 llm=llm,
8)
9
10task = Task(
11 description="Star a repo composiohq/composio on GitHub",
12 agent=crewai_agent,
13 expected_output="Status of the operation"
14)
15
16crew = Crew(
17 agents = [crewai_agent],
18 tasks = [task]
19)
6

Crew Kickoff

Python
1result = crew.kickoff()
2print(result)
Built with