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 23, 01:45 UTC
Fix tools fetching to always return tool collection
haxzie committed
May 20, 2025 at 11:57 UTC
ec6774bff4525a077e983f5982f0f4d6ab5e25ba
11 files changed
+46
-74
README.md
+4
-4
@@ -176,8 +176,8 @@ const composio = new Composio({
176
provider: new OpenAIProvider(),
177
});
178
179
-// Fetch a single tool
180
-const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
179
+// Fetch a single tool by it's slug
180
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
181
182
// Fetch multiple tools
183
const tools = await composio.tools.get('user123', {
@@ -220,7 +220,7 @@ Composio SDK supports powerful modifiers to transform tool schemas and execution
220
Schema modifiers allow you to transform tool schemas before they are used:
221
222
```typescript
223
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
223
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
224
modifyToolSchema: (toolSlug: string, tool: Tool) => ({
225
...tool,
226
description: 'Enhanced HackerNews search with additional features',
@@ -241,7 +241,7 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
241
For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
242
243
```typescript
244
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
244
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
245
// Transform input before execution
246
beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
247
...params,
examples/langchain/src/index.ts
+1
-2
@@ -12,10 +12,9 @@ const composio = new Composio({
12
13
// fetch the tool
14
console.log(`🔄 Fetching the tool...`);
15
-const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
15
+const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
16
17
// Define the tools for the agent to use
18
-const tools = [tool];
18
const toolNode = new ToolNode(tools);
19
20
// Create a model and give it access to the tools
examples/openai/src/assistants.ts
+2
-2
@@ -25,7 +25,7 @@ async function main() {
25
try {
26
console.log('🔄 Setting up Composio and fetching tool...');
27
28
- const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
28
+ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
29
30
console.log('🔄 Creating OpenAI Assistant with Composio tool...');
31
@@ -34,7 +34,7 @@ async function main() {
34
instructions:
35
'You are a helpful assistant that can fetch information about HackerNews users.',
36
model: 'gpt-4o',
37
- tools: [tool],
37
+ tools: tools,
38
});
39
40
console.log(`✅ Assistant created with ID: ${assistant.id}`);
examples/openai/src/chat-completions.ts
+2
-2
@@ -25,7 +25,7 @@ async function main() {
25
try {
26
console.log('🔄 Setting up Composio and fetching tool...');
27
28
- const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
28
+ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
29
30
const query = "Find information about the HackerNews user 'pg'";
31
@@ -40,7 +40,7 @@ async function main() {
40
},
41
{ role: 'user', content: query },
42
],
43
- tools: [tool],
43
+ tools: tools,
44
tool_choice: 'auto',
45
});
46
examples/openai/src/index.ts
+3
-3
@@ -14,10 +14,10 @@ const composio = new Composio({
14
});
15
16
/**
17
- * Get the tool by slug
17
+ * Get the tools
18
* This tool is automatically typed and wrapped with the OpenAI Provider
19
*/
20
-const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
20
+const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
21
/**
22
* Define a task for the assistant based on the tools in hand
23
*/
@@ -37,7 +37,7 @@ const messages: OpenAI.ChatCompletionMessageParam[] = [
37
const response = await openai.chat.completions.create({
38
model: 'gpt-4o-mini',
39
messages,
40
- tools: [tool],
40
+ tools: tools,
41
tool_choice: 'auto',
42
});
43
examples/vercel/src/index.ts
+2
-2
@@ -19,7 +19,7 @@ const composio = new Composio({
19
* Alternatively, you can use the `composio.getToolBySlug` method
20
*/
21
async function run() {
22
- const hackerNewsTool = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
22
+ const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
23
24
const messages: Message[] = [
25
{
@@ -31,7 +31,7 @@ async function run() {
31
const chatCompletion = async () => {
32
const { text, toolCalls, toolResults } = await generateText({
33
model: openai('gpt-4o-mini'),
34
- tools: { ['HACKERNEWS_GET_FRONTPAGE']: hackerNewsTool },
34
+ tools: tools,
35
messages,
36
});
37
packages/core/README.md
+4
-4
@@ -35,8 +35,8 @@ const composio = new Composio({
35
provider: new OpenAIProvider(),
36
});
37
38
-// Fetch a single tool
39
-const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
38
+// Fetch a single tool by slig
39
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
40
41
// Fetch multiple tools
42
const tools = await composio.tools.get('user123', {
@@ -69,7 +69,7 @@ Composio SDK supports powerful modifiers to transform tool schemas and execution
69
Schema modifiers allow you to transform tool schemas before they are used:
70
71
```typescript
72
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
72
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
73
modifyToolSchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
74
...tool,
75
description: 'Enhanced HackerNews search with additional features',
@@ -90,7 +90,7 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
90
For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
91
92
```typescript
93
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
93
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
94
// Transform input before execution
95
beforeToolExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
96
...params,
packages/core/src/composio.ts
-30
@@ -8,8 +8,6 @@ import { BaseComposioProvider } from './provider/BaseProvider';
8
import { Telemetry } from './telemetry/Telemetry';
9
import { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
10
import type { TelemetryMetadata } from './types/telemetry.types';
11
-import type { ProviderOptions } from './types/modifiers.types';
12
-import type { ToolListParams } from './types/tool.types';
11
import { getSDKConfig } from './utils/sdk';
12
import logger from './utils/logger';
13
import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
@@ -174,32 +172,4 @@ export class Composio<TProvider extends BaseComposioProvider<unknown, unknown> =
172
}
173
return this.client;
174
}
177
-
178
- /**
179
- * Fetch all the tools from Composio.
180
- * @param {ToolListParams} params Parameters to fetch the tools.
181
- * @param {ProviderOptions<TProvider>} modifiers Modifiers to apply to the tools.
182
- * @returns {Promise<ReturnType<TProvider['getTools']>>} The tools from the provider.
183
- */
184
- getTools<T extends TProvider>(
185
- userId: string,
186
- filters: ToolListParams,
187
- modifiers?: ProviderOptions<T>
188
- ): Promise<ReturnType<T['wrapTools']>> {
189
- return this.tools.get(userId, filters, modifiers) as Promise<ReturnType<T['wrapTools']>>;
190
- }
191
-
192
- /**
193
- * Fetch a tool from Composio by its slug.
194
- * @param {string} slug slug of the tool
195
- * @param {ProviderOptions<TProvider>} modifiers to be applied to the tool
196
- * @returns {Promise<ReturnType<TProvider['getToolBySlug']>>} The tool from the provider.
197
- */
198
- getToolBySlug<T extends TProvider>(
199
- userId: string,
200
- slug: string,
201
- modifiers?: ProviderOptions<T>
202
- ): Promise<ReturnType<T['wrapTool']>> {
203
- return this.tools.get(userId, slug, modifiers) as Promise<ReturnType<T['wrapTool']>>;
204
- }
175
}
packages/core/src/models/Tools.ts
+17
-17
@@ -296,40 +296,40 @@ export class Tools<
296
}
297
298
/**
299
- * Get a tool by its slug
299
+ * Get a list of tools by their slugs
300
* @param userId - The user id
301
- * @param slug - The slug of the tool
302
- * @param options - The options for the tool
303
- * @returns The tool
301
+ * @param filters - The filters for the tools
302
+ * @param options - The options for the tools
303
+ * @returns The tools
304
*
305
* @example
306
* ```ts
307
- * const tool = await composio.tools.get('default', 'github');
307
+ * const tools = await composio.tools.get('default', {
308
+ * tools: ['github'],
309
+ * });
310
* ```
311
*/
312
async get<T extends TProvider>(
313
userId: string,
312
- slug: string,
314
+ filters: ToolListParams,
315
options?: ProviderOptions<TProvider>
314
- ): Promise<ReturnType<T['wrapTool']>>;
316
+ ): Promise<ReturnType<T['wrapTools']>>;
317
318
/**
317
- * Get a list of tools by their slugs
319
+ * Get a tool by its slug
320
* @param userId - The user id
319
- * @param filters - The filters for the tools
320
- * @param options - The options for the tools
321
- * @returns The tools
321
+ * @param slug - The slug of the tool
322
+ * @param options - The options for the tool
323
+ * @returns The tool
324
*
325
* @example
326
* ```ts
325
- * const tools = await composio.tools.get('default', {
326
- * tools: ['github'],
327
- * });
327
+ * const tool = await composio.tools.get('default', 'github');
328
* ```
329
*/
330
async get<T extends TProvider>(
331
userId: string,
332
- filters: ToolListParams,
332
+ slug: string,
333
options?: ProviderOptions<TProvider>
334
): Promise<ReturnType<T['wrapTools']>>;
335
@@ -344,13 +344,13 @@ export class Tools<
344
userId: string,
345
arg2: ToolListParams | string,
346
options?: ProviderOptions<TProvider>
347
- ): Promise<TTool | TToolCollection> {
347
+ ): Promise<TToolCollection> {
348
// create the execute tool function
349
const executeToolFn = this.createExecuteToolFn(userId, options as ExecuteToolModifiers);
350
// if the first argument is a string, get a single tool
351
if (typeof arg2 === 'string') {
352
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifyToolSchema);
353
- return this.provider.wrapTool(tool, executeToolFn) as TTool;
353
+ return this.provider.wrapTools([tool], executeToolFn) as TToolCollection;
354
} else {
355
// if the first argument is an object, get a list of tools
356
const tools = await this.getRawComposioTools(userId, arg2, options?.modifyToolSchema);
packages/core/test/tools/tools.test.ts
+9
-6
@@ -194,7 +194,7 @@ describe('Tools', () => {
194
});
195
196
describe('get', () => {
197
- it('should get a single tool and wrap it with provider', async () => {
197
+ it('should get a single tool by slug and wrap it with provider as a collection', async () => {
198
const userId = 'test-user';
199
const slug = 'TOOL_SLUG';
200
@@ -203,13 +203,16 @@ describe('Tools', () => {
203
toolMocks.transformedTool as unknown as Tool
204
);
205
206
- context.mockProvider.wrapTool.mockReturnValueOnce('wrapped-tool');
206
+ context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools-collection');
207
208
const result = await context.tools.get(userId, slug);
209
210
expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(userId, slug, undefined);
211
- expect(context.mockProvider.wrapTool).toHaveBeenCalled();
212
- expect(result).toEqual('wrapped-tool');
211
+ expect(context.mockProvider.wrapTools).toHaveBeenCalledWith(
212
+ [toolMocks.transformedTool],
213
+ expect.any(Function)
214
+ );
215
+ expect(result).toEqual('wrapped-tools-collection');
216
});
217
218
it('should get multiple tools and wrap them with provider', async () => {
@@ -219,13 +222,13 @@ describe('Tools', () => {
222
const getRawComposioToolsSpy = vi.spyOn(context.tools, 'getRawComposioTools');
223
getRawComposioToolsSpy.mockResolvedValueOnce([toolMocks.transformedTool as unknown as Tool]);
224
222
- context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools');
225
+ context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools-collection');
226
227
const result = await context.tools.get(userId, filters);
228
229
expect(getRawComposioToolsSpy).toHaveBeenCalledWith(userId, filters, undefined);
230
expect(context.mockProvider.wrapTools).toHaveBeenCalled();
228
- expect(result).toEqual('wrapped-tools');
231
+ expect(result).toEqual('wrapped-tools-collection');
232
});
233
234
it('should pass modifiers to the underlying methods', async () => {
packages/wrappers/README.md
+2
-2
@@ -65,7 +65,7 @@ class BrowserRuntimeWrapper {
65
// Override or extend core methods as needed
66
async getTools() {
67
// Browser-specific implementation
68
- return this.composio.getTools();
68
+ return this.composio.tools.get();
69
}
70
}
71
```
@@ -135,7 +135,7 @@ class BrowserWrapper {
135
// Browser-specific implementation of core methods
136
async getTools() {
137
// Add browser-specific caching or other optimizations
138
- return this.composio.getTools();
138
+ return this.composio.tools.get();
139
}
140
}
141
```