
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
# 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
Prepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.
from typing import Literal
from langchain_openai import ChatOpenAI
from langgraph.graph import MessagesState, StateGraph
from langgraph.prebuilt import ToolNode
Access GitHub tools provided by Composio for LangGraph, initialize a ToolNode
with necessary tools obtaned from ComposioToolSet
.
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)
Initialize the LLM class and bind obtained tools to the model.
model = ChatOpenAI(temperature=0, streaming=True)
model_with_tools = model.bind_tools(functions)
LangGraph expects you to define different nodes of the agentic workflow as separate functions. Here we define a node for calling the LLM model.
def call_model(state: MessagesState):
messages = state["messages"]
response = model_with_tools.invoke(messages)
return {"messages": [response]}
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.
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()
After the compilation of workflow, we invoke the LLM with a task, and stream the response.
for chunk in app.stream(
{
"messages": [
(
"human",
# "Star the Github Repository composiohq/composio",
"Get my information.",
)
]
},
stream_mode="values",
):
chunk["messages"][-1].pretty_print()
FAQs
Use Composio to get array of tools with LangGraph Agent Workflows.
We found that composio-langgraph demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.