## 🦜🕸️ Using Composio With LangGraph
Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
### Goal
- **Star a repository on GitHub** using natural language commands through a LangGraph Agent.
### Installation and Setup
Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
```bash
# Install Composio LangGraph package
pip install composio-langgraph
# 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 LangGraph & LangChain for setting up your agent.
```python
from typing import Literal
from langchain_openai import ChatOpenAI
from langgraph.graph import MessagesState, StateGraph
from langgraph.prebuilt import ToolNode
```
#### 2. Fetch GitHub LangGraph Tools via Composio
Access GitHub tools provided by Composio for LangGraph, initialize a `ToolNode` with necessary tools obtaned from `ComposioToolSet`.
```python
from composio_langgraph import Action, ComposioToolSet
# Initialize the toolset for GitHub
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_actions(
actions=[
Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER,
Action.GITHUB_USERS_GET_AUTHENTICATED,
])
tool_node = ToolNode(tools)
```
#### 3. Prepare the model
Initialize the LLM class and bind obtained tools to the model.
```python
model = ChatOpenAI(temperature=0, streaming=True)
model_with_tools = model.bind_tools(functions)
```
#### 4. Define the Graph Nodes
LangGraph expects you to define different nodes of the agentic workflow as separate functions. Here we define a node for calling the LLM model.
```python
def call_model(state: MessagesState):
messages = state["messages"]
response = model_with_tools.invoke(messages)
return {"messages": [response]}
```
#### 5. Define the Graph Nodes and Edges
To establish the agent's workflow, we begin by initializing the workflow with `agent` and `tools` node, followed by specifying the connecting edges between nodes, finally compiling the workflow. These edges can be straightforward or conditional, depending on the workflow requirements.
```python
def should_continue(state: MessagesState) -> Literal["tools", "__end__"]:
messages = state["messages"]
last_message = messages[-1]
if last_message.tool_calls:
return "tools"
return "__end__"
workflow = StateGraph(MessagesState)
# Define the two nodes we will cycle between
workflow.add_node("agent", call_model)
workflow.add_node("tools", tool_node)
workflow.add_edge("__start__", "agent")
workflow.add_conditional_edges(
"agent",
should_continue,
)
workflow.add_edge("tools", "agent")
app = workflow.compile()
```
#### 6. Invoke & Check Response
After the compilation of workflow, we invoke the LLM with a task, and stream the response.
```python
for chunk in app.stream(
{
"messages": [
(
"human",
# "Star the Github Repository composiohq/composio",
"Get my information.",
)
]
},
stream_mode="values",
):
chunk["messages"][-1].pretty_print()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ComposioHQ/composio",
"name": "composio-langgraph",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "composio",
"author_email": "Composio <tech@composio.dev>",
"download_url": "https://files.pythonhosted.org/packages/0c/c7/e12bb1639bb2dbe2414164169451681d58af54651e4c10983daf8e3c1b21/composio_langgraph-0.8.5.tar.gz",
"platform": null,
"description": "## \ud83e\udd9c\ud83d\udd78\ufe0f Using Composio With LangGraph\n\nIntegrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.\n\n### Goal\n\n- **Star a repository on GitHub** using natural language commands through a LangGraph Agent.\n\n### Installation and Setup\n\nEnsure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.\n\n```bash\n# Install Composio LangGraph package\npip install composio-langgraph\n\n# Connect your GitHub account\ncomposio-cli add github\n\n# View available applications you can connect with\ncomposio-cli show-apps\n```\n\n### Usage Steps\n\n#### 1. Import Base Packages\n\nPrepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.\n\n```python\nfrom typing import Literal\n\nfrom langchain_openai import ChatOpenAI\nfrom langgraph.graph import MessagesState, StateGraph\nfrom langgraph.prebuilt import ToolNode\n```\n\n#### 2. Fetch GitHub LangGraph Tools via Composio\n\nAccess GitHub tools provided by Composio for LangGraph, initialize a `ToolNode` with necessary tools obtaned from `ComposioToolSet`.\n\n```python\nfrom composio_langgraph import Action, ComposioToolSet\n\n# Initialize the toolset for GitHub\ncomposio_toolset = ComposioToolSet()\ntools = composio_toolset.get_actions(\n actions=[\n Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER,\n Action.GITHUB_USERS_GET_AUTHENTICATED,\n ])\ntool_node = ToolNode(tools)\n```\n\n#### 3. Prepare the model\n\nInitialize the LLM class and bind obtained tools to the model.\n\n```python\nmodel = ChatOpenAI(temperature=0, streaming=True)\nmodel_with_tools = model.bind_tools(functions)\n```\n#### 4. Define the Graph Nodes\n\nLangGraph expects you to define different nodes of the agentic workflow as separate functions. Here we define a node for calling the LLM model.\n\n```python\ndef call_model(state: MessagesState):\n messages = state[\"messages\"]\n response = model_with_tools.invoke(messages)\n return {\"messages\": [response]}\n```\n#### 5. Define the Graph Nodes and Edges\n\nTo establish the agent's workflow, we begin by initializing the workflow with `agent` and `tools` node, followed by specifying the connecting edges between nodes, finally compiling the workflow. These edges can be straightforward or conditional, depending on the workflow requirements.\n\n```python\ndef should_continue(state: MessagesState) -> Literal[\"tools\", \"__end__\"]:\n messages = state[\"messages\"]\n last_message = messages[-1]\n if last_message.tool_calls:\n return \"tools\"\n return \"__end__\"\n\n\nworkflow = StateGraph(MessagesState)\n\n# Define the two nodes we will cycle between\nworkflow.add_node(\"agent\", call_model)\nworkflow.add_node(\"tools\", tool_node)\n\nworkflow.add_edge(\"__start__\", \"agent\")\nworkflow.add_conditional_edges(\n \"agent\",\n should_continue,\n)\nworkflow.add_edge(\"tools\", \"agent\")\n\napp = workflow.compile()\n```\n#### 6. Invoke & Check Response\n\nAfter the compilation of workflow, we invoke the LLM with a task, and stream the response.\n\n```python\nfor chunk in app.stream(\n {\n \"messages\": [\n (\n \"human\",\n # \"Star the Github Repository composiohq/composio\",\n \"Get my information.\",\n )\n ]\n },\n stream_mode=\"values\",\n):\n chunk[\"messages\"][-1].pretty_print()\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Use Composio to get array of tools with LangGraph Agent Workflows.",
"version": "0.8.5",
"project_urls": {
"Homepage": "https://github.com/ComposioHQ/composio"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8a0831759227b5dfe191c458757cc0a0e0757a0e6dae65749c3b34e7db4c1304",
"md5": "fd25db681b3376e20f1861173bdb627c",
"sha256": "cb121d5d6a902b6a81525b4f12fdbc209ab26060e49ac861e78b81941b7e6853"
},
"downloads": -1,
"filename": "composio_langgraph-0.8.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fd25db681b3376e20f1861173bdb627c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.9",
"size": 4272,
"upload_time": "2025-07-24T11:44:32",
"upload_time_iso_8601": "2025-07-24T11:44:32.327391Z",
"url": "https://files.pythonhosted.org/packages/8a/08/31759227b5dfe191c458757cc0a0e0757a0e6dae65749c3b34e7db4c1304/composio_langgraph-0.8.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0cc7e12bb1639bb2dbe2414164169451681d58af54651e4c10983daf8e3c1b21",
"md5": "4118aadf8e03dbf5b7794f322bf36c99",
"sha256": "671e1a62e14bffc7beac0dca4144c7d0bcf73b9e76195efc8d267beb898c65fd"
},
"downloads": -1,
"filename": "composio_langgraph-0.8.5.tar.gz",
"has_sig": false,
"md5_digest": "4118aadf8e03dbf5b7794f322bf36c99",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.9",
"size": 4036,
"upload_time": "2025-07-24T11:44:42",
"upload_time_iso_8601": "2025-07-24T11:44:42.460171Z",
"url": "https://files.pythonhosted.org/packages/0c/c7/e12bb1639bb2dbe2414164169451681d58af54651e4c10983daf8e3c1b21/composio_langgraph-0.8.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 11:44:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ComposioHQ",
"github_project": "composio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "composio-langgraph"
}