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 imports

haxzie8063a274755d
diff --git a/README.md b/README.md
index 57dd705eb..cfd58ef63 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,20 @@
# @composio/core
-The core Composio SDK which allows users to interact with the Composio Platform.
+The core Composio SDK which allows users to interact with the Composio Platform. It provides a powerful and flexible way to manage and execute tools, handle authentication, and integrate with various platforms and frameworks.
## Core Features
- **Tools**: Manage and execute tools within the Composio ecosystem. Includes functionality to list, retrieve, and execute tools.
- **Toolkits**: Organize and manage collections of tools for specific use cases.
-- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions. Includes support for different trigger types and status management.
-- **AuthConfigs**: Configure authentication providers and settings. Manage auth configs with features to create, update, enable/disable, and delete configurations.
-- **ConnectedAccounts**: Manage third-party service connections. Includes functionality to create, list, refresh, and manage the status of connected accounts.
+- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions.
+- **AuthConfigs**: Configure authentication providers and settings.
+- **ConnectedAccounts**: Manage third-party service connections.
- **ActionExecution**: Track and manage the execution of actions within the platform.
## Installation
+### Core SDK
+
```bash
npm install @composio/core
# or
@@ -21,94 +23,100 @@ yarn add @composio/core
pnpm add @composio/core
```
-## Configuration
-
-```typescript
-interface ComposioConfig {
- apiKey?: string; // Your Composio API key
- baseURL?: string; // Custom API base URL (optional)
- allowTracking?: boolean; // Enable/disable telemetry (default: true)
- allowTracing?: boolean; // Enable/disable tracing (default: true)
- toolset?: TToolset; // Custom toolset (default: OpenAIToolset)
- telemetryTransport?: BaseTelemetryTransport; // Custom telemetry transport
-}
+### Toolsets
-const composio = new Composio({
- apiKey: process.env.COMPOSIO_API_KEY,
- toolset: new OpenAIToolset(), // Optional: defaults to OpenAIToolset
-});
-```
+```bash
+# Install OpenAI toolset (included in core)
+npm install @composio/openai
-## Toolsets
+# Install Vercel AI toolset
+npm install @composio/vercel
-Composio SDK supports two types of toolsets, each with different modifier capabilities:
+# Install Langchain toolset
+npm install @composio/langchain
+```
-### 1. Non-Agentic Toolsets
+## Getting Started
-These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
+### Basic Usage with OpenAI Toolset
```typescript
import { Composio } from '@composio/core';
import { OpenAIToolset } from '@composio/openai-toolset';
-import type { Tool } from '@composio/core';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
+ // OpenAIToolset is the default, so this is optional
toolset: new OpenAIToolset(),
});
-// Get a tool with schema modifiers
-const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
- modifyToolSchema: (toolSlug: string, tool: Tool) => ({
- ...tool,
- description: 'Search HackerNews posts with improved description',
- inputParameters: {
- ...tool.inputParameters,
- limit: {
- type: 'number',
- description: 'Maximum number of posts to return',
- },
- },
- }),
+// Fetch a single tool
+const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
+
+// Fetch multiple tools
+const tools = await composio.tools.get('user123', {
+ category: 'search',
+ limit: 10,
});
```
-### 2. Agentic Toolsets
-
-These toolsets support full modifier capabilities, making them suitable for complex integrations like Vercel, Langchain, etc. They support:
-
-1. **Schema Modifiers**: Transform tool schemas using `modifyToolSchema`
-2. **Execution Modifiers**: Transform tool execution behavior
- - `beforeToolExecute`: Transform input parameters before execution
- - `afterToolExecute`: Transform output after execution
+## Using with a Toolset
-Example:
+### Example with Vercel AI Toolset
```typescript
import { Composio } from '@composio/core';
import { VercelToolset } from '@composio/vercel-toolset';
-import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
toolset: new VercelToolset(),
});
-// Get a tool with full modifier support
-const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
- // Schema modifier
+// Fetch tools for Vercel AI SDK
+const tools = await composio.tools.get('user123', {
+ category: 'search',
+});
+
+// Use tools with Vercel AI SDK
+const completion = await ai.chat({
+ messages: [{ role: 'user', content: 'Search for posts about React' }],
+ tools: tools,
+});
+```
+
+## Modifiers
+
+Composio SDK supports powerful modifiers to transform tool schemas and execution behavior.
+
+### Schema Modifiers
+
+Schema modifiers allow you to transform tool schemas before they are used:
+
+```typescript
+const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
modifyToolSchema: (toolSlug: string, tool: Tool) => ({
...tool,
- description: 'Search HackerNews posts with improved description',
+ description: 'Enhanced HackerNews search with additional features',
inputParameters: {
...tool.inputParameters,
limit: {
type: 'number',
description: 'Maximum number of posts to return',
+ default: 10,
},
},
}),
- // Execution modifiers
+});
+```
+
+### Execution Modifiers
+
+For agentic toolsets (like Vercel AI and Langchain), you can also modify tool execution behavior:
+
+```typescript
+const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
+ // Transform input before execution
beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
...params,
arguments: {
@@ -116,6 +124,8 @@ const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS',
limit: Math.min((params.arguments?.limit as number) || 10, 100),
},
}),
+
+ // Transform output after execution
afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
...response,
data: {
@@ -129,75 +139,89 @@ const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS',
});
```
-## Creating a Custom Toolset
+## Development
+
+### Creating Custom Toolsets
-To create a new toolset, extend either `BaseNonAgenticToolset` or `BaseAgenticToolset` from `@composio/core`:
+You can create custom toolsets by extending either `BaseNonAgenticToolset` or `BaseAgenticToolset`:
+
+#### Non-Agentic Toolset
```typescript
import { BaseNonAgenticToolset } from '@composio/core';
-import type { Tool, ToolListParams, ToolOptions } from '@composio/core';
+import type { Tool } from '@composio/core';
interface CustomTool {
name: string;
// ... custom tool properties
}
-export class CustomToolset extends BaseNonAgenticToolset<Array<CustomTool>, CustomTool> {
- readonly FILE_NAME: string = 'custom/toolset.ts';
+export class CustomToolset extends BaseNonAgenticToolset<CustomTool[], CustomTool> {
+ readonly name = 'custom-toolset';
- wrapTool = (tool: Tool): CustomTool => {
- return {
- name: tool.name,
- // ... map other properties
- };
- };
+ wrapTool = (tool: Tool): CustomTool => ({
+ name: tool.name,
+ // ... map other properties
+ });
- async getTools(
- userId: string,
- params?: ToolListParams,
- options?: ToolOptions
- ): Promise<Array<CustomTool>> {
- const tools = await this.getComposio().tools.getComposioTools(
- userId,
- params,
- options?.modifyToolSchema
- );
- return tools?.map(tool => this.wrapTool(tool)) ?? [];
- }
+ wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
+}
+```
+
+#### Agentic Toolset
+
+```typescript
+import { BaseAgenticToolset } from '@composio/core';
+import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
- async getToolBySlug(userId: string, slug: string, options?: ToolOptions): Promise<CustomTool> {
- const tool = await this.getComposio().tools.getComposioToolBySlug(
- userId,
- slug,
- options?.modifyToolSchema
+export class CustomAgenticToolset extends BaseAgenticToolset<CustomTool[], CustomTool> {
+ readonly name = 'custom-agentic-toolset';
+
+ wrapTool = (tool: Tool): CustomTool => ({
+ name: tool.name,
+ // ... map other properties
+ });
+
+ wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
+
+ async executeToolCall(
+ userId: string,
+ tool: { name: string; arguments: unknown },
+ options: ExecuteToolFnOptions,
+ modifiers?: ExecuteToolModifiers
+ ): Promise<string> {
+ const result = await this.executeTool(
+ tool.name,
+ {
+ arguments: tool.arguments,
+ userId,
+ ...options,
+ },
+ modifiers
);
- return this.wrapTool(tool);
+ return JSON.stringify(result);
}
}
```
-To quickly create a toolset project, use the provided script:
+To quickly create a new toolset project, use the provided script:
```bash
-# Create a non-agentic toolset (default)
-pnpm run create-toolset <your-toolset-name>
+# Create a non-agentic toolset
+pnpm create-toolset my-toolset
# Create an agentic toolset
-pnpm run create-toolset <your-toolset-name> --agentic
+pnpm create-toolset my-toolset --agentic
```
## Environment Variables
- `COMPOSIO_API_KEY`: Your Composio API key
-- `COMPOSIO_BASE_URL`: Custom API base URL
+- `COMPOSIO_BASE_URL`: Custom API base URL (optional)
- `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
- `DEVELOPMENT`: Development mode flag
- `CI`: CI environment flag
-## Contributing
-
-We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
-
## License
ISC License
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 892cef5c7..0dda39acf 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -9,8 +9,8 @@ export {
export { OpenAIToolset } from './toolset/OpenAIToolset';
export { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
export { jsonSchemaToModel } from './utils/jsonSchema';
-export { Tool, ToolListParams, ToolListParamsSchema } from './types/tool.types';
-export { Toolset } from './types/toolset.types';
+export { Tool, ToolListParams, ToolListParamsSchema, ToolExecuteParams } from './types/tool.types';
+export { Toolset, ExecuteToolFn, ExecuteToolFnOptions } from './types/toolset.types';
export { ExecuteMetadata } from './types/customTool.types';
// Type exports
export type {
diff --git a/packages/toolsets/cloudflare/src/index.ts b/packages/toolsets/cloudflare/src/index.ts
index 5031e4e9f..4faa6b06e 100644
--- a/packages/toolsets/cloudflare/src/index.ts
+++ b/packages/toolsets/cloudflare/src/index.ts
@@ -10,9 +10,13 @@
* @module toolsets/cloudflare
*/
import { AiTextGenerationToolInput } from '@cloudflare/workers-types';
-import { Tool, ExecuteToolModifiers, BaseNonAgenticToolset } from '@composio/core';
-import { ToolExecuteParams } from 'packages/core/src/types/tool.types';
-import { ExecuteToolFnOptions } from 'packages/core/src/types/toolset.types';
+import {
+ Tool,
+ ExecuteToolModifiers,
+ BaseNonAgenticToolset,
+ ToolExecuteParams,
+ ExecuteToolFnOptions,
+} from '@composio/core';
type AiToolCollection = Record<string, AiTextGenerationToolInput>;
diff --git a/packages/toolsets/langchain/src/index.ts b/packages/toolsets/langchain/src/index.ts
index 7b85c0575..bbeb53709 100644
--- a/packages/toolsets/langchain/src/index.ts
+++ b/packages/toolsets/langchain/src/index.ts
@@ -9,9 +9,8 @@
* @packageDocumentation
* @module toolsets/langchain
*/
-import { BaseAgenticToolset, jsonSchemaToModel, Tool } from '@composio/core';
+import { BaseAgenticToolset, jsonSchemaToModel, Tool, ExecuteToolFn } from '@composio/core';
import { DynamicStructuredTool } from '@langchain/core/tools';
-import { ExecuteToolFn } from 'packages/core/src/types/toolset.types';
export type LangChainToolCollection = Array<DynamicStructuredTool>;
export class LangchainToolset extends BaseAgenticToolset<
diff --git a/packages/toolsets/vercel/src/index.ts b/packages/toolsets/vercel/src/index.ts
index 648e5766d..1da1c5703 100644
--- a/packages/toolsets/vercel/src/index.ts
+++ b/packages/toolsets/vercel/src/index.ts
@@ -10,10 +10,9 @@
* @packageDocumentation
* @module toolsets/vercel
*/
-import { BaseAgenticToolset, Tool as ComposioTool } from '@composio/core';
+import { BaseAgenticToolset, Tool as ComposioTool, ExecuteToolFn } from '@composio/core';
import type { Tool as VercelTool } from 'ai';
import { jsonSchema, tool } from 'ai';
-import { ExecuteToolFn } from 'packages/core/src/types/toolset.types';
type VercelToolCollection = Record<string, VercelTool>;
export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, VercelTool> {