πŸ¦™ Using Composio With LlamaIndex

Star A Repository on Github

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

1

Install Packages

$pip install composio-llamaindex llama-index
2

Import Libraries & Initialize ComposioToolSet & LLM

1from llama_index.llms.openai import OpenAI
2from llama_index.core.llms import ChatMessage
3from llama_index.core.agent import FunctionCallingAgentWorker
4from composio_llamaindex import App, ComposioToolSet
5
6toolset = ComposioToolSet()
7llm = OpenAI()
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

1tools = toolset.get_tools(apps=[App.GITHUB])
5

Define the Agent

1prefix_messages = [
2 ChatMessage(
3 role="system",
4 content=(
5 "You are a Github Agent, and you can use tools to perform actions on Github."
6 ),
7 )
8]
9
10agent = FunctionCallingAgentWorker(
11 tools=tools,
12 llm=llm,
13 prefix_messages=prefix_messages,
14 max_function_calls=10,
15 allow_parallel_tool_calls=False,
16 verbose=True,
17).as_agent()
6

Execute the Agent

1result = agent.chat("Star a repo composiohq/composio on GitHub")
Built with