Overview
In this example, you’ll learn how to:- Integrate Composio with LangChain
- Build a state graph for agent workflows
- Create multi-turn conversations with context
- Use tools within a LangGraph workflow
Prerequisites
Complete Example
How It Works
Initialize with LangChain Provider
We initialize Composio with the
LangchainProvider, which automatically formats tools for LangChain compatibility.Create Tool Node
We create a
ToolNode from the Composio tools. This node will be responsible for executing tools in the graph.Bind Tools to Model
We create a ChatOpenAI model and bind the tools to it using
.bindTools(). This enables the model to call these tools.Define State Graph
We create a
StateGraph with two nodes:agent: Calls the model to decide the next actiontools: Executes the tools when the model requests them
Add Conditional Edges
We add conditional routing logic:
- If the model makes tool calls → route to
toolsnode - Otherwise → end the workflow
Graph Visualization
The workflow graph looks like this:Expected Output
Key Features
Stateful Conversations
Stateful Conversations
LangGraph maintains conversation state across multiple turns. The second query about “haxzie” uses context from the previous conversation.
Automatic Tool Routing
Automatic Tool Routing
The graph automatically decides when to use tools based on the model’s output, creating an autonomous agent workflow.
Composable Workflows
Composable Workflows
You can extend this graph with additional nodes for more complex workflows like error handling, validation, or multi-step reasoning.
Advanced Usage
You can extend this example with:- Streaming: Add streaming support for real-time responses
- Checkpointing: Save and restore conversation state
- Multiple Tools: Add more Composio tools for richer capabilities
- Custom Nodes: Add validation or preprocessing nodes
Next Steps
Custom Tools
Create your own tools with custom logic
OpenAI Example
Learn the basics with OpenAI