Skip to content

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

Fix tools fetching to always return tool collection

haxzieec6774bff452
diff --git a/README.md b/README.md
index 7ae8b9228..7e66aa868 100644
--- a/README.md
+++ b/README.md
@@ -176,8 +176,8 @@ const composio = new Composio({
provider: new OpenAIProvider(),
});
-// Fetch a single tool
-const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
+// Fetch a single tool by it's slug
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
// Fetch multiple tools
const tools = await composio.tools.get('user123', {
@@ -220,7 +220,7 @@ Composio SDK supports powerful modifiers to transform tool schemas and execution
Schema modifiers allow you to transform tool schemas before they are used:
```typescript
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
modifyToolSchema: (toolSlug: string, tool: Tool) => ({
...tool,
description: 'Enhanced HackerNews search with additional features',
@@ -241,7 +241,7 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
```typescript
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
// Transform input before execution
beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
...params,
diff --git a/examples/langchain/src/index.ts b/examples/langchain/src/index.ts
index 799930e78..0f43c52ea 100644
--- a/examples/langchain/src/index.ts
+++ b/examples/langchain/src/index.ts
@@ -12,10 +12,9 @@ const composio = new Composio({
// fetch the tool
console.log(`πŸ”„ Fetching the tool...`);
-const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
+const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
// Define the tools for the agent to use
-const tools = [tool];
const toolNode = new ToolNode(tools);
// Create a model and give it access to the tools
diff --git a/examples/openai/src/assistants.ts b/examples/openai/src/assistants.ts
index 0ff37869f..dbbbdf4a5 100644
--- a/examples/openai/src/assistants.ts
+++ b/examples/openai/src/assistants.ts
@@ -25,7 +25,7 @@ async function main() {
try {
console.log('πŸ”„ Setting up Composio and fetching tool...');
- const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
+ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
console.log('πŸ”„ Creating OpenAI Assistant with Composio tool...');
@@ -34,7 +34,7 @@ async function main() {
instructions:
'You are a helpful assistant that can fetch information about HackerNews users.',
model: 'gpt-4o',
- tools: [tool],
+ tools: tools,
});
console.log(`βœ… Assistant created with ID: ${assistant.id}`);
diff --git a/examples/openai/src/chat-completions.ts b/examples/openai/src/chat-completions.ts
index ec87f8790..01553f7b2 100644
--- a/examples/openai/src/chat-completions.ts
+++ b/examples/openai/src/chat-completions.ts
@@ -25,7 +25,7 @@ async function main() {
try {
console.log('πŸ”„ Setting up Composio and fetching tool...');
- const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
+ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
const query = "Find information about the HackerNews user 'pg'";
@@ -40,7 +40,7 @@ async function main() {
},
{ role: 'user', content: query },
],
- tools: [tool],
+ tools: tools,
tool_choice: 'auto',
});
diff --git a/examples/openai/src/index.ts b/examples/openai/src/index.ts
index 97f15e2bd..971546b5d 100644
--- a/examples/openai/src/index.ts
+++ b/examples/openai/src/index.ts
@@ -14,10 +14,10 @@ const composio = new Composio({
});
/**
- * Get the tool by slug
+ * Get the tools
* This tool is automatically typed and wrapped with the OpenAI Provider
*/
-const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
+const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
/**
* Define a task for the assistant based on the tools in hand
*/
@@ -37,7 +37,7 @@ const messages: OpenAI.ChatCompletionMessageParam[] = [
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages,
- tools: [tool],
+ tools: tools,
tool_choice: 'auto',
});
diff --git a/examples/vercel/src/index.ts b/examples/vercel/src/index.ts
index dd7a56419..688e7d435 100644
--- a/examples/vercel/src/index.ts
+++ b/examples/vercel/src/index.ts
@@ -19,7 +19,7 @@ const composio = new Composio({
* Alternatively, you can use the `composio.getToolBySlug` method
*/
async function run() {
- const hackerNewsTool = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
+ const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
const messages: Message[] = [
{
@@ -31,7 +31,7 @@ async function run() {
const chatCompletion = async () => {
const { text, toolCalls, toolResults } = await generateText({
model: openai('gpt-4o-mini'),
- tools: { ['HACKERNEWS_GET_FRONTPAGE']: hackerNewsTool },
+ tools: tools,
messages,
});
diff --git a/packages/core/README.md b/packages/core/README.md
index be2a23d28..6344eb106 100644
--- a/packages/core/README.md
+++ b/packages/core/README.md
@@ -35,8 +35,8 @@ const composio = new Composio({
provider: new OpenAIProvider(),
});
-// Fetch a single tool
-const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
+// Fetch a single tool by slig
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
// Fetch multiple tools
const tools = await composio.tools.get('user123', {
@@ -69,7 +69,7 @@ Composio SDK supports powerful modifiers to transform tool schemas and execution
Schema modifiers allow you to transform tool schemas before they are used:
```typescript
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
modifyToolSchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
...tool,
description: 'Enhanced HackerNews search with additional features',
@@ -90,7 +90,7 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
```typescript
-const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
+const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
// Transform input before execution
beforeToolExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
...params,
diff --git a/packages/core/src/composio.ts b/packages/core/src/composio.ts
index 16759aa5f..1b22a7bcb 100644
--- a/packages/core/src/composio.ts
+++ b/packages/core/src/composio.ts
@@ -8,8 +8,6 @@ import { BaseComposioProvider } from './provider/BaseProvider';
import { Telemetry } from './telemetry/Telemetry';
import { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
import type { TelemetryMetadata } from './types/telemetry.types';
-import type { ProviderOptions } from './types/modifiers.types';
-import type { ToolListParams } from './types/tool.types';
import { getSDKConfig } from './utils/sdk';
import logger from './utils/logger';
import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
@@ -174,32 +172,4 @@ export class Composio<TProvider extends BaseComposioProvider<unknown, unknown> =
}
return this.client;
}
-
- /**
- * Fetch all the tools from Composio.
- * @param {ToolListParams} params Parameters to fetch the tools.
- * @param {ProviderOptions<TProvider>} modifiers Modifiers to apply to the tools.
- * @returns {Promise<ReturnType<TProvider['getTools']>>} The tools from the provider.
- */
- getTools<T extends TProvider>(
- userId: string,
- filters: ToolListParams,
- modifiers?: ProviderOptions<T>
- ): Promise<ReturnType<T['wrapTools']>> {
- return this.tools.get(userId, filters, modifiers) as Promise<ReturnType<T['wrapTools']>>;
- }
-
- /**
- * Fetch a tool from Composio by its slug.
- * @param {string} slug slug of the tool
- * @param {ProviderOptions<TProvider>} modifiers to be applied to the tool
- * @returns {Promise<ReturnType<TProvider['getToolBySlug']>>} The tool from the provider.
- */
- getToolBySlug<T extends TProvider>(
- userId: string,
- slug: string,
- modifiers?: ProviderOptions<T>
- ): Promise<ReturnType<T['wrapTool']>> {
- return this.tools.get(userId, slug, modifiers) as Promise<ReturnType<T['wrapTool']>>;
- }
}
diff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.ts
index beba52bd6..99cbfd3d9 100644
--- a/packages/core/src/models/Tools.ts
+++ b/packages/core/src/models/Tools.ts
@@ -296,40 +296,40 @@ export class Tools<
}
/**
- * Get a tool by its slug
+ * Get a list of tools by their slugs
* @param userId - The user id
- * @param slug - The slug of the tool
- * @param options - The options for the tool
- * @returns The tool
+ * @param filters - The filters for the tools
+ * @param options - The options for the tools
+ * @returns The tools
*
* @example
* ```ts
- * const tool = await composio.tools.get('default', 'github');
+ * const tools = await composio.tools.get('default', {
+ * tools: ['github'],
+ * });
* ```
*/
async get<T extends TProvider>(
userId: string,
- slug: string,
+ filters: ToolListParams,
options?: ProviderOptions<TProvider>
- ): Promise<ReturnType<T['wrapTool']>>;
+ ): Promise<ReturnType<T['wrapTools']>>;
/**
- * Get a list of tools by their slugs
+ * Get a tool by its slug
* @param userId - The user id
- * @param filters - The filters for the tools
- * @param options - The options for the tools
- * @returns The tools
+ * @param slug - The slug of the tool
+ * @param options - The options for the tool
+ * @returns The tool
*
* @example
* ```ts
- * const tools = await composio.tools.get('default', {
- * tools: ['github'],
- * });
+ * const tool = await composio.tools.get('default', 'github');
* ```
*/
async get<T extends TProvider>(
userId: string,
- filters: ToolListParams,
+ slug: string,
options?: ProviderOptions<TProvider>
): Promise<ReturnType<T['wrapTools']>>;
@@ -344,13 +344,13 @@ export class Tools<
userId: string,
arg2: ToolListParams | string,
options?: ProviderOptions<TProvider>
- ): Promise<TTool | TToolCollection> {
+ ): Promise<TToolCollection> {
// create the execute tool function
const executeToolFn = this.createExecuteToolFn(userId, options as ExecuteToolModifiers);
// if the first argument is a string, get a single tool
if (typeof arg2 === 'string') {
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifyToolSchema);
- return this.provider.wrapTool(tool, executeToolFn) as TTool;
+ return this.provider.wrapTools([tool], executeToolFn) as TToolCollection;
} else {
// if the first argument is an object, get a list of tools
const tools = await this.getRawComposioTools(userId, arg2, options?.modifyToolSchema);
diff --git a/packages/core/test/tools/tools.test.ts b/packages/core/test/tools/tools.test.ts
index c32a7d575..4d765408c 100644
--- a/packages/core/test/tools/tools.test.ts
+++ b/packages/core/test/tools/tools.test.ts
@@ -194,7 +194,7 @@ describe('Tools', () => {
});
describe('get', () => {
- it('should get a single tool and wrap it with provider', async () => {
+ it('should get a single tool by slug and wrap it with provider as a collection', async () => {
const userId = 'test-user';
const slug = 'TOOL_SLUG';
@@ -203,13 +203,16 @@ describe('Tools', () => {
toolMocks.transformedTool as unknown as Tool
);
- context.mockProvider.wrapTool.mockReturnValueOnce('wrapped-tool');
+ context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools-collection');
const result = await context.tools.get(userId, slug);
expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(userId, slug, undefined);
- expect(context.mockProvider.wrapTool).toHaveBeenCalled();
- expect(result).toEqual('wrapped-tool');
+ expect(context.mockProvider.wrapTools).toHaveBeenCalledWith(
+ [toolMocks.transformedTool],
+ expect.any(Function)
+ );
+ expect(result).toEqual('wrapped-tools-collection');
});
it('should get multiple tools and wrap them with provider', async () => {
@@ -219,13 +222,13 @@ describe('Tools', () => {
const getRawComposioToolsSpy = vi.spyOn(context.tools, 'getRawComposioTools');
getRawComposioToolsSpy.mockResolvedValueOnce([toolMocks.transformedTool as unknown as Tool]);
- context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools');
+ context.mockProvider.wrapTools.mockReturnValueOnce('wrapped-tools-collection');
const result = await context.tools.get(userId, filters);
expect(getRawComposioToolsSpy).toHaveBeenCalledWith(userId, filters, undefined);
expect(context.mockProvider.wrapTools).toHaveBeenCalled();
- expect(result).toEqual('wrapped-tools');
+ expect(result).toEqual('wrapped-tools-collection');
});
it('should pass modifiers to the underlying methods', async () => {
diff --git a/packages/wrappers/README.md b/packages/wrappers/README.md
index e92f1b241..1cc6dd75b 100644
--- a/packages/wrappers/README.md
+++ b/packages/wrappers/README.md
@@ -65,7 +65,7 @@ class BrowserRuntimeWrapper {
// Override or extend core methods as needed
async getTools() {
// Browser-specific implementation
- return this.composio.getTools();
+ return this.composio.tools.get();
}
}
```
@@ -135,7 +135,7 @@ class BrowserWrapper {
// Browser-specific implementation of core methods
async getTools() {
// Add browser-specific caching or other optimizations
- return this.composio.getTools();
+ return this.composio.tools.get();
}
}
```