Skip to main content

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 composiohq/composio 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': 'composiohq', 'repo': 'composio'}`
> {'execution_details': {'executed': True}, 'response_data': ''}
> I have successfully starred the repository composiohq/composio 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

composio_langchain-0.5.36.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

composio_langchain-0.5.36-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file composio_langchain-0.5.36.tar.gz.

File metadata

  • Download URL: composio_langchain-0.5.36.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for composio_langchain-0.5.36.tar.gz
Algorithm Hash digest
SHA256 0920a7fe28dd00bc0f44d3db91f4b7b0884853abf3f39f7399039357ad382abe
MD5 a0f8ae6950aff4b6f6b151ff71170d8c
BLAKE2b-256 46e54b692cad6afdbe732412d7f1ff6c5bc38b5eb88e866edcf05b7b0b8a76bd

See more details on using hashes here.

File details

Details for the file composio_langchain-0.5.36-py3-none-any.whl.

File metadata

File hashes

Hashes for composio_langchain-0.5.36-py3-none-any.whl
Algorithm Hash digest
SHA256 5b478011853122e837d3716a9efb9d2617e66c404c8312ad996f22bd1a3504b9
MD5 3e4d0356e69a7a90811ad29b8c61faef
BLAKE2b-256 956bfb7554922cfc691a1eed600ca37a5cead0d19e23a5ecfe2173adc0fadd2a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page