Use Composio to get an array of tools with your LangChain agent.
Project description
🦜🔗 Using Composio With LangChain
Integrate Composio with LangChain agents to allow them to interact seamlessly with external apps, enhancing their functionality and reach.
Goal
- Star a repository on GitHub using natural language commands through a LangChain Agent.
Installation and Setup
Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
# Install Composio LangChain package
pip install composio-langchain
# Connect your GitHub account
composio-cli add github
# View available applications you can connect with
composio-cli show-apps
Usage Steps
1. Import Base Packages
Prepare your environment by initializing necessary imports from LangChain and setting up your agent.
from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain import hub
from langchain_openai import ChatOpenAI
# Initialize LangChain OpenAI Chat
llm = ChatOpenAI()
# Pull the agent prompt configuration
prompt = hub.pull("hwchase17/openai-functions-agent")
2. Fetch GitHub LangChain Tools via Composio
Access GitHub tools provided by Composio for LangChain.
from composio_langchain import ComposioToolset, Action, App
# Initialize the toolset for GitHub
tools = ComposioToolset(apps=[App.GITHUB])
3. Execute the Agent
Configure and execute the agent to perform tasks such as starring a repository on GitHub.
task = "Star a repo SamparkAI/docs on GitHub"
# Create and set up the agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Execute the task
agent_executor.invoke({"input": task})
4. Check Response
Validate the execution and response from the agent to ensure the task was completed successfully.
> Entering new AgentExecutor chain...
> Invoking: `github_star_repo` with `{'owner': 'SamparkAI', 'repo': 'docs'}`
> {'execution_details': {'executed': True}, 'response_data': ''}
> I have successfully starred the repository SamparkAI/docs on GitHub.
Advanced Configuration
- Filter Specific Actions: Limit the actions an agent can execute.
# Filter to only allow creating issues on GitHub
toolsGithubCreateIssue = ComposioToolset(actions=[Action.GITHUB_CREATE_ISSUE])
- Filter Specific Apps: Restrict the tools an agent can use.
# Allow usage of Asana and GitHub only
toolsAsanaGithub = ComposioToolset(apps=[App.ASANA, App.GITHUB])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for composio_langchain-0.3.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75c7e0b8a6fc43ad8ca18b64d9587bff7c9bb4d384c9450ba2b25ec100740216 |
|
MD5 | 6347b59871e110e5b169add88e92871f |
|
BLAKE2b-256 | 9ed7c8c703ba427d3f3d2781bfbf1fc0866cdfb0119b753996ebb8e45f77b2f7 |
Hashes for composio_langchain-0.3.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec868889f147784532298ea75268bf84215a84c3a58f16a9f9313a68c3ca9103 |
|
MD5 | 66783c3a1b70328804fd3b2a49fe8a78 |
|
BLAKE2b-256 | c9550e4a324efb2e3dcf531a29b152cb44720ba63476e6f01e8fd183f9ccf4dd |