Skip to main content
This example demonstrates how to create an autonomous agent using Composio tools with LangChain and LangGraph to build a stateful conversation flow.

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

1

Install dependencies

2

Set up environment variables

Create a .env file with your API keys:

Complete Example

How It Works

1

Initialize with LangChain Provider

We initialize Composio with the LangchainProvider, which automatically formats tools for LangChain compatibility.
2

Create Tool Node

We create a ToolNode from the Composio tools. This node will be responsible for executing tools in the graph.
3

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.
4

Define State Graph

We create a StateGraph with two nodes:
  • agent: Calls the model to decide the next action
  • tools: Executes the tools when the model requests them
5

Add Conditional Edges

We add conditional routing logic:
  • If the model makes tool calls → route to tools node
  • Otherwise → end the workflow
6

Execute Workflow

We invoke the compiled workflow with messages. The graph automatically handles tool execution and maintains conversation state.

Graph Visualization

The workflow graph looks like this:

Expected Output

Key Features

LangGraph maintains conversation state across multiple turns. The second query about “haxzie” uses context from the previous conversation.
The graph automatically decides when to use tools based on the model’s output, creating an autonomous agent workflow.
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