Skip to main content

Star A Repository on GitHub

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

Install Packages

pip install composio-langchain langchain_openai
2

Import Libraries & Initialize ComposioToolSet & LLM

from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain import hub
from langchain_openai import ChatOpenAI
from composio_langchain import ComposioToolSet, App

llm = ChatOpenAI()
composio_toolset = ComposioToolSet()
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
tools = composio_toolset.get_tools(apps=[App.GITHUB])
5

Define the Agent

prompt = hub.pull("hwchase17/openai-functions-agent")
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
6

Execute the Agent

task = "Star a repo composiohq/composio on GitHub"
agent_executor.invoke({"input": task})