Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
md 63 lines 1.92 KB
Rendered Raw
1 # composio-langgraph
2
3 Adapts Composio tools to LangChain's `StructuredTool` format for use in LangGraph agents and graph workflows, giving them access to 1000+ apps through a single Composio session.
4
5 ## Installation
6
7 ```bash
8 pip install composio composio-langgraph langgraph langchain langchain-openai
9 ```
10
11 Set `COMPOSIO_API_KEY` (get one from [dashboard.composio.dev/settings](https://dashboard.composio.dev/settings)) and `OPENAI_API_KEY` in your environment:
12
13 ```bash
14 export COMPOSIO_API_KEY=xxxxxxxxx
15 export OPENAI_API_KEY=xxxxxxxxx
16 ```
17
18 ## Quickstart
19
20 Create a session for your user, fetch its tools, and hand them to your agent. The wrapped tools also work anywhere LangGraph accepts LangChain tools, such as a `ToolNode` in a custom graph.
21
22 ```python
23 from composio import Composio
24 from composio_langgraph import LanggraphProvider
25 from langchain.agents import create_agent
26 from langchain_openai import ChatOpenAI
27
28 composio = Composio(provider=LanggraphProvider())
29 llm = ChatOpenAI(model="gpt-5.2")
30
31 # Each session is scoped to one of your users
32 session = composio.create(user_id="user_123")
33 tools = session.tools()
34
35 agent = create_agent(tools=tools, model=llm)
36 result = agent.invoke(
37 {
38 "messages": [
39 (
40 "user",
41 "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'",
42 )
43 ]
44 }
45 )
46
47 print(result["messages"][-1].content)
48 ```
49
50 ## Error handling
51
52 Each wrapped tool builds its `args_schema` from the Composio tool's input schema. When argument validation fails, the tool does not raise; it returns a structured result:
53
54 ```python
55 {"successful": False, "error": "<validation message>", "data": None}
56 ```
57
58 Check `successful` in tool output instead of wrapping calls in `try`/`except`.
59
60 ## Links
61
62 - [LangChain provider docs](https://docs.composio.dev/docs/providers/langchain) (covers LangGraph)
63 - [Composio documentation](https://docs.composio.dev)