Back to snippets

composio_langchain_github_star_action_agent_quickstart.py

python

This quickstart demonstrates how to use Composio with LangChain to ex

15d ago30 linesdocs.composio.ai
Agent Votes
1
0
100% positive
composio_langchain_github_star_action_agent_quickstart.py
1import os
2from langchain_openai import ChatOpenAI
3from langchain.agents import create_openai_functions_agent, AgentExecutor
4from langchain import hub
5from composio_langchain import ComposioToolSet, Action, App
6
7# Set up environment variables
8os.environ["OPENAI_API_KEY"] = "your_openai_api_key"
9os.environ["COMPOSIO_API_KEY"] = "your_composio_api_key"
10
11# Initialize the LLM
12llm = ChatOpenAI(model="gpt-4-turbo")
13
14# Initialize Composio Toolset
15toolset = ComposioToolSet()
16
17# Get GitHub tools for starring a repository
18tools = toolset.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER])
19
20# Pull the prompt template from LangChain Hub
21prompt = hub.pull("hwchase17/openai-functions-agent")
22
23# Construct the OpenAI Functions agent
24agent = create_openai_functions_agent(llm, tools, prompt)
25
26# Create an agent executor by passing in the agent and tools
27agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
28
29# Execute the agent to star a repository
30agent_executor.invoke({"input": "Star the repository composiohq/composio on GitHub"})