@devries-cameron20 / composio-1 / commits / 0bf38f674
Fork 0

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

Update documentation for tools and providers, including new examples and modifications to existing code snippets. Added custom provider guides for Python and TypeScript, and improved the structure of authentication and execution examples. Adjusted navigation in the documentation to reflect these changes.

balyan.sid@gmail.com committed Jun 20, 2025 at 15:29 UTC 0bf38f674e8bbaaa5fb15d3009556cac7c2913cb
19 files changed +663 -634
fern/docs.yml
+6 -7
@@ -175,12 +175,6 @@ navigation:
175 icon: rocket
176 skip-slug: true
177 contents:
178 - - page: Hello World
179 - path: pages/dist/examples/hello-world.mdx
180 - slug: examples/hello-world
181 - - page: Sample Script
182 - path: pages/dist/examples/sample-script.mdx
183 - slug: examples/sample-script
178 - page: Basic Hono Server
179 path: pages/dist/examples/sample-webserver/sample-webserver.mdx
180 slug: examples/sample-webserver
@@ -225,10 +219,15 @@ navigation:
219 - page: Mastra Provider
220 path: pages/dist/providers/mastra.mdx
221 - section: Writing your own provider
222 + skip-slug: true
223 icon: code
224 contents:
225 - page: TypeScript
231 - path: pages/dist/providers/custom.mdx
226 + path: pages/dist/providers/ts-custom.mdx
227 + slug: providers/custom/typescript
228 + - page: Python
229 + path: pages/dist/providers/py-custom.mdx
230 + slug: providers/custom/python
231 - tab: tools
232 layout:
233 - section: Tool
fern/pages/src/authentication/custom-auth-configs.mdx
+36 -36
@@ -95,18 +95,6 @@ As usual, copy and use the auth config ID starting with `ac_` in your applicatio
95 This auth config is now ready to be used in your application!
96
97 <CodeGroup>
98 -```typescript TypeScript maxLines=60
99 -const connReq = await composio.connectedAccounts.initiate(userId, "ac_1234");
100 -
101 -console.log(connReq.redirectUrl);
102 -
103 -const connection = await composio.connectedAccounts.waitForConnection(
104 -connReq.id
105 -);
106 -
107 -console.log(connection);
108 -
109 -````
98 ```python Python maxLines=60
99 # Create a new connected account
100 connection_request = composio.connected_accounts.initiate(
@@ -118,7 +106,19 @@ print(connection_request)
106 # Wait for the connection to be established
107 connected_account = connection_request.wait_for_connection()
108 print(connected_account)
121 -````
109 +```
110 +```typescript TypeScript maxLines=60
111 +const connReq = await composio.connectedAccounts.initiate(userId, "ac_1234");
112 +
113 +console.log(connReq.redirectUrl);
114 +
115 +const connection = await composio.connectedAccounts.waitForConnection(
116 +connReq.id
117 +);
118 +
119 +console.log(connection);
120 +
121 +```
122
123 </CodeGroup>
124
@@ -149,28 +149,6 @@ Create a redirect logic, either through your DNS or in your application to redir
149 **Example: API Route for OAuth Redirect**
150
151 <CodeGroup>
152 -```typescript Next.js (pages/api/composio-redirect.ts)
153 -import type { NextApiRequest, NextApiResponse } from 'next';
154 -
155 -export default function handler(req: NextApiRequest, res: NextApiResponse) {
156 - // The target Composio endpoint that handles OAuth callbacks
157 - const composioEndpoint = 'https://backend.composio.dev/api/v3/toolkits/callback';
158 -
159 -// Extract and preserve all query parameters
160 -const queryParams = new URLSearchParams();
161 -Object.entries(req.query).forEach(([key, value]) => {
162 -if (typeof value === 'string') {
163 -queryParams.append(key, value);
164 -}
165 -});
166 -
167 -// Redirect to Composio with all query parameters intact
168 -const redirectUrl = `${composioEndpoint}?${queryParams.toString()}`;
169 -res.redirect(302, redirectUrl);
170 -}
171 -
172 -````
173 -
152 ```python FastAPI (app.py)
153 from fastapi import FastAPI
154 from fastapi.responses import RedirectResponse
@@ -198,7 +176,29 @@ def authorize_app(toolkit: str):
176 auth_config_id=auth_config_id,
177 )
178 return RedirectResponse(url=connection_request.redirect_url)
201 -````
179 +```
180 +
181 +```typescript Next.js (pages/api/composio-redirect.ts)
182 +import type { NextApiRequest, NextApiResponse } from 'next';
183 +
184 +export default function handler(req: NextApiRequest, res: NextApiResponse) {
185 + // The target Composio endpoint that handles OAuth callbacks
186 + const composioEndpoint = 'https://backend.composio.dev/api/v3/toolkits/callback';
187 +
188 +// Extract and preserve all query parameters
189 +const queryParams = new URLSearchParams();
190 +Object.entries(req.query).forEach(([key, value]) => {
191 +if (typeof value === 'string') {
192 +queryParams.append(key, value);
193 +}
194 +});
195 +
196 +// Redirect to Composio with all query parameters intact
197 +const redirectUrl = `${composioEndpoint}?${queryParams.toString()}`;
198 +res.redirect(302, redirectUrl);
199 +}
200 +
201 +```
202
203 </CodeGroup>
204 </Step>
fern/pages/src/authentication/custom-auth-params.mdx
+38 -38
@@ -13,6 +13,11 @@ In case Composio is not being used for managing the auth but only for the tools.
13 First, initialize the Composio SDK with your API key:
14
15 <CodeGroup>
16 +```python Python maxLines=10
17 +from composio import Composio
18 +
19 +composio = Composio()
20 +```
21 ```typescript TypeScript maxLines=10
22 import { Composio } from "@composio/core";
23
@@ -20,11 +25,6 @@ const composio = new Composio({
25 apiKey: process.env.COMPOSIO_API_KEY,
26 });
27 ```
23 -```python Python maxLines=10
24 -from composio import Composio
25 -
26 -composio = Composio()
27 -```
28 </CodeGroup>
29
30 ## Creating the Auth Modifier Function
@@ -37,28 +37,6 @@ Before Execute Modifiers are a way to modify the parameters of a tool before it
37 </Card>
38
39 <CodeGroup>
40 -```typescript TypeScript maxLines=25
41 -const authModifier = (toolSlug: string, toolkitSlug: string, params: any) => {
42 - // Add authentication parameters for specific toolkits
43 - if (toolkitSlug === "NOTION") {
44 - if (!params.customAuthParams) {
45 - params.customAuthParams = {};
46 - }
47 -
48 - if (!params.customAuthParams.parameters) {
49 - params.customAuthParams.parameters = [];
50 - }
51 -
52 - // Add an API key to the headers
53 - params.customAuthParams.parameters.push({
54 - in: "header",
55 - name: "X-API-Key",
56 - value: process.env.CUSTOM_API_KEY,
57 - });
58 - }
59 - return params;
60 -};
61 -```
40 ```python Python maxLines=25
41 from composio import before_execute
42 from composio.types import ToolExecuteParams
@@ -82,6 +60,28 @@ def add_custom_auth(
60 )
61 return params
62 ```
63 +```typescript TypeScript maxLines=25
64 +const authModifier = (toolSlug: string, toolkitSlug: string, params: any) => {
65 + // Add authentication parameters for specific toolkits
66 + if (toolkitSlug === "NOTION") {
67 + if (!params.customAuthParams) {
68 + params.customAuthParams = {};
69 + }
70 +
71 + if (!params.customAuthParams.parameters) {
72 + params.customAuthParams.parameters = [];
73 + }
74 +
75 + // Add an API key to the headers
76 + params.customAuthParams.parameters.push({
77 + in: "header",
78 + name: "X-API-Key",
79 + value: process.env.CUSTOM_API_KEY,
80 + });
81 + }
82 + return params;
83 +};
84 +```
85 </CodeGroup>
86
87 ## Executing Tools with Custom Auth
@@ -94,6 +94,17 @@ Following is an example of how to execute a tool with a custom authentication mo
94 For Agentic Providers, read about [Before Execution Modifiers](/docs/modifiers/before-execution).
95
96 <CodeGroup>
97 +```python Python maxLines=20
98 +result = composio.tools.execute(
99 + slug="NOTION_GET_DATABASE_ITEMS",
100 + user_id="default",
101 + arguments={},
102 + modifiers=[
103 + add_custom_auth,
104 + ],
105 +)
106 +print(result)
107 +```
108 ```typescript TypeScript maxLines=20
109 const result = await composio.tools.execute(
110 "NOTION_GET_DATABASE_ITEMS",
@@ -110,15 +121,4 @@ const result = await composio.tools.execute(
121
122 console.log(JSON.stringify(result, null, 2));
123 ```
113 -```python Python maxLines=20
114 -result = composio.tools.execute(
115 - slug="NOTION_GET_DATABASE_ITEMS",
116 - user_id="default",
117 - arguments={},
118 - modifiers=[
119 - add_custom_auth,
120 - ],
121 -)
122 -print(result)
123 -```
124 </CodeGroup>
\ No newline at end of file
fern/pages/src/authentication/programmatic-auth-configs.mdx
+60 -60
@@ -15,19 +15,6 @@ Auth configs are created once and reused many times. However when dealing with m
15 For certain apps, you can optionally use Composio's managed auth. This means you don't have to provide your own OAuth credentials, Bearer tokens, API keys, etc.
16
17 <CodeGroup>
18 -```typescript TypeScript maxLines=60 wordWrap {7}
19 -import { Composio } from "@composio/core";
20 -
21 -const composio = new Composio();
22 -
23 -const authConfig = await composio.authConfigs.create("LINEAR", {
24 - name: "Linear",
25 - type: "use_composio_managed_auth",
26 -});
27 -
28 -console.log(authConfig);
29 -```
30 -
18 ```python Python maxLines=60 wordWrap
19 from composio import Composio
20
@@ -42,6 +29,19 @@ auth_config = composio.auth_configs.create(
29 )
30 print(auth_config)
31 ```
32 +
33 +```typescript TypeScript maxLines=60 wordWrap {7}
34 +import { Composio } from "@composio/core";
35 +
36 +const composio = new Composio();
37 +
38 +const authConfig = await composio.authConfigs.create("LINEAR", {
39 + name: "Linear",
40 + type: "use_composio_managed_auth",
41 +});
42 +
43 +console.log(authConfig);
44 +```
45 </CodeGroup>
46
47
@@ -59,20 +59,6 @@ This is the URI that captures the OAuth code that is returned to the app.
59 In this case, we're using our own OAuth2 client ID and secret to create the auth config for Notion:
60
61 <CodeGroup>
62 -```typescript TypeScript maxLines=60 wordWrap
63 -const authConfig = await composio.authConfigs.create("NOTION", {
64 - name: "Notion",
65 - type: "use_custom_auth",
66 - credentials: {
67 - client_id: "1234567890",
68 - client_secret: "1234567890",
69 - oauth_redirect_uri: "https://backend.composio.dev/api/v3/toolkits/callback",
70 - },
71 - authScheme: "OAUTH2",
72 -});
73 -
74 -console.log(authConfig);
75 -```
62 ```python Python maxLines=60 wordWrap
63 # Use custom auth
64 auth_config = composio.auth_configs.create(
@@ -90,6 +76,20 @@ auth_config = composio.auth_configs.create(
76 )
77 print(auth_config)
78 ```
79 +```typescript TypeScript maxLines=60 wordWrap
80 +const authConfig = await composio.authConfigs.create("NOTION", {
81 + name: "Notion",
82 + type: "use_custom_auth",
83 + credentials: {
84 + client_id: "1234567890",
85 + client_secret: "1234567890",
86 + oauth_redirect_uri: "https://backend.composio.dev/api/v3/toolkits/callback",
87 + },
88 + authScheme: "OAUTH2",
89 +});
90 +
91 +console.log(authConfig);
92 +```
93 </CodeGroup>
94
95 ### Fetching the fields
@@ -98,6 +98,14 @@ For more complex cases where you need to dynamically discover the exact field na
98 **Inspect the auth config details**
99
100 <CodeGroup>
101 +```python Python maxLines=60 wordWrap
102 +required_fields = composio.toolkits.get_auth_config_creation_fields(
103 + toolkit="NOTION",
104 + auth_scheme="OAUTH2",
105 + required_only=True,
106 +)
107 +print(required_fields)
108 +```
109 ```typescript TypeScript maxLines=60
110 const toolkits = await composio.toolkits.get("NOTION");
111
@@ -108,14 +116,6 @@ const authFields = await composio.toolkits.getAuthConfigCreationFields('NOTION',
116
117 console.log("Required auth config fields:", authFields);
118 ```
111 -```python Python maxLines=60 wordWrap
112 -required_fields = composio.toolkits.get_auth_config_creation_fields(
113 - toolkit="NOTION",
114 - auth_scheme="OAUTH2",
115 - required_only=True,
116 -)
117 -print(required_fields)
118 -```
119 </CodeGroup>
120
121
@@ -129,31 +129,6 @@ NOTION_CLIENT_SECRET=your_client_secret
129 This makes it easy to create the auth config programmatically by reading required fields from the environment variables.
130
131 <CodeGroup>
132 -```typescript TypeScript maxLines=60 wordWrap
133 -import { Composio } from "@composio/core";
134 -
135 -const composio = new Composio({
136 - apiKey: process.env.COMPOSIO_API_KEY,
137 -});
138 -
139 -const authConfigCreationFields = await composio.toolkits.getAuthConfigCreationFields('NOTION', 'OAUTH2', {
140 - requiredOnly: true,
141 -});
142 -
143 -console.log("Required auth config fields:", requiredAuthFields);
144 -
145 -const authConfig = await composio.authConfigs.create("NOTION", {
146 - name: "Notion",
147 - type: "use_custom_auth",
148 - authScheme: "OAUTH2", // Replace with the correct scheme for your toolkit if different
149 - credentials: Object.fromEntries(
150 - requiredAuthFields.map(({ name }) => [
151 - name,
152 - process.env[`NOTION_${name.toUpperCase()}`] || "",
153 - ])
154 - ),
155 -});
156 -```
132 ```python Python maxLines=60 wordWrap
133 import os
134
@@ -183,5 +158,30 @@ auth_config = composio.auth_configs.create(
158 },
159 )
160 ```
161 +```typescript TypeScript maxLines=60 wordWrap
162 +import { Composio } from "@composio/core";
163 +
164 +const composio = new Composio({
165 + apiKey: process.env.COMPOSIO_API_KEY,
166 +});
167 +
168 +const authConfigCreationFields = await composio.toolkits.getAuthConfigCreationFields('NOTION', 'OAUTH2', {
169 + requiredOnly: true,
170 +});
171 +
172 +console.log("Required auth config fields:", requiredAuthFields);
173 +
174 +const authConfig = await composio.authConfigs.create("NOTION", {
175 + name: "Notion",
176 + type: "use_custom_auth",
177 + authScheme: "OAUTH2", // Replace with the correct scheme for your toolkit if different
178 + credentials: Object.fromEntries(
179 + requiredAuthFields.map(({ name }) => [
180 + name,
181 + process.env[`NOTION_${name.toUpperCase()}`] || "",
182 + ])
183 + ),
184 +});
185 +```
186 </CodeGroup>
187 </Accordion>
\ No newline at end of file
fern/pages/src/get-started/providers.mdx
+41 -13
@@ -31,18 +31,18 @@ Here's how you can generate text with various providers using Composio SDK:
31 <Tab title="OpenAI (Default)">
32 OpenAI is a completion provider. You can use it to generate text, function calls.
33 <CodeGroup>
34 +```python Python
35 +from composio import Composio
36 +from composio_openai import OpenAIProvider
37 +
38 +composio = Composio(provider=OpenAIProvider())
39 +```
40 ```typescript TypeScript
41 import { Composio } from "@composio/core";
42 import { OpenAIProvider } from "@composio/openai";
43
44 const composio = new Composio({ provider: new OpenAIProvider() });
45
40 -```
41 -```python Python
42 -from composio import Composio
43 -from composio_openai import OpenAIProvider
44 -
45 -composio = Composio(provider=OpenAIProvider())
46 ```
47
48 </CodeGroup>
@@ -50,6 +50,12 @@ composio = Composio(provider=OpenAIProvider())
50 <Tab title="Anthropic">
51 Anthropic is a completion provider. You can use it to generate text, function calls.
52 <CodeGroup>
53 +```python Python
54 +from composio import Composio
55 +from composio_anthropic import AnthropicProvider
56 +
57 +composio = Composio(provider=AnthropicProvider())
58 +```
59 ```typescript TypeScript
60 import { Composio } from "@composio/core";
61 import { AnthropicProvider } from "@composio/anthropic";
@@ -58,13 +64,6 @@ import { Anthropic } from "@anthropic-ai/sdk";
64 const composio = new Composio({ provider: new AnthropicProvider() });
65
66 ```
61 -```python Python
62 -from composio import Composio
63 -from composio_anthropic import AnthropicProvider
64 -
65 -composio = Composio(provider=AnthropicProvider())
66 -```
67 -
67 </CodeGroup>
68 </Tab>
69 <Tab title="Vercel AI SDK">
@@ -95,11 +94,40 @@ const composio = new Composio({
94 </Tab>
95 <Tab title="OpenAI Agents">
96 ```python Python
97 +import asyncio
98 +
99 +from agents import Agent, Runner
100 +
101 from composio import Composio
102 from composio_openai_agents import OpenAIAgentsProvider
103
104 +# Initialize Composio toolset
105 composio = Composio(provider=OpenAIAgentsProvider())
106
107 +# Get all the tools
108 +tools = composio.tools.get(
109 + user_id="default",
110 + tools=["GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER"],
111 +)
112 +
113 +# Create an agent with the tools
114 +agent = Agent(
115 + name="GitHub Agent",
116 + instructions="You are a helpful assistant.",
117 + tools=tools,
118 +)
119 +
120 +# Run the agent
121 +async def main():
122 + result = await Runner.run(
123 + starting_agent=agent,
124 + input=(
125 + "Star the repository composiohq/composio on GitHub"
126 + ),
127 + )
128 + print(result.final_output)
129 +
130 +asyncio.run(main())
131 ```
132 </Tab>
133 </Tabs>
fern/pages/src/get-started/quickstart.mdx
+10 -10
@@ -26,12 +26,12 @@ export COMPOSIO_API_KEY=your_api_key
26 ## Install the SDK
27 First and foremost, install the Composio SDK.
28 <CodeGroup>
29 -```bash title="TypeScript" for="typescript"
30 -npm install @composio/core@next
31 -```
29 ```bash title="Python" for="python"
30 pip install composio
31 ```
32 +```bash title="TypeScript" for="typescript"
33 +npm install @composio/core@next
34 +```
35 </CodeGroup>
36
37 ## Initialise
@@ -39,6 +39,13 @@ pip install composio
39 To use the SDK, you need to initialize it with your API key:
40
41 <CodeGroup>
42 +```python Python
43 +from composio import Composio
44 +
45 +composio = Composio(
46 + # api_key="your-api-key",
47 +)
48 +```
49 ```typescript TypeScript
50 import { Composio } from '@composio/core';
51
@@ -47,13 +54,6 @@ const composio = new Composio({
54 // apiKey: 'your-api-key',
55 });
56 ```
50 -```python Python
51 -from composio import Composio
52 -
53 -composio = Composio(
54 - # api_key="your-api-key",
55 -)
56 -```
57 </CodeGroup>
58
59
fern/pages/src/migration-guide.mdx
+2 -2
@@ -191,14 +191,14 @@ To examine the raw schema definition of a tool for understanding input/output pa
191
192 <CodeGroup>
193 <SnippetCode
194 - src="fern/snippets/python/raw_tools.py"
194 + src="fern/snippets/tool-calling/python/raw_tools.py"
195 startLine={1}
196 endLine={11}
197 title="Python (current)"
198 />
199
200 <SnippetCode
201 - src="fern/snippets/typescript/raw_tools.ts"
201 + src="fern/snippets/tool-calling/typescript/raw_tools.ts"
202 startLine={1}
203 endLine={11}
204 title="TypeScript (current)"
fern/pages/src/providers/anthropic.mdx
+36 -36
@@ -13,18 +13,29 @@ The Anthropic Provider transforms Composio tools into a format compatible with A
13 Anthropic provider can be installed for both the SDKs.
14
15 <CodeGroup>
16 -```bash title="TypeScript" for="typescript" maxLines=60 wordWrap
17 -npm install @composio/anthropic @anthropic-ai/sdk
18 -```
19 -
16 ```bash title="Python" for="python" maxLines=60 wordWrap
17 pip install composio[anthropic]
18 ```
19 +
20 +```bash title="TypeScript" for="typescript" maxLines=60 wordWrap
21 +npm install @composio/anthropic @anthropic-ai/sdk
22 +```
23 </CodeGroup>
24
25 You can specify the provider in the constructor. The constructor also takes in an optional `cacheTools` parameter.
26
27 <CodeGroup>
28 +```python Python maxLines=60 wordWrap
29 +import anthropic
30 +
31 +from composio import Composio
32 +from composio_anthropic import AnthropicProvider
33 +
34 +# Initialize tools.
35 +anthropic_client = anthropic.Anthropic()
36 +composio = Composio(provider=AnthropicProvider())
37 +```
38 +
39 ```typescript TypeScript maxLines=60 wordWrap {5}
40 import { Composio } from "@composio/core";
41 import { AnthropicProvider } from "@composio/anthropic";
@@ -37,22 +48,33 @@ const composio = new Composio({
48
49 const anthropic = new Anthropic();
50 ```
51 +</CodeGroup>
52
53 +## Usage
54 +
55 +<CodeGroup>
56 ```python Python maxLines=60 wordWrap
42 -import anthropic
57 +# Define your user ID
58 +user_id = "default"
59
44 -from composio import Composio
45 -from composio_anthropic import AnthropicProvider
60 +# Get GitHub tools that are pre-configured
61 +tools = composio.tools.get(user_id=user_id, toolkits=["GITHUB"])
62
47 -# Initialize tools.
48 -anthropic_client = anthropic.Anthropic()
49 -composio = Composio(provider=AnthropicProvider())
50 -```
51 -</CodeGroup>
63 +# Get response from the LLM
64 +response = anthropic_client.messages.create(
65 + model="claude-3-5-sonnet-20240620",
66 + max_tokens=1024,
67 + tools=tools,
68 + messages=[
69 + {"role": "user", "content": "Star me composiohq/composio repo in github."},
70 + ],
71 +)
72
53 -## Usage
73 +# Execute the function calls.
74 +result = composio.provider.handle_tool_calls(user_id=user_id, response=response)
75 +print(result)
76 +```
77
55 -<CodeGroup>
78 ```typescript TypeScript maxLines=60 wordWrap
79 const userId = "user@acme.com";
80 const tools = await composio.tools.get(userId, {
@@ -75,28 +97,6 @@ const res = await composio.provider.handleToolCalls(userId, msg);
97
98 console.log(JSON.parse(res[0]).details);
99 ```
78 -
79 -```python Python maxLines=60 wordWrap
80 -# Define your user ID
81 -user_id = "default"
82 -
83 -# Get GitHub tools that are pre-configured
84 -tools = composio.tools.get(user_id=user_id, toolkits=["GITHUB"])
85 -
86 -# Get response from the LLM
87 -response = anthropic_client.messages.create(
88 - model="claude-3-5-sonnet-20240620",
89 - max_tokens=1024,
90 - tools=tools,
91 - messages=[
92 - {"role": "user", "content": "Star me composiohq/composio repo in github."},
93 - ],
94 -)
95 -
96 -# Execute the function calls.
97 -result = composio.provider.handle_tool_calls(user_id=user_id, response=response)
98 -print(result)
99 -```
100 </CodeGroup>
101
102 ### Streaming
fern/pages/src/providers/openai.mdx
+15 -15
@@ -12,25 +12,25 @@ The OpenAI Provider is the default provider for the Composio SDK. It transforms
12 By default the OpenAI Provider is installed when you install the Composio SDK. You can also install it manually:
13
14 <CodeGroup>
15 -```bash title="TypeScript" for="typescript"
16 -npm install @composio/openai
17 -```
15 ```bash title="Python" for="python"
16 pip install composio[openai]
17 ```
18 +```bash title="TypeScript" for="typescript"
19 +npm install @composio/openai
20 +```
21 </CodeGroup>
22 The OpenAI Provider is used by default when you initialize the Composio SDK but you can explicitly specify it.
23
24 <CodeGroup>
25 <SnippetCode
26 - src="fern/snippets/providers/typescript/openai.ts"
26 + src="fern/snippets/providers/python/openai-provider.py"
27 startLine={1}
28 - endLine={7}
28 + endLine={8}
29 />
30 <SnippetCode
31 - src="fern/snippets/providers/python/openai-provider.py"
31 + src="fern/snippets/providers/typescript/openai.ts"
32 startLine={1}
33 - endLine={8}
33 + endLine={7}
34 />
35 </CodeGroup>
36
@@ -38,30 +38,30 @@ The OpenAI Provider is used by default when you initialize the Composio SDK but
38 The Responses API is the recommended way to build more agentic flows with the OpenAI API. Read more about it in the [OpenAI documentation](https://platform.openai.com/docs/guides/responses-vs-chat-completions)
39
40 <CodeGroup>
41 +```python
42 +
43 +```
44 <SnippetCode
45 src="fern/snippets/providers/typescript/openai.ts"
46 startLine={5}
47 endLine={24}
48 />
46 -```python
47 -
48 -```
49 </CodeGroup>
50
51 ## Chat Completion API
52 Chat Completion API is the industry standard for building LLM-powered applications. Chat completions is also adopted and used by many other LLM providers apart from OpenAI.
53
54 <CodeGroup>
55 -<SnippetCode
56 - src="fern/snippets/providers/typescript/openai.ts"
57 - startLine={26}
58 - endLine={45}
59 -/>
55 <SnippetCode
56 src="fern/snippets/providers/python/openai-provider.py"
57 startLine={10}
58 endLine={24}
59 />
60 +<SnippetCode
61 + src="fern/snippets/providers/typescript/openai.ts"
62 + startLine={26}
63 + endLine={45}
64 +/>
65
66 </CodeGroup>
67
fern/pages/src/providers/py-custom.mdx new
+6
@@ -0,0 +1,6 @@
1 +---
2 +title: Python Custom Provider
3 +image: "https://og.composio.dev/api/og?title=Custom%20Providers" # image for socials
4 +keywords: ""
5 +hide-nav-links: false
6 +---
fern/pages/src/providers/ts-custom.mdx renamed
+2 -2
@@ -1,11 +1,11 @@
1 ---
2 -title: Custom Providers
2 +title: TypeScript Custom Provider
3 image: "https://og.composio.dev/api/og?title=Custom%20Providers" # image for socials
4 keywords: ""
5 hide-nav-links: false
6 ---
7
8 -This guide provides a comprehensive walkthrough of creating custom providers for the Composio SDK, enabling integration with different AI frameworks and platforms.
8 +This guide provides a comprehensive walkthrough of creating custom providers for the Composio TypeScriptSDK, enabling integration with different AI frameworks and platforms.
9
10 ## Provider Architecture
11
fern/pages/src/tool-calling/after-execution-modifiers.mdx
+54 -54
@@ -33,6 +33,41 @@ Since completion providers don't have a function execution step -- Composio will
33 Hence, the modifier is configured on the `tools.execute` method.
34
35 <CodeGroup>
36 +```python Python maxLines=60 wordWrap
37 +from composio import Composio, after_execute
38 +from composio.types import ToolExecutionResponse
39 +
40 +@after_execute(tools=["HACKERNEWS_GET_USER"])
41 +def after_execute_modifier(
42 + tool: str,
43 + toolkit: str,
44 + response: ToolExecutionResponse,
45 +) -> ToolExecutionResponse:
46 + return {
47 + **response,
48 + "data": {
49 + "karama": response["data"]["karama"],
50 + },
51 + }
52 +
53 +# Get response from the LLM
54 +response = openai_client.chat.completions.create(
55 + model="gpt-4o-mini",
56 + tools=tools,
57 + messages=messages,
58 +)
59 +print(response)
60 +
61 +# Execute the function calls.
62 +result = composio.provider.handle_tool_calls(
63 + response=response,
64 + user_id="default",
65 + modifiers=[
66 + after_execute_modifier,
67 + ]
68 +)
69 +print(result)
70 +```
71 ```typescript TypeScript maxLines=60 wordWrap
72 const response = await openai.chat.completions.create({
73 model: "gpt-4o-mini",
@@ -73,9 +108,20 @@ if (tool_calls) {
108 }
109
110 ```
76 -```python Python maxLines=60 wordWrap
111 +
112 +</CodeGroup>
113 +</Tab>
114 +
115 +<Tab title="With Agentic Frameworks">
116 +Agentic providers have a function execution step.
117 +The modifier is configured on the `tools.get` method which modifies the execution logic within the framework!
118 +<CodeGroup>
119 +```python Python (CrewAI) maxLines=60 wordWrap
120 from composio import Composio, after_execute
121 from composio.types import ToolExecutionResponse
122 +from composio_crewai import CrewAIProvider
123 +
124 +composio = Composio(provider=CrewAIProvider())
125
126 @after_execute(tools=["HACKERNEWS_GET_USER"])
127 def after_execute_modifier(
@@ -86,36 +132,19 @@ def after_execute_modifier(
132 return {
133 **response,
134 "data": {
89 - "karama": response["data"]["karama"],
135 + "karma": response["data"]["karma"],
136 },
137 }
138
93 -# Get response from the LLM
94 -response = openai_client.chat.completions.create(
95 - model="gpt-4o-mini",
96 - tools=tools,
97 - messages=messages,
98 -)
99 -print(response)
139
101 -# Execute the function calls.
102 -result = composio.provider.handle_tool_calls(
103 - response=response,
104 - user_id="default",
105 - modifiers=[
106 - after_execute_modifier,
107 - ]
140 +tools = composio.tools.get(
141 + user_id="default",
142 + slug="HACKERNEWS_GET_USER",
143 + modifiers=[
144 + after_execute_modifier,
145 + ]
146 )
109 -print(result)
147 ```
111 -
112 -</CodeGroup>
113 -</Tab>
114 -
115 -<Tab title="With Agentic Frameworks">
116 -Agentic providers have a function execution step.
117 -The modifier is configured on the `tools.get` method which modifies the execution logic within the framework!
118 -<CodeGroup>
148 ```typescript TypeScript (Vercel) maxLines=60 wordWrap {24-27}
149 import { Composio } from "@composio/core";
150 import { VercelProvider } from "@composio/vercel";
@@ -151,35 +180,6 @@ const agenticTools = await composio.tools.get(
180 }
181 );
182
154 -```
155 -```python Python (CrewAI) maxLines=60 wordWrap
156 -from composio import Composio, after_execute
157 -from composio.types import ToolExecutionResponse
158 -from composio_crewai import CrewAIProvider
159 -
160 -composio = Composio(provider=CrewAIProvider())
161 -
162 -@after_execute(tools=["HACKERNEWS_GET_USER"])
163 -def after_execute_modifier(
164 - tool: str,
165 - toolkit: str,
166 - response: ToolExecutionResponse,
167 -) -> ToolExecutionResponse:
168 - return {
169 - **response,
170 - "data": {
171 - "karama": response["data"]["karama"],
172 - },
173 - }
174 -
175 -
176 -tools = composio.tools.get(
177 - user_id="default",
178 - slug="HACKERNEWS_GET_USER",
179 - modifiers=[
180 - after_execute_modifier,
181 - ]
182 -)
183 ```
184
185 </CodeGroup>
fern/pages/src/tool-calling/authenticating-tools.mdx
+20 -20
@@ -66,16 +66,16 @@ Here's how to authenticate a toolkit for a given user using the OAuth flow.
66
67 <CodeGroup>
68 <SnippetCode
69 - src="fern/snippets/tool-calling/typescript/auth-tools.ts"
69 + src="fern/snippets/tool-calling/python/auth-tools.py"
70 startLine={1}
71 endLine={21}
72 - title="TypeScript"
72 + title="Python"
73 />
74 <SnippetCode
75 - src="fern/snippets/tool-calling/python/auth-tools.py"
75 + src="fern/snippets/tool-calling/typescript/auth-tools.ts"
76 startLine={1}
77 endLine={21}
78 - title="Python"
78 + title="TypeScript"
79 />
80 </CodeGroup>
81
@@ -88,18 +88,18 @@ For API key based toolkits, you can either request the user to provide the API k
88 If you know the required authentication fields for your toolkit (like `apiKey` for most API-based services), you can directly create the connection:
89
90 <CodeGroup>
91 -<SnippetCode
92 - src="fern/snippets/tool-calling/typescript/auth-tools.ts"
93 - startLine={24}
94 - endLine={37}
95 - title="TypeScript"
96 -/>
91 <SnippetCode
92 src="fern/snippets/tool-calling/python/auth-tools.py"
93 startLine={23}
94 endLine={31}
95 title="Python"
96 />
97 +<SnippetCode
98 + src="fern/snippets/tool-calling/typescript/auth-tools.ts"
99 + startLine={24}
100 + endLine={37}
101 + title="TypeScript"
102 +/>
103 </CodeGroup>
104
105 ## Specifying auth schemes
@@ -112,18 +112,18 @@ The auth scheme information is typed and can be configured as follows:
112
113
114 <CodeGroup>
115 -<SnippetCode
116 - src="fern/snippets/tool-calling/typescript/auth-tools.ts"
117 - startLine={38}
118 - endLine={50}
119 - title="TypeScript"
120 -/>
115 <SnippetCode
116 src="fern/snippets/tool-calling/python/auth-tools.py"
117 startLine={32}
118 endLine={44}
119 title="Python"
120 />
121 +<SnippetCode
122 + src="fern/snippets/tool-calling/typescript/auth-tools.ts"
123 + startLine={38}
124 + endLine={50}
125 + title="TypeScript"
126 +/>
127 </CodeGroup>
128
129 It might be useful to read all the optional and required auth config fields for a toolkit and optionally prompt the user for the values.
@@ -136,15 +136,15 @@ In this case, the user will be redirected to `https://www.yourapp.com/callback`
136
137 <CodeGroup>
138 <SnippetCode
139 - src="fern/snippets/tool-calling/typescript/callback-url.ts"
139 + src="fern/snippets/tool-calling/python/callback-url.py"
140 startLine={10}
141 endLine={20}
142 - title="TypeScript"
142 + title="Python"
143 />
144 <SnippetCode
145 - src="fern/snippets/tool-calling/python/callback-url.py"
145 + src="fern/snippets/tool-calling/typescript/callback-url.ts"
146 startLine={10}
147 endLine={20}
148 - title="Python"
148 + title="TypeScript"
149 />
150 </CodeGroup>
fern/pages/src/tool-calling/before-execution-modifiers.mdx
+63 -63
@@ -33,6 +33,46 @@ Since completion providers don't have a function execution step -- Composio will
33 Hence, the modifier is configured on the `tools.execute` method.
34
35 <CodeGroup>
36 +```python Python maxLines=60 wordWrap
37 +from openai import OpenAI
38 +from composio import Composio, before_execute
39 +from composio.types import ToolExecuteParams
40 +
41 +composio = Composio()
42 +openai_client = OpenAI()
43 +user_id = "user@email.com"
44 +
45 +@before_execute(tools=["HACKERNEWS_GET_LATEST_POSTS"])
46 +def before_execute_modifier(
47 + tool: str,
48 + toolkit: str,
49 + params: ToolExecuteParams,
50 +) -> ToolExecuteParams:
51 + params["arguments"]["size"] = 1
52 + return params
53 +
54 +
55 +# Get tools
56 +tools = composio.tools.get(user_id=user_id, slug="HACKERNEWS_GET_LATEST_POSTS")
57 +
58 +# Get response from the LLM
59 +response = openai_client.chat.completions.create(
60 + model="gpt-4o-mini",
61 + tools=tools,
62 + messages=[{"role": "user", "content": "Fetch latest posts from hackernews"}],
63 +)
64 +print(response)
65 +
66 +# Execute the function calls.
67 +result = composio.provider.handle_tool_calls(
68 + response=response,
69 + user_id="default",
70 + modifiers=[
71 + before_execute_modifier,
72 + ],
73 +)
74 +print(result)
75 +```
76 ```typescript TypeScript maxLines=60 wordWrap {11, 20-28}
77 const response = await openai.chat.completions.create({
78 model: "gpt-4o-mini",
@@ -69,55 +109,43 @@ if (tool_calls) {
109 }
110
111 ```
72 -```python Python maxLines=60 wordWrap
73 -from openai import OpenAI
112 +
113 +</CodeGroup>
114 +</Tab>
115 +
116 +<Tab title="With Agentic Frameworks">
117 +Agentic providers have a function execution step.
118 +The modifier is configured on the `tools.get` method which modifies the execution logic within the framework!
119 +
120 +<CodeGroup>
121 +```python Python (CrewAI) maxLines=60 wordWrap
122 from composio import Composio, before_execute
123 from composio.types import ToolExecuteParams
124 +from composio_crewai import CrewAIProvider
125
77 -composio = Composio()
78 -openai_client = OpenAI()
79 -user_id = "user@email.com"
126 +composio = Composio(provider=CrewAIProvider())
127
81 -@before_execute(tools=["HACKERNEWS_GET_LATEST_POSTS"])
82 -def before_execute_modifier(
128 +@before_execute(tools=["LINEAR_CREATE_LINEAR_ISSUE"])
129 +def modify_linear_project_id(
130 tool: str,
131 toolkit: str,
132 params: ToolExecuteParams,
133 ) -> ToolExecuteParams:
87 - params["arguments"]["size"] = 1
134 + params["arguments"]["project_id"] = "1234567890"
135 return params
136
90 -
91 -# Get tools
92 -tools = composio.tools.get(user_id=user_id, slug="HACKERNEWS_GET_LATEST_POSTS")
93 -
94 -# Get response from the LLM
95 -response = openai_client.chat.completions.create(
96 - model="gpt-4o-mini",
97 - tools=tools,
98 - messages=[{"role": "user", "content": "Fetch latest posts from hackernews"}],
99 -)
100 -print(response)
101 -
102 -# Execute the function calls.
103 -result = composio.provider.handle_tool_calls(
104 - response=response,
137 +tools = composio.tools.get(
138 user_id="default",
106 - modifiers=[
107 - before_execute_modifier,
139 + tools=[
140 + "HACKERNEWS_GET_LATEST_POSTS",
141 + "HACKERNEWS_GET_USER",
142 + "LINEAR_CREATE_LINEAR_ISSUE",
143 ],
144 + modifiers=[
145 + after_execute_modifier,
146 + ]
147 )
110 -print(result)
148 ```
112 -
113 -</CodeGroup>
114 -</Tab>
115 -
116 -<Tab title="With Agentic Frameworks">
117 -Agentic providers have a function execution step.
118 -The modifier is configured on the `tools.get` method which modifies the execution logic within the framework!
119 -
120 -<CodeGroup>
149 ```typescript TypeScript (Mastra) maxLines=60 wordWrap {22-26}
150 import { Composio } from "@composio/core";
151 import { MastraProvider } from "@composio/mastra";
@@ -158,34 +186,6 @@ const { text } = await generateText({
186 maxSteps: 5,
187 });
188
161 -```
162 -```python Python (CrewAI) maxLines=60 wordWrap
163 -from composio import Composio, before_execute
164 -from composio.types import ToolExecuteParams
165 -from composio_crewai import CrewAIProvider
166 -
167 -composio = Composio(provider=CrewAIProvider())
168 -
169 -@before_execute(tools=["LINEAR_CREATE_LINEAR_ISSUE"])
170 -def modify_linear_project_id(
171 - tool: str,
172 - toolkit: str,
173 - params: ToolExecuteParams,
174 -) -> ToolExecuteParams:
175 - params["arguments"]["project_id"] = "1234567890"
176 - return params
177 -
178 -tools = composio.tools.get(
179 - user_id="default",
180 - tools=[
181 - "HACKERNEWS_GET_LATEST_POSTS",
182 - "HACKERNEWS_GET_USER",
183 - "LINEAR_CREATE_LINEAR_ISSUE",
184 - ],
185 - modifiers=[
186 - after_execute_modifier,
187 - ]
188 -)
189 ```
190
191 </CodeGroup>
fern/pages/src/tool-calling/custom-tools.mdx
+38 -38
@@ -203,6 +203,37 @@ def get_issue_info_direct(
203 You can add custom headers and query parameters to your toolkit-based tools using the `parameters` option in `executeToolRequest`:
204
205 <CodeGroup>
206 +```python Python maxLines=60 wordWrap
207 +@composio.tools.custom_tool(toolkit="github")
208 +def get_issue_info(
209 + request: GetIssueInfoInput,
210 + execute_request: ExecuteRequestFn,
211 + auth_credentials: dict,
212 +) -> dict:
213 + """Get information about a GitHub issue."""
214 + response = execute_request(
215 + endpoint=f"/repos/composiohq/composio/issues/{request.issue_number}",
216 + method="GET",
217 + parameters=[
218 + {
219 + "name": "Accept",
220 + "value": "application/vnd.github.v3+json",
221 + "type": "header",
222 + },
223 + {
224 + "name": "Authorization",
225 + "value": f"Bearer {auth_credentials['access_token']}",
226 + "type": "header",
227 + },
228 + {
229 + "name": 'X-Custom-Header',
230 + "value": 'custom-value',
231 + "type": 'header',
232 + },
233 + ],
234 + )
235 + return {"data": response.data}
236 +```
237 ```typescript TypeScript maxLines=60
238 const tool = await composio.tools.createCustomTool({
239 slug: 'GITHUB_SEARCH_REPOSITORIES',
@@ -247,37 +278,6 @@ const tool = await composio.tools.createCustomTool({
278 },
279 });
280 ```
250 -```python Python maxLines=60 wordWrap
251 -@composio.tools.custom_tool(toolkit="github")
252 -def get_issue_info(
253 - request: GetIssueInfoInput,
254 - execute_request: ExecuteRequestFn,
255 - auth_credentials: dict,
256 -) -> dict:
257 - """Get information about a GitHub issue."""
258 - response = execute_request(
259 - endpoint=f"/repos/composiohq/composio/issues/{request.issue_number}",
260 - method="GET",
261 - parameters=[
262 - {
263 - "name": "Accept",
264 - "value": "application/vnd.github.v3+json",
265 - "type": "header",
266 - },
267 - {
268 - "name": "Authorization",
269 - "value": f"Bearer {auth_credentials['access_token']}",
270 - "type": "header",
271 - },
272 - {
273 - "name": 'X-Custom-Header',
274 - "value": 'custom-value',
275 - "type": 'header',
276 - },
277 - ],
278 - )
279 - return {"data": response.data}
280 -```
281 </CodeGroup>
282
283 ## Executing Custom Tools
@@ -285,6 +285,13 @@ def get_issue_info(
285 You can execute custom tools just like any other tool:
286
287 <CodeGroup>
288 +```python Python maxLines=60 wordWrap
289 +response = composio.tools.execute(
290 + user_id="default",
291 + slug="TOOL_SLUG", # For the tool above you can use `get_issue_info.slug`
292 + arguments={"issue_number": 1},
293 +)
294 +```
295 ```typescript TypeScript maxLines=60 wordWrap
296 const result = await composio.tools.execute('TOOL_SLUG', {
297 arguments: {
@@ -294,13 +301,6 @@ const result = await composio.tools.execute('TOOL_SLUG', {
301 connectedAccountId: 'optional-account-id', // Required for toolkit-based tools
302 });
303 ```
297 -```python Python maxLines=60 wordWrap
298 -response = composio.tools.execute(
299 - user_id="default",
300 - slug="TOOL_SLUG", # For the tool above you can use `get_issue_info.slug`
301 - arguments={"issue_number": 1},
302 -)
303 -```
304 </CodeGroup>
305
306 ## Best Practices
fern/pages/src/tool-calling/executing-tools.mdx
+68 -72
@@ -15,22 +15,20 @@ This approach works consistently across all supported non-agent providers.
15 To learn how to setup these providers, see [Providers](/providers).
16
17 <CodeGroup>
18 -<SnippetCode
19 - src="fern/snippets/tool-calling/typescript/exec-tool-completions.ts"
20 - startLine={1}
21 - endLine={30}
22 - title="TypeScript (Anthropic)"
23 -/>
24 -
18 <SnippetCode
19 src="fern/snippets/tool-calling/python/exec-tool-completions.py"
20 startLine={1}
21 endLine={25}
22 title="Python (Google)"
23 />
24 +<SnippetCode
25 + src="fern/snippets/tool-calling/typescript/exec-tool-completions.ts"
26 + startLine={1}
27 + endLine={30}
28 + title="TypeScript (Anthropic)"
29 +/>
30 </CodeGroup>
31
33 -
32 ## Using Agentic Frameworks
33 Composio also has first-party support for agentic frameworks which execute tools, feed the result to the LLM and continue the conversation.
34
@@ -40,19 +38,18 @@ Here, the tool execution is handled by the agentic framework. Composio makes sur
38 </Tip>
39
40 <CodeGroup>
43 -<SnippetCode
44 - src="fern/snippets/tool-calling/typescript/exec-tool-agentic.ts"
45 - startLine={1}
46 - endLine={30}
47 - title="TypeScript (Anthropic)"
48 -/>
49 -
41 <SnippetCode
42 src="fern/snippets/tool-calling/python/exec-tool-agentic.py"
43 startLine={1}
44 endLine={37}
45 title="Python (OpenAI Agents SDK)"
46 />
47 +<SnippetCode
48 + src="fern/snippets/tool-calling/typescript/exec-tool-agentic.ts"
49 + startLine={1}
50 + endLine={30}
51 + title="TypeScript (Anthropic)"
52 +/>
53 </CodeGroup>
54
55 ## Tools are scoped to a user
@@ -67,19 +64,6 @@ For more information on authentication, see [Authenticating Tools](./authenticat
64 In case you just want to call a tool manually -- not using any framework or LLM provider, you can do so using the `execute` method.
65
66 <CodeGroup>
70 -```typescript TypeScript maxLines=60 wordWrap
71 -const userId = "user@example.com";
72 -const composio = new Composio();
73 -
74 -const result = await composio.tools.execute("HACKERNEWS_GET_USER", {
75 - userId,
76 - arguments: {
77 - username: "pg",
78 - },
79 -});
80 -console.log(result);
81 -```
82 -
67 ```python Python maxLines=60 wordWrap
68
69 user_id = "user@example.com"
@@ -92,24 +76,24 @@ result = composio.tools.execute(
76 )
77 print(result)
78 ```
79 +```typescript TypeScript maxLines=60 wordWrap
80 +const userId = "user@example.com";
81 +const composio = new Composio();
82 +
83 +const result = await composio.tools.execute("HACKERNEWS_GET_USER", {
84 + userId,
85 + arguments: {
86 + username: "pg",
87 + },
88 +});
89 +console.log(result);
90 +```
91 </CodeGroup>
92
93 ### Proxy Execute -- Manually calling toolkit APIs
94 You can also proxy requests to an API of any supported toolkit. This is useful when you want to manually call an API of a toolkit and inject the authentication state from Composio.
95
96 <CodeGroup>
101 -```typescript TypeScript maxLines=60 wordWrap
102 -// Send a custom request to a toolkit
103 -const { data } = await composio.tools.proxyExecute({
104 - toolkitSlug: 'github',
105 - userId: 'user@example.com',
106 - data: {
107 - endpoint: '/repos/owner/repo/issues',
108 - method: 'GET'
109 - }
110 -});
111 -console.log(data);
112 -```
97 ```python Python maxLines=60 wordWrap
98 response = composio.tools.proxy(
99 endpoint="/repos/composiohq/composio/issues/1",
@@ -124,6 +108,18 @@ response = composio.tools.proxy(
108 ],
109 )
110 ```
111 +```typescript TypeScript maxLines=60 wordWrap
112 +// Send a custom request to a toolkit
113 +const { data } = await composio.tools.proxyExecute({
114 + toolkitSlug: 'github',
115 + userId: 'user@example.com',
116 + data: {
117 + endpoint: '/repos/owner/repo/issues',
118 + method: 'GET'
119 + }
120 +});
121 +console.log(data);
122 +```
123 </CodeGroup>
124
125 If you're interested in extending toolkits and creating custom tools, see [Custom tools](/docs/custom-tools).
@@ -137,25 +133,6 @@ Composio SDK includes automatic file handling for tools that work with files. Wh
133 When a tool accepts file inputs (marked with `file_uploadable: true`), you can pass local file paths or URLs. Here's an example using Google Drive upload:
134
135 <CodeGroup>
140 -```typescript TypeScript maxLines=60 wordWrap
141 -import { Composio } from '@composio/core';
142 -import path from 'path';
143 -
144 -const composio = new Composio({
145 - apiKey: process.env.COMPOSIO_API_KEY
146 -});
147 -
148 -// Upload a local file to Google Drive
149 -const result = await composio.tools.execute('GOOGLEDRIVE_UPLOAD_FILE', {
150 - userId: 'default',
151 - arguments: {
152 - file_to_upload: path.join(__dirname, 'document.pdf') // Local file path
153 - }
154 -});
155 -
156 -console.log(result.data); // Contains Google Drive file details
157 -```
158 -
136 ```python Python maxLines=60 wordWrap
137 import os
138
@@ -174,6 +151,25 @@ result = composio.tools.execute(
151
152 print(result.data) # Contains Google Drive file details
153 ```
154 +
155 +```typescript TypeScript maxLines=60 wordWrap
156 +import { Composio } from '@composio/core';
157 +import path from 'path';
158 +
159 +const composio = new Composio({
160 + apiKey: process.env.COMPOSIO_API_KEY
161 +});
162 +
163 +// Upload a local file to Google Drive
164 +const result = await composio.tools.execute('GOOGLEDRIVE_UPLOAD_FILE', {
165 + userId: 'default',
166 + arguments: {
167 + file_to_upload: path.join(__dirname, 'document.pdf') // Local file path
168 + }
169 +});
170 +
171 +console.log(result.data); // Contains Google Drive file details
172 +```
173 </CodeGroup>
174
175 The SDK automatically:
@@ -188,19 +184,6 @@ When a tool returns file outputs, the SDK automatically:
184 2. Provides the local file path in the response
185
186 <CodeGroup>
191 -```typescript TypeScript maxLines=60 wordWrap
192 -// Download a file from Google Drive
193 -const result = await composio.tools.execute('GOOGLEDRIVE_DOWNLOAD_FILE', {
194 - userId: 'default',
195 - arguments: {
196 - file_id: 'your_file_id'
197 - }
198 -});
199 -
200 -// Result includes local file path
201 -console.log(result.data.file.uri); // "/path/to/downloaded/file.pdf"
202 -```
203 -
187 ```python Python maxLines=60 wordWrap
188 # Download a file from Google Drive
189 result = composio.tools.execute(
@@ -214,6 +197,19 @@ result = composio.tools.execute(
197 # Result includes local file path
198 print(result.data["file"]) # "/path/to/downloaded/file.pdf"
199 ```
200 +
201 +```typescript TypeScript maxLines=60 wordWrap
202 +// Download a file from Google Drive
203 +const result = await composio.tools.execute('GOOGLEDRIVE_DOWNLOAD_FILE', {
204 + userId: 'default',
205 + arguments: {
206 + file_id: 'your_file_id'
207 + }
208 +});
209 +
210 +// Result includes local file path
211 +console.log(result.data.file.uri); // "/path/to/downloaded/file.pdf"
212 +```
213 </CodeGroup>
214
215 ### Disabling Auto File Handling
fern/pages/src/tool-calling/fetching-tools.mdx
+48 -48
@@ -24,6 +24,13 @@ Composio determines the importance of a tool based on the usage and relevance of
24 </Tip>
25
26 <CodeGroup>
27 +```python Python maxLines=60 wordWrap
28 +tools = composio.tools.get(
29 + user_id,
30 + toolkits=["GITHUB", "HACKERNEWS"],
31 +)
32 +```
33 +
34 ```typescript TypeScript maxLines=60 wordWrap
35 const tools = await composio.tools.get(
36 userId,
@@ -32,13 +39,6 @@ const tools = await composio.tools.get(
39 }
40 );
41 ```
35 -
36 -```python Python maxLines=60 wordWrap
37 -tools = composio.tools.get(
38 - user_id,
39 - toolkits=["GITHUB", "HACKERNEWS"],
40 -)
41 -```
42 </CodeGroup>
43
44 **Limiting the results**
@@ -48,12 +48,6 @@ Multiple toolkits have 100s of tools. These can easily overwhelm the LLM. Hence,
48 The default `limit` is 20 -- meaning you get the top 20 important tools from the toolkit.
49
50 <CodeGroup>
51 -```typescript TypeScript maxLines=60 wordWrap
52 -const tools = await composio.tools.get(userId, {
53 - toolkits: ["GITHUB"],
54 - limit: 5, // Returns the top 5 important tools from the toolkit
55 -});
56 -```
51 ```python Python maxLines=60 wordWrap
52 tools = composio.tools.get(
53 user_id,
@@ -61,6 +55,12 @@ tools = composio.tools.get(
55 limit=5, # Returns the top 5 important tools from the toolkit
56 )
57 ```
58 +```typescript TypeScript maxLines=60 wordWrap
59 +const tools = await composio.tools.get(userId, {
60 + toolkits: ["GITHUB"],
61 + limit: 5, // Returns the top 5 important tools from the toolkit
62 +});
63 +```
64 </CodeGroup>
65
66 **Filtering by scopes**
@@ -75,14 +75,6 @@ Scope filtering can only be used with a single toolkit at a time.
75 </Tip>
76
77 <CodeGroup>
78 -```typescript TypeScript maxLines=60 wordWrap
79 -// Get GitHub tools that require specific scopes
80 -const tools = await composio.tools.get(userId, {
81 - toolkits: ["GITHUB"],
82 - scopes: ["repo"], // Only get tools requiring these scopes
83 - limit: 10
84 -});
85 -```
78 ```python Python maxLines=60 wordWrap
79 # Get GitHub tools that require specific scopes
80 tools = composio.tools.get(
@@ -92,6 +84,14 @@ tools = composio.tools.get(
84 limit=10
85 )
86 ```
87 +```typescript TypeScript maxLines=60 wordWrap
88 +// Get GitHub tools that require specific scopes
89 +const tools = await composio.tools.get(userId, {
90 + toolkits: ["GITHUB"],
91 + scopes: ["repo"], // Only get tools requiring these scopes
92 + limit: 10
93 +});
94 +```
95 </CodeGroup>
96
97 ## Filtering by tool
@@ -99,16 +99,6 @@ You may specify the list of tools to fetch by directly providing the tool names.
99
100 <CodeGroup>
101
102 -```typescript TypeScript maxLines=60 wordWrap
103 -const tools = await composio.tools.get(userId, {
104 - tools: [
105 - "GITHUB_CREATE_AN_ISSUE",
106 - "GITHUB_CREATE_AN_ISSUE_COMMENT",
107 - "GITHUB_CREATE_A_COMMIT",
108 - ],
109 -});
110 -```
111 -
102 ```python Python maxLines=60 wordWrap
103 tools = composio.tools.get(
104 user_id,
@@ -119,6 +109,16 @@ tools = composio.tools.get(
109 ],
110 )
111 ```
112 +
113 +```typescript TypeScript maxLines=60 wordWrap
114 +const tools = await composio.tools.get(userId, {
115 + tools: [
116 + "GITHUB_CREATE_AN_ISSUE",
117 + "GITHUB_CREATE_AN_ISSUE_COMMENT",
118 + "GITHUB_CREATE_A_COMMIT",
119 + ],
120 +});
121 +```
122 </CodeGroup>
123
124 ## Fetching raw tools
@@ -130,16 +130,16 @@ To examine the raw schema definitition of a tool to understand the input/output
130
131 <CodeGroup>
132 <SnippetCode
133 - src="fern/snippets/tool-calling/typescript/raw_tools.ts"
133 + src="fern/snippets/tool-calling/python/raw_tools.py"
134 startLine={5}
135 endLine={7}
136 - title="TypeScript"
136 + title="Python"
137 />
138 <SnippetCode
139 - src="fern/snippets/tool-calling/python/raw_tools.py"
139 + src="fern/snippets/tool-calling/typescript/raw_tools.ts"
140 startLine={5}
141 endLine={7}
142 - title="Python"
142 + title="TypeScript"
143 />
144 </CodeGroup>
145
@@ -150,19 +150,6 @@ You may also filter tools by searching for them. This is a good way to find tool
150 This step runs a semantic search on the tool names and descriptions and returns the most relevant tools.
151
152 <CodeGroup>
153 -```typescript TypeScript maxLines=60 wordWrap
154 -const tools = await composio.tools.get(userId, {
155 - search: "hubspot organize contacts",
156 -});
157 -
158 -// Search within a specific toolkit
159 -const tools = await composio.tools.get(userId, {
160 - search: "repository issues",
161 - toolkits: ["GITHUB"], // Optional: limit search to specific toolkit
162 - limit: 5 // Optional: limit number of results
163 -});
164 -```
165 -
153 ```python Python maxLines=60 wordWrap
154 tools = composio.tools.get(
155 user_id,
@@ -177,6 +164,19 @@ tools = composio.tools.get(
164 limit=5 # Optional: limit number of results
165 )
166 ```
167 +
168 +```typescript TypeScript maxLines=60 wordWrap
169 +const tools = await composio.tools.get(userId, {
170 + search: "hubspot organize contacts",
171 +});
172 +
173 +// Search within a specific toolkit
174 +const tools = await composio.tools.get(userId, {
175 + search: "repository issues",
176 + toolkits: ["GITHUB"], // Optional: limit search to specific toolkit
177 + limit: 5 // Optional: limit number of results
178 +});
179 +```
180 </CodeGroup>
181
182 ## Filter Combinations
fern/pages/src/tool-calling/schema-modifiers.mdx
+65 -65
@@ -27,6 +27,30 @@ Schema modifiers transform a tool's schema before the tool is seen by an agent.
27 </Note>
28
29 <CodeGroup>
30 +```python Python maxLines=60 wordWrap
31 +from composio import Composio, schema_modifier
32 +from composio.types import Tool
33 +
34 +user_id = "your@email.com"
35 +
36 +@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])
37 +def modify_schema(
38 + tool: str,
39 + toolkit: str,
40 + schema: Tool,
41 +) -> Tool:
42 + _ = schema.input_parameters["properties"].pop("page", None)
43 + schema.input_parameters["required"] = ["size"]
44 + return schema
45 +
46 +tools = composio.tools.get(
47 + user_id=user_id,
48 + tools=["HACKERNEWS_GET_LATEST_POSTS", "HACKERNEWS_GET_USER"],
49 + modifiers=[
50 + modify_schema,
51 + ]
52 +)
53 +```
54 ```typescript TypeScript maxLines=60 wordWrap
55 const userId = "your@email.com";
56
@@ -52,11 +76,23 @@ const tools = await composio.tools.get(
76 console.log(JSON.stringify(tools, null, 2));
77
78 ```
55 -```python Python maxLines=60 wordWrap
79 +
80 +</CodeGroup>
81 +
82 +In using the above modified tool schema, the `page` argument is removed and the `size` argument is required.
83 +
84 +You can test this out by viewing the tool call response in the LLM too!
85 +
86 +<Accordion title="Schema modified tool call">
87 +<CodeGroup>
88 +
89 +```python Python maxLines=60 wordWrap
90 +
91 +from openai import OpenAI
92 from composio import Composio, schema_modifier
93 from composio.types import Tool
94 +from composio_openai import OpenAIProvider
95
59 -user_id = "your@email.com"
96
97 @schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])
98 def modify_schema(
@@ -68,23 +104,37 @@ def modify_schema(
104 schema.input_parameters["required"] = ["size"]
105 return schema
106
71 -tools = composio.tools.get(
72 - user_id=user_id,
73 - tools=["HACKERNEWS_GET_LATEST_POSTS", "HACKERNEWS_GET_USER"],
74 - modifiers=[
75 - modify_schema,
76 - ]
77 -)
78 -```
107 +# Initialize tools.
108 +openai_client = OpenAI()
109 +composio = Composio(provider=OpenAIProvider())
110
80 -</CodeGroup>
111 +# Define task.
112 +task = "Get the latest posts from Hacker News"
113
82 -In using the above modified tool schema, the `page` argument is removed and the `size` argument is required.
114 +# Get GitHub tools that are pre-configured
115 +tools = composio.tools.get(
116 + user_id="default",
117 + tools=['HACKERNEWS_GET_LATEST_POSTS', 'HACKERNEWS_GET_USER'],
118 + modifiers=[
119 + modify_schema,
120 + ],
121 +)
122
84 -You can test this out by viewing the tool call response in the LLM too!
123 +# Get response from the LLM
124 +response = openai_client.chat.completions.create(
125 + model="gpt-4o-mini",
126 + tools=tools,
127 + messages=[
128 + {"role": "system", "content": "You are a helpful assistant."},
129 + {"role": "user", "content": task},
130 + ],
131 +)
132 +print(response)
133
86 -<Accordion title="Schema modified tool call">
87 -<CodeGroup>
134 +# Execute the function calls.
135 +result = composio.provider.handle_tool_calls(response=response, user_id="default")
136 +print(result)
137 +```
138
139 ```typescript TypeScript maxLines=60 wordWrap
140 import { Composio } from '@composio/core';
@@ -134,55 +184,5 @@ const response = await openai.chat.completions.create({
184 console.log(response.choices[0].message.tool_calls);
185 ```
186
137 -```python Python maxLines=60 wordWrap
138 -
139 -from openai import OpenAI
140 -from composio import Composio, schema_modifier
141 -from composio.types import Tool
142 -from composio_openai import OpenAIProvider
143 -
144 -
145 -@schema_modifier(tools=["HACKERNEWS_GET_LATEST_POSTS"])
146 -def modify_schema(
147 - tool: str,
148 - toolkit: str,
149 - schema: Tool,
150 -) -> Tool:
151 - _ = schema.input_parameters["properties"].pop("page", None)
152 - schema.input_parameters["required"] = ["size"]
153 - return schema
154 -
155 -# Initialize tools.
156 -openai_client = OpenAI()
157 -composio = Composio(provider=OpenAIProvider())
158 -
159 -# Define task.
160 -task = "Star a repo composiohq/composio on GitHub"
161 -
162 -# Get GitHub tools that are pre-configured
163 -tools = composio.tools.get(
164 - user_id="default",
165 - tools=['HACKERNEWS_GET_LATEST_POSTS', 'HACKERNEWS_GET_USER'],
166 - modifiers=[
167 - modify_schema,
168 - ],
169 -)
170 -
171 -# Get response from the LLM
172 -response = openai_client.chat.completions.create(
173 - model="gpt-4o-mini",
174 - tools=tools,
175 - messages=[
176 - {"role": "system", "content": "You are a helpful assistant."},
177 - {"role": "user", "content": task},
178 - ],
179 -)
180 -print(response)
181 -
182 -# Execute the function calls.
183 -result = composio.provider.handle_tool_calls(response=response, user_id="default")
184 -print(result)
185 -```
186 -
187 </CodeGroup>
188 </Accordion>
fern/pages/src/triggers/using-triggers.mdx
+55 -55
@@ -56,12 +56,6 @@ First, you can view the required configuration to make the trigger too as follow
56 To create a trigger, first fetch the user's connection ID, then use it along with the required configuration.
57
58 <CodeGroup>
59 -<SnippetCode
60 - src="fern/snippets/triggers/typescript/triggers.ts"
61 - startLine={28}
62 - endLine={40}
63 - title="TypeScript (new)"
64 -/>
59 ```python Python
60 instance = composio.triggers.create(
61 slug="GITHUB_COMMIT_EVENT",
@@ -73,6 +67,12 @@ instance = composio.triggers.create(
67 )
68 print(instance)
69 ```
70 +<SnippetCode
71 + src="fern/snippets/triggers/typescript/triggers.ts"
72 + startLine={28}
73 + endLine={40}
74 + title="TypeScript (new)"
75 +/>
76 </CodeGroup>
77
78
@@ -85,14 +85,6 @@ When you specify multiple multiple filters, _ALL_ of them must match for the tri
85 This method uses websockets to subscribe to the trigger.
86
87 <CodeGroup>
88 -<SnippetCode
89 -src="fern/snippets/triggers/typescript/triggers.ts"
90 -startLine={42}
91 -endLine={53}
92 -title="TypeScript (new)"
93 -/>
94 -
95 -
88 ```python Python
89 # Fetch connected account for user
90 user_id = "user@acme.com"
@@ -115,6 +107,13 @@ instance = composio.triggers.create(
107 print(instance)
108 ```
109
110 +<SnippetCode
111 +src="fern/snippets/triggers/typescript/triggers.ts"
112 +startLine={42}
113 +endLine={53}
114 +title="TypeScript (new)"
115 +/>
116 +
117 </CodeGroup>
118
119
@@ -128,13 +127,13 @@ To receive trigger events via webhooks, you need to configure a publicly accessi
127 <CodeGroup>
128
129 <SnippetCode
131 - src="fern/snippets/triggers/typescript/trigger-webhook.ts"
132 - title="app/api/webhook/route.ts"
130 + src="fern/snippets/triggers/python/trigger-webhook.py"
131 + title="app/route.py"
132 />
133
134 <SnippetCode
136 - src="fern/snippets/triggers/python/trigger-webhook.py"
137 - title="app/route.py"
135 + src="fern/snippets/triggers/typescript/trigger-webhook.ts"
136 + title="app/api/webhook/route.ts"
137 />
138
139 </CodeGroup>
@@ -143,18 +142,18 @@ To receive trigger events via webhooks, you need to configure a publicly accessi
142 When subscribing to triggers, it is helpful to know the payload type recieved from the trigger. You can inspect the payload type by fetching the trigger type.
143
144 <CodeGroup>
146 -```typescript TypeScript maxLines=60 wordWrap
147 -const triggerType = await composio.triggers.getType("SLACK_RECEIVE_MESSAGE");
148 -
149 -console.log(triggerType.payload);
150 -```
151 -
145 ```python Python maxLines=60 wordWrap
146 # Get a trigger by id
147 trigger = composio.triggers.get_type(slug="GITHUB_COMMIT_EVENT")
148 print(trigger.payload)
149 ```
150
151 +```typescript TypeScript maxLines=60 wordWrap
152 +const triggerType = await composio.triggers.getType("SLACK_RECEIVE_MESSAGE");
153 +
154 +console.log(triggerType.payload);
155 +```
156 +
157 </CodeGroup>
158
159 ## Subscribing to triggers through the SDK
@@ -168,6 +167,17 @@ You subscribe to multiple trigger events by configuring the filters.
167 When you specify multiple multiple filters, _ALL_ of them must match for the trigger to be subscribed to.
168
169 <CodeGroup>
170 +```python Python maxLines=60 wordWrap
171 +user_id = "user@email.com"
172 +
173 +# Subscribe to a trigger
174 +subscription = composio.triggers.subscribe()
175 +
176 +# Define a handler
177 +@subscription.handle(toolkit="GITHUB", user_id=user_id)
178 +def handle_github_event(data):
179 + print(data)
180 +```
181 ```typescript TypeScript maxLines=60 wordWrap
182 await composio.triggers.subscribe(
183 triggerData => {
@@ -182,17 +192,6 @@ await composio.triggers.subscribe(
192 }
193 )
194 ```
185 -```python Python maxLines=60 wordWrap
186 -user_id = "user@email.com"
187 -
188 -# Subscribe to a trigger
189 -subscription = composio.triggers.subscribe()
190 -
191 -# Define a handler
192 -@subscription.handle(toolkit="GITHUB", user_id=user_id)
193 -def handle_github_event(data):
194 - print(data)
195 -```
195 </CodeGroup>
196
197 ## Specifying trigger configuration
@@ -211,30 +210,22 @@ The dashboard will show you the trigger configuration to fill in.
210 </Frame>
211
212 <CodeGroup>
213 +```python Python maxLines=60 wordWrap
214 +# Get a trigger by id
215 +trigger = composio.triggers.get_type(slug="GITHUB_COMMIT_EVENT")
216 +print(trigger.config)
217 +```
218 +
219 ```typescript TypeScript maxLines=60 wordWrap
220 const triggerType = await composio.triggers.getType("GITHUB_STAR_ADDED_EVENT");
221
222 console.log(triggerType.config);
223
219 -```
220 -```python Python maxLines=60 wordWrap
221 -# Get a trigger by id
222 -trigger = composio.triggers.get_type(slug="GITHUB_COMMIT_EVENT")
223 -print(trigger.config)
224 ```
225
226 </CodeGroup>
227
228 <CodeGroup>
229 -```typescript TypeScript maxLines=60 wordWrap
230 -await composio.triggers.create("GITHUB_PULL_REQUEST_EVENT", {
231 - connectedAccountId: "ca_k_py8Qbd17_d",
232 - triggerConfig: { // Properties expected for trigger config
233 - owner: "composiohq",
234 - repo: "composio",
235 - },
236 -});
237 -```
229 ```python Python maxLines=60 wordWrap
230 instance = composio.triggers.create(
231 slug="GITHUB_PULL_REQUEST_EVENT",
@@ -245,6 +236,15 @@ instance = composio.triggers.create(
236 },
237 )
238 ```
239 +```typescript TypeScript maxLines=60 wordWrap
240 +await composio.triggers.create("GITHUB_PULL_REQUEST_EVENT", {
241 + connectedAccountId: "ca_k_py8Qbd17_d",
242 + triggerConfig: { // Properties expected for trigger config
243 + owner: "composiohq",
244 + repo: "composio",
245 + },
246 +});
247 +```
248 </CodeGroup>
249
250 ## Enabling/Disabling triggers
@@ -252,27 +252,27 @@ instance = composio.triggers.create(
252 In cases where the trigger isn't required for the system, it can be disabled.
253
254 <CodeGroup>
255 - ```typescript TypeScript maxLines=60 wordWrap
256 - await composio.triggers.disable("ti_abcd123");
257 - ```
255 ```python Python maxLines=60 wordWrap
256 # Disable a trigger instance
257 disabled_instance = composio.triggers.disable(trigger_id="ti_abcd123")
258 print(disabled_instance)
259 ```
260 + ```typescript TypeScript maxLines=60 wordWrap
261 + await composio.triggers.disable("ti_abcd123");
262 + ```
263 </CodeGroup>
264
265 If needed, the trigger can be enabled again.
266
267 <CodeGroup>
268 - ```typescript TypeScript maxLines=60 wordWrap
269 - await composio.triggers.enable("ti_abcd123");
270 - ```
268 ```python Python maxLines=60 wordWrap
269 # Enable a trigger instance
270 enabled_instance = composio.triggers.enable(trigger_id="ti_abcd123")
271 print(enabled_instance)
272 ```
273 + ```typescript TypeScript maxLines=60 wordWrap
274 + await composio.triggers.enable("ti_abcd123");
275 + ```
276 </CodeGroup>
277
278 ## Troubleshooting