Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 09:30 UTC
docs: Rewrite Anthropic provider page — Messages API only, tested agentic loop
Separate Claude Agent SDK content into its own future page. The Anthropic page now covers only the Messages API with a clean agentic loop pattern, tested in both Python and TypeScript. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sushmithamallesh committed
Feb 16, 2026 at 19:55 UTC
0b70137904a272a9604aec7466e788ada8df15fb
1 file changed
+89
-302
docs/content/docs/providers/anthropic.mdx
+89
-302
@@ -1,273 +1,28 @@
1
---
2
title: Anthropic
3
description: Build an agent with Claude and enable it to use 800+ tools with Composio.
4
-keywords: [claude]
4
+keywords: [claude, messages api]
5
---
6
7
-## Claude Agents SDK
8
-
9
-<ToolTypeFlow>
10
-
11
-<ToolTypeOption id="native" name="Native Tools" icon="native">
12
-<Steps>
13
-<Step>
14
-**Install**
15
-
16
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
17
-<Tab value="Python">
18
-```bash
19
-pip install composio composio-claude-agent-sdk claude-agent-sdk
20
-```
21
-</Tab>
22
-<Tab value="TypeScript">
23
-```bash
24
-npm install dotenv @composio/core @composio/claude-agent-sdk @anthropic-ai/claude-agent-sdk
25
-```
26
-</Tab>
27
-</Tabs>
28
-</Step>
29
-
30
-<Step>
31
-**Configure API Keys**
32
-
33
-<Callout type="info">
34
-Set `COMPOSIO_API_KEY` with your API key from [Settings](https://platform.composio.dev/?next_page=/settings) and `ANTHROPIC_API_KEY` with your [Anthropic API key](https://console.anthropic.com/settings/keys).
35
-</Callout>
36
-
37
-```txt title=".env"
38
-COMPOSIO_API_KEY=xxxxxxxxx
39
-ANTHROPIC_API_KEY=xxxxxxxxx
40
-```
41
-</Step>
42
-
43
-<Step>
44
-**Create session and run agent**
45
-
46
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
47
-<Tab value="Python">
48
-```python
49
-import asyncio
50
-from dotenv import load_dotenv
51
-load_dotenv()
52
-
53
-from composio import Composio
54
-from composio_claude_agent_sdk import ClaudeAgentSDKProvider
55
-from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions, create_sdk_mcp_server
56
-
57
-# Initialize Composio with Claude Agent SDK provider
58
-composio = Composio(provider=ClaudeAgentSDKProvider())
59
-
60
-external_user_id = "user_2nFh83Hde"
61
-recipient_email = "soham.g@composio.dev"
62
-
63
-# Create a session
64
-session = composio.create(user_id=external_user_id)
65
-
66
-# Get tools from the session
67
-tools = session.tools()
68
-custom_server = create_sdk_mcp_server(name="composio", version="1.0.0", tools=tools)
69
-
70
-# Run the agent
71
-async def main():
72
- options = ClaudeAgentOptions(
73
- system_prompt="You are a helpful assistant.",
74
- permission_mode="bypassPermissions",
75
- mcp_servers={"composio": custom_server},
76
- )
77
-
78
- async with ClaudeSDKClient(options=options) as client:
79
- await client.query(f"Send an email to {recipient_email} with the subject 'Hello from Composio' and the body 'This is a test email!'")
80
- async for msg in client.receive_response():
81
- print(msg)
82
-
83
-asyncio.run(main())
84
-```
85
-</Tab>
86
-<Tab value="TypeScript">
87
-```typescript
88
-import "dotenv/config";
89
-import { Composio } from "@composio/core";
90
-import { ClaudeAgentSDKProvider } from "@composio/claude-agent-sdk";
91
-import { createSdkMcpServer, query } from "@anthropic-ai/claude-agent-sdk";
92
-
93
-// Initialize Composio with Claude Agent SDK provider
94
-const composio = new Composio({
95
- provider: new ClaudeAgentSDKProvider(),
96
-});
97
-
98
-const externalUserId = "user_2nFh83Hde";
99
-const recipientEmail = "soham.g@composio.dev";
100
-
101
-// Create a session
102
-const session = await composio.create(externalUserId);
103
-
104
-// Get tools from the session
105
-const tools = await session.tools();
106
-
107
-const customServer = createSdkMcpServer({
108
- name: "composio",
109
- version: "1.0.0",
110
- tools: tools,
111
-});
112
-
113
-// Run the agent
114
-console.log("Running agent...");
115
-for await (const content of query({
116
- prompt: `Send an email to ${recipientEmail} with the subject 'Hello from Composio' and the body 'This is a test email!'`,
117
- options: {
118
- mcpServers: { composio: customServer },
119
- permissionMode: "bypassPermissions",
120
- },
121
-})) {
122
- if (content.type === "assistant") {
123
- console.log("Claude:", content.message);
124
- }
125
-}
126
-
127
-console.log("Received response from Claude");
128
-```
129
-</Tab>
130
-</Tabs>
131
-</Step>
132
-</Steps>
133
-</ToolTypeOption>
134
-
135
-<ToolTypeOption id="mcp" name="MCP" icon="mcp">
136
-<Steps>
137
-<Step>
138
-**Install**
139
-
140
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
141
-<Tab value="Python">
142
-```bash
143
-pip install composio claude-agent-sdk
144
-```
145
-</Tab>
146
-<Tab value="TypeScript">
147
-```bash
148
-npm install dotenv @composio/core @anthropic-ai/claude-agent-sdk
149
-```
150
-</Tab>
151
-</Tabs>
152
-</Step>
153
-
154
-<Step>
155
-**Configure API Keys**
7
+The Anthropic Provider transforms Composio tools into a format compatible with the [Claude Messages API](https://docs.anthropic.com/en/api/messages).
8
9
<Callout type="info">
158
-Set `COMPOSIO_API_KEY` with your API key from [Settings](https://platform.composio.dev/?next_page=/settings) and `ANTHROPIC_API_KEY` with your [Anthropic API key](https://console.anthropic.com/settings/keys).
10
+Looking for the Claude Agent SDK? See the [Claude Agent SDK](/docs/providers/claude-agent-sdk) provider page.
11
</Callout>
12
161
-```txt title=".env"
162
-COMPOSIO_API_KEY=xxxxxxxxx
163
-ANTHROPIC_API_KEY=xxxxxxxxx
164
-```
165
-</Step>
166
-
167
-<Step>
168
-**Create session and run agent**
169
-
170
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
171
-<Tab value="Python">
172
-```python
173
-import asyncio
174
-from dotenv import load_dotenv
175
-load_dotenv()
176
-
177
-from composio import Composio
178
-from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
179
-
180
-# Initialize Composio
181
-composio = Composio()
182
-
183
-external_user_id = "user_2nFh83Hde"
184
-recipient_email = "soham.g@composio.dev"
185
-
186
-# Create a session
187
-session = composio.create(user_id=external_user_id)
188
-
189
-# Run the agent
190
-async def main():
191
- options = ClaudeAgentOptions(
192
- system_prompt="You are a helpful assistant.",
193
- permission_mode="bypassPermissions",
194
- mcp_servers={
195
- "composio": {
196
- "type": "http",
197
- "url": session.mcp.url,
198
- "headers": session.mcp.headers,
199
- }
200
- },
201
- )
202
-
203
- async with ClaudeSDKClient(options=options) as client:
204
- await client.query(f"Send an email to {recipient_email} with the subject 'Hello from Composio' and the body 'This is a test email!'")
205
- async for msg in client.receive_response():
206
- print(msg)
207
-
208
-asyncio.run(main())
209
-```
210
-</Tab>
211
-<Tab value="TypeScript">
212
-```typescript
213
-import "dotenv/config";
214
-import { Composio } from "@composio/core";
215
-import { query } from "@anthropic-ai/claude-agent-sdk";
216
-
217
-// Initialize Composio
218
-const composio = new Composio();
219
-
220
-const externalUserId = "user_2nFh83Hde";
221
-const recipientEmail = "soham.g@composio.dev";
222
-
223
-// Create a session
224
-const session = await composio.create(externalUserId);
225
-
226
-// Run the agent
227
-console.log("Running agent...");
228
-for await (const content of query({
229
- prompt: `Send an email to ${recipientEmail} with the subject 'Hello from Composio' and the body 'This is a test email!'`,
230
- options: {
231
- mcpServers: {
232
- composio: {
233
- type: "http",
234
- url: session.mcp.url,
235
- headers: session.mcp.headers,
236
- },
237
- },
238
- permissionMode: "bypassPermissions",
239
- },
240
-})) {
241
- if (content.type === "assistant") {
242
- console.log("Claude:", content.message);
243
- }
244
-}
245
-
246
-console.log("Received response from Claude");
247
-```
248
-</Tab>
249
-</Tabs>
250
-</Step>
251
-</Steps>
252
-</ToolTypeOption>
253
-
254
-</ToolTypeFlow>
255
-
256
-## Anthropic API
257
-
13
<Steps>
14
<Step>
15
**Install**
16
262
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
17
+<Tabs groupId="language" items={["Python", "TypeScript"]} persist>
18
<Tab value="Python">
19
```bash
265
-pip install composio composio-anthropic anthropic
20
+pip install composio composio_anthropic anthropic
21
```
22
</Tab>
23
<Tab value="TypeScript">
24
```bash
270
-npm install dotenv @composio/core @composio/anthropic @anthropic-ai/sdk
25
+npm install @composio/core @composio/anthropic @anthropic-ai/sdk
26
```
27
</Tab>
28
</Tabs>
@@ -287,87 +42,119 @@ ANTHROPIC_API_KEY=xxxxxxxxx
42
</Step>
43
44
<Step>
290
-**Create session and run agent**
45
+**Create session and run**
46
292
-<Tabs groupId="language" items={['Python', 'TypeScript']} persist>
47
+<Tabs groupId="language" items={["Python", "TypeScript"]} persist>
48
<Tab value="Python">
49
```python
50
+import json
51
import anthropic
296
-from dotenv import load_dotenv
297
-load_dotenv()
298
-
52
from composio import Composio
53
from composio_anthropic import AnthropicProvider
54
302
-# Initialize Composio with Anthropic provider
303
-anthropic_client = anthropic.Anthropic()
55
composio = Composio(provider=AnthropicProvider())
56
+client = anthropic.Anthropic()
57
306
-external_user_id = "user_2nFh83Hde"
307
-recipient_email = "soham.g@composio.dev"
308
-
309
-# Create a session
310
-session = composio.create(user_id=external_user_id)
311
-
312
-# Get tools from the session
58
+# Create a session for your user
59
+session = composio.create(user_id="user_123")
60
tools = session.tools()
61
315
-# Get response from the LLM
316
-response = anthropic_client.messages.create(
317
- model="claude-sonnet-4-5",
318
- max_tokens=1024,
62
+messages = [
63
+ {"role": "user", "content": "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'"}
64
+]
65
+
66
+response = client.messages.create(
67
+ model="claude-sonnet-4-5-20250929",
68
+ max_tokens=4096,
69
tools=tools,
320
- messages=[
321
- {"role": "user", "content": f"Send an email to {recipient_email} with the subject 'Hello from Composio' and the body 'This is a test email!'"},
322
- ],
70
+ messages=messages,
71
)
72
325
-# Execute the function calls
326
-result = composio.provider.handle_tool_calls(user_id=external_user_id, response=response)
327
-print(result)
73
+# Agentic loop — keep executing tool calls until the model responds with text
74
+while response.stop_reason == "tool_use":
75
+ tool_use_blocks = [block for block in response.content if block.type == "tool_use"]
76
+ results = composio.provider.handle_tool_calls(user_id="user_123", response=response)
77
+ messages.append({"role": "assistant", "content": response.content})
78
+ messages.append({
79
+ "role": "user",
80
+ "content": [
81
+ {"type": "tool_result", "tool_use_id": tool_use_blocks[i].id, "content": json.dumps(result)}
82
+ for i, result in enumerate(results)
83
+ ]
84
+ })
85
+ response = client.messages.create(
86
+ model="claude-sonnet-4-5-20250929",
87
+ max_tokens=4096,
88
+ tools=tools,
89
+ messages=messages,
90
+ )
91
+
92
+# Print final response
93
+for block in response.content:
94
+ if hasattr(block, "text"):
95
+ print(block.text)
96
```
97
</Tab>
98
<Tab value="TypeScript">
99
```typescript
332
-import "dotenv/config";
333
-import { Composio } from "@composio/core";
334
-import { AnthropicProvider } from "@composio/anthropic";
335
-import Anthropic from "@anthropic-ai/sdk";
100
+import Anthropic from '@anthropic-ai/sdk';
101
+import { Composio } from '@composio/core';
102
+import { AnthropicProvider } from '@composio/anthropic';
103
337
-// Initialize Composio with Anthropic provider
104
const composio = new Composio({
339
- provider: new AnthropicProvider(),
105
+ provider: new AnthropicProvider(),
106
});
341
-const anthropic = new Anthropic();
342
-
343
-const externalUserId = "user_2nFh83Hde";
344
-const recipientEmail = "soham.g@composio.dev";
107
+const client = new Anthropic();
108
346
-// Create a session
347
-const session = await composio.create(externalUserId);
348
-
349
-// Get tools from the session
109
+// Create a session for your user
110
+const session = await composio.create("user_123");
111
const tools = await session.tools();
112
352
-// Get response from the LLM
353
-const msg = await anthropic.messages.create({
354
- model: "claude-sonnet-4-5",
355
- messages: [
113
+const messages: Anthropic.MessageParam[] = [
114
{
357
- role: "user",
358
- content: `Send an email to ${recipientEmail} with the subject 'Hello from Composio' and the body 'This is a test email!'`,
115
+ role: "user",
116
+ content: "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'"
117
},
360
- ],
361
- tools: tools,
362
- max_tokens: 1000,
118
+];
119
+
120
+let response = await client.messages.create({
121
+ model: "claude-sonnet-4-5-20250929",
122
+ max_tokens: 4096,
123
+ tools: tools,
124
+ messages: messages,
125
});
126
365
-// Execute the function calls
366
-const result = await composio.provider.handleToolCalls(externalUserId, msg);
367
-console.log(result);
127
+// Agentic loop — keep executing tool calls until the model responds with text
128
+while (response.stop_reason === "tool_use") {
129
+ const toolUseBlocks = response.content.filter(
130
+ (block): block is Anthropic.ToolUseBlock => block.type === "tool_use"
131
+ );
132
+ const results = await composio.provider.handleToolCalls("user_123", response);
133
+ messages.push({ role: "assistant", content: response.content });
134
+ messages.push({
135
+ role: "user",
136
+ content: results.map((result, i) => ({
137
+ type: "tool_result" as const,
138
+ tool_use_id: toolUseBlocks[i].id,
139
+ content: JSON.stringify(result),
140
+ })),
141
+ });
142
+ response = await client.messages.create({
143
+ model: "claude-sonnet-4-5-20250929",
144
+ max_tokens: 4096,
145
+ tools: tools,
146
+ messages: messages,
147
+ });
148
+}
149
+
150
+// Print final response
151
+for (const block of response.content) {
152
+ if (block.type === "text") {
153
+ console.log(block.text);
154
+ }
155
+}
156
```
157
</Tab>
158
</Tabs>
159
</Step>
160
</Steps>
373
-