πŸ¦œπŸ”— Using Composio With LangChain

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

1from langchain.agents import create_openai_functions_agent, AgentExecutor
2from langchain import hub
3from langchain_openai import ChatOpenAI
4from composio_langchain import ComposioToolSet, App
5
6llm = ChatOpenAI()
7composio_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

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

Define the Agent

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

Execute the Agent

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