@devries-cameron20 / composio-1 / commits / 7a2e1b2ca
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.

Add details about modifiers into readme.md

haxzie committed May 13, 2025 at 14:45 UTC 7a2e1b2ca3f2d8ec2d98e2df8536424929d636ad
2 files changed +499 -134
README.md
+166 -6
@@ -13,10 +13,122 @@ The core Composio SDK which allows users to interact with the Composio Platform.
13
14 ## Toolsets
15
16 -Composio SDK supports two types of toolsets:
16 +Composio SDK supports two types of toolsets, each with different modifier capabilities:
17
18 -1. **Non-Agentic Toolsets**: These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
19 -2. **Agentic Toolsets**: These toolsets support full modifier capabilities including tool execution modifiers, schema modifiers, and custom modifiers. They are suitable for more complex integrations like Vercel, Langchain, etc.
18 +### 1. Non-Agentic Toolsets
19 +
20 +These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
21 +
22 +Schema modifiers allow you to transform tool schemas using the `TransformToolSchemaModifier` function:
23 +
24 +```typescript
25 +import { Composio } from '@composio/core';
26 +import { OpenAIToolset } from '@composio/openai-toolset';
27 +import type { Tool } from '@composio/core';
28 +
29 +const composio = new Composio({
30 + apiKey: process.env.COMPOSIO_API_KEY,
31 + toolset: new OpenAIToolset(),
32 +});
33 +
34 +// Get a tool with schema modifiers
35 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
36 + schema: (toolSlug: string, tool: Tool) => ({
37 + ...tool,
38 + description: 'Search HackerNews posts with improved description',
39 + inputParameters: {
40 + ...tool.inputParameters,
41 + limit: {
42 + type: 'number',
43 + description: 'Maximum number of posts to return',
44 + },
45 + },
46 + }),
47 +});
48 +```
49 +
50 +### 2. Agentic Toolsets
51 +
52 +These toolsets support full modifier capabilities, making them suitable for complex integrations like Vercel, Langchain, etc. They support:
53 +
54 +1. **Schema Modifiers**: Transform tool schemas using `TransformToolSchemaModifier`
55 +2. **Execution Modifiers**: Transform tool execution behavior
56 + - `beforeToolExecute`: Transform input parameters before execution
57 + - `afterToolExecute`: Transform output after execution
58 +
59 +Example:
60 +
61 +```typescript
62 +import { Composio } from '@composio/core';
63 +import { VercelToolset } from '@composio/vercel-toolset';
64 +import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
65 +
66 +const composio = new Composio({
67 + apiKey: process.env.COMPOSIO_API_KEY,
68 + toolset: new VercelToolset(),
69 +});
70 +
71 +// Get a tool with full modifier support
72 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
73 + // Schema modifier
74 + schema: (toolSlug: string, tool: Tool) => ({
75 + ...tool,
76 + description: 'Search HackerNews posts with improved description',
77 + inputParameters: {
78 + ...tool.inputParameters,
79 + limit: {
80 + type: 'number',
81 + description: 'Maximum number of posts to return',
82 + },
83 + },
84 + }),
85 + // Execution modifiers
86 + beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
87 + ...params,
88 + arguments: {
89 + ...params.arguments,
90 + limit: Math.min((params.arguments?.limit as number) || 10, 100),
91 + },
92 + }),
93 + afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
94 + ...response,
95 + data: {
96 + ...response.data,
97 + posts: (response.data?.posts as any[]).map(post => ({
98 + ...post,
99 + url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
100 + })),
101 + },
102 + }),
103 +});
104 +
105 +// Execute the tool with execution modifiers
106 +const result = await composio.toolset.executeTool(
107 + tool,
108 + {
109 + arguments: { query: 'AI', limit: 20 },
110 + },
111 + {
112 + beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
113 + ...params,
114 + arguments: {
115 + ...params.arguments,
116 + limit: Math.min((params.arguments?.limit as number) || 10, 100),
117 + },
118 + }),
119 + afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
120 + ...response,
121 + data: {
122 + ...response.data,
123 + posts: (response.data?.posts as any[]).map(post => ({
124 + ...post,
125 + url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
126 + })),
127 + },
128 + }),
129 + }
130 +);
131 +```
132
133 ## Usage
134
@@ -24,13 +136,27 @@ Composio SDK supports two types of toolsets:
136
137 ```typescript
138 import { Composio } from '@composio/core';
139 +import type { Tool } from '@composio/core';
140
141 // By default composio ships with OpenAI toolset (non-agentic)
142 const composio = new Composio({
143 apiKey: process.env.COMPOSIO_API_KEY,
144 });
145
33 -const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS');
146 +// Get a tool with schema modifiers
147 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
148 + schema: (toolSlug: string, tool: Tool) => ({
149 + ...tool,
150 + description: 'Search HackerNews posts with improved description',
151 + inputParameters: {
152 + ...tool.inputParameters,
153 + limit: {
154 + type: 'number',
155 + description: 'Maximum number of posts to return',
156 + },
157 + },
158 + }),
159 +});
160 console.log(tool);
161 ```
162
@@ -45,14 +171,48 @@ import { Composio } from '@composio/core';
171 import { VercelToolset } from '@composio/vercel-toolset'; // Agentic toolset
172 // or
173 import { OpenAIToolset } from '@composio/openai-toolset'; // Non-agentic toolset
174 +import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
175
176 const composio = new Composio({
177 apiKey: process.env.COMPOSIO_API_KEY,
178 toolset: new VercelToolset(), // or new OpenAIToolset()
179 });
180
54 -const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS');
55 -console.log(tool);
181 +// Get a tool with appropriate modifiers based on toolset type
182 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
183 + // Schema modifiers (supported by both types)
184 + schema: (toolSlug: string, tool: Tool) => ({
185 + ...tool,
186 + description: 'Search HackerNews posts with improved description',
187 + inputParameters: {
188 + ...tool.inputParameters,
189 + limit: {
190 + type: 'number',
191 + description: 'Maximum number of posts to return',
192 + },
193 + },
194 + }),
195 + // Execution modifiers (only for agentic toolsets)
196 + ...(composio.toolset instanceof VercelToolset && {
197 + beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
198 + ...params,
199 + arguments: {
200 + ...params.arguments,
201 + limit: Math.min((params.arguments?.limit as number) || 10, 100),
202 + },
203 + }),
204 + afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
205 + ...response,
206 + data: {
207 + ...response.data,
208 + posts: (response.data?.posts as any[]).map(post => ({
209 + ...post,
210 + url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
211 + })),
212 + },
213 + }),
214 + }),
215 +});
216 ```
217
218 ## Creating a new toolset
packages/toolsets/README.md
+333 -128
@@ -1,88 +1,111 @@
1 # Composio Toolsets
2
3 -This package contains various toolsets that integrate with Composio's core functionality. Each toolset provides a collection of tools that can be used to interact with different services and APIs.
3 +This directory contains various toolsets that implement the Composio SDK for different platforms and frameworks. Each toolset provides a way to interact with the Composio Platform using the specific platform's conventions and requirements.
4
5 ## Types of Toolsets
6
7 -Composio SDK supports two types of toolsets:
7 +Composio SDK supports two types of toolsets, each with different modifier capabilities:
8
9 ### 1. Non-Agentic Toolsets
10
11 These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
12
13 +Example implementation:
14 +
15 ```typescript
16 import { BaseNonAgenticToolset } from '@composio/core';
15 -import type { Tool, ToolListParams, SchemaModifiersParams } from '@composio/core';
16 -
17 -interface ToolType {
18 - // Define your tool type here
19 -}
20 -
21 -interface ToolCollection {
22 - // Define your tool collection here
23 -}
24 -
25 -export class NonAgenticToolset extends BaseNonAgenticToolset<ToolCollection, ToolType> {
26 - static FRAMEWORK_NAME = 'non-agentic-toolset';
27 - readonly FILE_NAME: string = 'toolsets/non-agentic-toolset/src/index.ts';
28 -
29 - wrapTool = (tool: Tool): ToolType => {
30 - // Implement tool wrapping logic
31 - return tool as ToolType;
32 - };
33 -
34 - getTools = async (
35 - params?: ToolListParams,
36 - modifiers?: SchemaModifiersParams
37 - ): Promise<ToolCollection> => {
38 - // Implement tool collection logic
39 - return [];
40 - };
41 -
42 - getToolBySlug = async (slug: string, modifiers?: SchemaModifiersParams): Promise<ToolType> => {
43 - const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
44 - return this.wrapTool(tool);
45 - };
17 +import type { Tool, SchemaModifiersParams } from '@composio/core';
18 +
19 +export class NonAgenticToolset extends BaseNonAgenticToolset {
20 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: SchemaModifiersParams): Promise<Tool> {
21 + // Apply schema modifiers if provided
22 + if (modifiers?.schema) {
23 + return modifiers.schema(toolSlug, tool);
24 + }
25 + return tool;
26 + }
27 +
28 + async getTools(): Promise<Tool[]> {
29 + // Fetch tools from Composio API
30 + const response = await this.client.getTools();
31 + return response.data;
32 + }
33 +
34 + async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<Tool> {
35 + // Fetch tool from Composio API
36 + const response = await this.client.getToolBySlug(slug);
37 + // Apply schema modifiers if provided
38 + return this.wrapTool(slug, response.data, modifiers);
39 + }
40 }
41 ```
42
43 ### 2. Agentic Toolsets
44
51 -These toolsets support full modifier capabilities including tool execution modifiers, schema modifiers, and custom modifiers. They are suitable for more complex integrations like Vercel, Langchain, etc.
45 +These toolsets support full modifier capabilities, making them suitable for complex integrations like Vercel, Langchain, etc. They support:
46 +
47 +1. **Schema Modifiers**: Transform tool schemas using `TransformToolSchemaModifier`
48 +2. **Execution Modifiers**: Transform tool execution behavior
49 + - `beforeToolExecute`: Transform input parameters before execution
50 + - `afterToolExecute`: Transform output after execution
51 +3. **Execute Modifiers**: Used during tool execution
52 + - `beforeToolExecute`: Transform input parameters
53 + - `afterToolExecute`: Transform output
54 +
55 +Example implementation:
56
57 ```typescript
58 import { BaseAgenticToolset } from '@composio/core';
55 -import type { Tool, ToolListParams, ModifiersParams } from '@composio/core';
59 +import type { Tool, ModifiersParams, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
60 +
61 +export class AgenticToolset extends BaseAgenticToolset {
62 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: ModifiersParams): Promise<Tool> {
63 + let wrappedTool = tool;
64 +
65 + // Apply schema modifiers if provided
66 + if (modifiers?.schema) {
67 + wrappedTool = modifiers.schema(toolSlug, wrappedTool);
68 + }
69 +
70 + return wrappedTool;
71 + }
72 +
73 + async getTools(modifiers?: ModifiersParams): Promise<Tool[]> {
74 + // Fetch tools from Composio API
75 + const response = await this.client.getTools();
76 + // Apply modifiers to each tool
77 + return Promise.all(response.data.map(tool => this.wrapTool(tool.slug, tool, modifiers)));
78 + }
79 +
80 + async getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<Tool> {
81 + // Fetch tool from Composio API
82 + const response = await this.client.getToolBySlug(slug);
83 + // Apply modifiers
84 + return this.wrapTool(slug, response.data, modifiers);
85 + }
86 +
87 + async executeTool(
88 + tool: Tool,
89 + params: ToolExecuteParams,
90 + modifiers?: ModifiersParams
91 + ): Promise<ToolExecuteResponse> {
92 + let executeParams = params;
93
57 -interface ToolType {
58 - // Define your tool type here
59 -}
94 + // Apply beforeToolExecute modifier if provided
95 + if (modifiers?.beforeToolExecute) {
96 + executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
97 + }
98
61 -interface ToolCollection {
62 - // Define your tool collection here
63 -}
99 + // Execute the tool
100 + const response = await this.client.executeTool(tool.slug, executeParams);
101
65 -export class AgenticToolset extends BaseAgenticToolset<ToolCollection, ToolType> {
66 - static FRAMEWORK_NAME = 'agentic-toolset';
67 - readonly FILE_NAME: string = 'toolsets/agentic-toolset/src/index.ts';
102 + // Apply afterToolExecute modifier if provided
103 + if (modifiers?.afterToolExecute) {
104 + return modifiers.afterToolExecute(tool.slug, response.data);
105 + }
106
69 - wrapTool = (tool: Tool): ToolType => {
70 - // Implement tool wrapping logic
71 - return tool as ToolType;
72 - };
73 -
74 - getTools = async (
75 - params?: ToolListParams,
76 - modifiers?: ModifiersParams
77 - ): Promise<ToolCollection> => {
78 - // Implement tool collection logic with full modifier support
79 - return [];
80 - };
81 -
82 - getToolBySlug = async (slug: string, modifiers?: ModifiersParams): Promise<ToolType> => {
83 - const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
84 - return this.wrapTool(tool);
85 - };
107 + return response.data;
108 + }
109 }
110 ```
111
@@ -92,13 +115,13 @@ To create a new toolset, you can use the provided script:
115
116 ```bash
117 # Create a non-agentic toolset (default)
95 -pnpm run create-toolset <toolset-name>
118 +pnpm run create-toolset <your-toolset-name>
119
120 # Create an agentic toolset
98 -pnpm run create-toolset <toolset-name> --agentic
121 +pnpm run create-toolset <your-toolset-name> --agentic
122 ```
123
101 -This will create a new toolset with the following structure:
124 +The script will create a new toolset with the following structure:
125
126 ```
127 <toolset-name>/
@@ -110,93 +133,275 @@ This will create a new toolset with the following structure:
133 └── README.md # Toolset documentation
134 ```
135
113 -### Required Methods
136 +## Required Methods
137
115 -1. `wrapTool`: This method is responsible for wrapping a tool in the toolset's specific format.
116 -2. `getTools`: This method retrieves all available tools from the Composio API.
117 -3. `getToolBySlug`: This method retrieves a specific tool by its slug.
138 +Each toolset must implement the following methods:
139
119 -### Configuration
140 +### For Non-Agentic Toolsets
141
121 -Each toolset comes with the following configuration files:
142 +```typescript
143 +class NonAgenticToolset extends BaseNonAgenticToolset {
144 + // Wrap a tool with schema modifiers
145 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: SchemaModifiersParams): Promise<Tool>;
146
123 -- `package.json`: Contains dependencies and build scripts
124 -- `tsconfig.json`: TypeScript configuration
125 -- `tsup.config.ts`: Build configuration for the toolset
147 + // Get all available tools
148 + async getTools(modifiers?: SchemaModifiersParams): Promise<Tool[]>;
149
127 -## Building and Testing
150 + // Get a specific tool by slug
151 + async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<Tool>;
152 +}
153 +```
154
129 -To build your toolset:
155 +### For Agentic Toolsets
156
131 -```bash
132 -cd packages/toolsets/<toolset-name>
133 -pnpm build
157 +```typescript
158 +class AgenticToolset extends BaseAgenticToolset {
159 + // Wrap a tool with modifiers
160 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: ModifiersParams): Promise<Tool>;
161 +
162 + // Get all available tools
163 + async getTools(modifiers?: ModifiersParams): Promise<Tool[]>;
164 +
165 + // Get a specific tool by slug
166 + async getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<Tool>;
167 +
168 + // Execute a tool with modifiers
169 + async executeTool(
170 + tool: Tool,
171 + params: ToolExecuteParams,
172 + modifiers?: ModifiersParams
173 + ): Promise<ToolExecuteResponse>;
174 +}
175 +```
176 +
177 +## Modifier Types
178 +
179 +### Schema Modifiers (Both Types)
180 +
181 +```typescript
182 +type SchemaModifiersParams = {
183 + schema?: TransformToolSchemaModifier;
184 +};
185 +
186 +type TransformToolSchemaModifier = (toolSlug: string, tool: Tool) => Tool;
187 +```
188 +
189 +### Execution Modifiers (Agentic Only)
190 +
191 +```typescript
192 +type ModifiersParams = {
193 + schema?: TransformToolSchemaModifier;
194 + beforeToolExecute?: BeforeToolExecuteModifier;
195 + afterToolExecute?: AfterToolExecuteModifier;
196 +};
197 +
198 +type BeforeToolExecuteModifier = (toolSlug: string, params: ToolExecuteParams) => ToolExecuteParams;
199 +type AfterToolExecuteModifier = (
200 + toolSlug: string,
201 + response: ToolExecuteResponse
202 +) => ToolExecuteResponse;
203 ```
204
205 ## Best Practices
206
138 -1. **Type Safety**: Always define proper TypeScript interfaces for your tools and collections
139 -2. **Error Handling**: Implement proper error handling in your tool methods
140 -3. **Documentation**: Document your tools and their parameters clearly
141 -4. **Testing**: Write unit tests for your toolset functionality
207 +1. **Type Safety**: Always use TypeScript and ensure proper type definitions for all methods and parameters.
208 +2. **Error Handling**: Implement proper error handling for API calls and tool execution.
209 +3. **Documentation**: Document your toolset's features, requirements, and usage examples.
210 +4. **Testing**: Write tests for your toolset implementation.
211 5. **Modifier Support**:
212 - For non-agentic toolsets, implement schema modifiers to transform tool schemas
144 - - For agentic toolsets, implement full modifier support including execution and custom modifiers
213 + - For agentic toolsets, implement both schema and execution modifiers for full control over tool behavior
214
215 ## Example Implementation
216
148 -Here's a simple example of implementing a non-agentic toolset:
217 +Here's a complete example of a non-agentic toolset implementation:
218
219 ```typescript
151 -interface MyToolType {
152 - name: string;
153 - description: string;
154 - execute: (params: any) => Promise<any>;
220 +import { BaseNonAgenticToolset } from '@composio/core';
221 +import type { Tool, SchemaModifiersParams } from '@composio/core';
222 +
223 +export class OpenAIToolset extends BaseNonAgenticToolset {
224 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: SchemaModifiersParams): Promise<Tool> {
225 + // Apply schema modifiers if provided
226 + if (modifiers?.schema) {
227 + return modifiers.schema(toolSlug, tool);
228 + }
229 + return tool;
230 + }
231 +
232 + async getTools(modifiers?: SchemaModifiersParams): Promise<Tool[]> {
233 + // Fetch tools from Composio API
234 + const response = await this.client.getTools();
235 + // Apply modifiers to each tool
236 + return Promise.all(response.data.map(tool => this.wrapTool(tool.slug, tool, modifiers)));
237 + }
238 +
239 + async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<Tool> {
240 + // Fetch tool from Composio API
241 + const response = await this.client.getToolBySlug(slug);
242 + // Apply modifiers
243 + return this.wrapTool(slug, response.data, modifiers);
244 + }
245 }
246 +```
247
157 -interface MyToolCollection {
158 - [key: string]: MyToolType;
159 -}
248 +And here's a complete example of an agentic toolset implementation:
249
161 -export class MyNonAgenticToolset extends BaseNonAgenticToolset<MyToolCollection, MyToolType> {
162 - static FRAMEWORK_NAME = 'my-toolset';
163 - readonly FILE_NAME: string = 'toolsets/my-toolset/src/index.ts';
164 -
165 - wrapTool = (tool: Tool): MyToolType => {
166 - return {
167 - name: tool.name,
168 - description: tool.description,
169 - execute: async params => {
170 - // Implement tool execution logic
171 - return await this.getComposio().tools.execute(tool.slug, params);
172 - },
173 - };
174 - };
175 -
176 - getTools = async (
177 - params?: ToolListParams,
178 - modifiers?: SchemaModifiersParams
179 - ): Promise<MyToolCollection> => {
180 - const tools = await this.getComposio().tools.getTools(params, modifiers?.schema);
181 - return tools.reduce((acc, tool) => {
182 - acc[tool.slug] = this.wrapTool(tool);
183 - return acc;
184 - }, {} as MyToolCollection);
185 - };
186 -
187 - getToolBySlug = async (slug: string, modifiers?: SchemaModifiersParams): Promise<MyToolType> => {
188 - const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
189 - return this.wrapTool(tool);
190 - };
250 +```typescript
251 +import { BaseAgenticToolset } from '@composio/core';
252 +import type { Tool, ModifiersParams, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
253 +
254 +export class VercelToolset extends BaseAgenticToolset {
255 + async wrapTool(toolSlug: string, tool: Tool, modifiers?: ModifiersParams): Promise<Tool> {
256 + let wrappedTool = tool;
257 +
258 + // Apply schema modifiers if provided
259 + if (modifiers?.schema) {
260 + wrappedTool = modifiers.schema(toolSlug, wrappedTool);
261 + }
262 +
263 + return wrappedTool;
264 + }
265 +
266 + async getTools(modifiers?: ModifiersParams): Promise<Tool[]> {
267 + // Fetch tools from Composio API
268 + const response = await this.client.getTools();
269 + // Apply modifiers to each tool
270 + return Promise.all(response.data.map(tool => this.wrapTool(tool.slug, tool, modifiers)));
271 + }
272 +
273 + async getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<Tool> {
274 + // Fetch tool from Composio API
275 + const response = await this.client.getToolBySlug(slug);
276 + // Apply modifiers
277 + return this.wrapTool(slug, response.data, modifiers);
278 + }
279 +
280 + async executeTool(
281 + tool: Tool,
282 + params: ToolExecuteParams,
283 + modifiers?: ModifiersParams
284 + ): Promise<ToolExecuteResponse> {
285 + let executeParams = params;
286 +
287 + // Apply beforeToolExecute modifier if provided
288 + if (modifiers?.beforeToolExecute) {
289 + executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
290 + }
291 +
292 + // Execute the tool
293 + const response = await this.client.executeTool(tool.slug, executeParams);
294 +
295 + // Apply afterToolExecute modifier if provided
296 + if (modifiers?.afterToolExecute) {
297 + return modifiers.afterToolExecute(tool.slug, response.data);
298 + }
299 +
300 + return response.data;
301 + }
302 }
303 ```
304
194 -## Contributing
305 +## Usage Examples
306 +
307 +### Using a Non-Agentic Toolset
308
196 -When contributing a new toolset:
309 +```typescript
310 +import { Composio } from '@composio/core';
311 +import { OpenAIToolset } from '@composio/openai-toolset';
312 +import type { Tool } from '@composio/core';
313 +
314 +const composio = new Composio({
315 + apiKey: process.env.COMPOSIO_API_KEY,
316 + toolset: new OpenAIToolset(),
317 +});
318 +
319 +// Get a tool with schema modifiers
320 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
321 + schema: (toolSlug: string, tool: Tool) => ({
322 + ...tool,
323 + description: 'Search HackerNews posts with improved description',
324 + inputParameters: {
325 + ...tool.inputParameters,
326 + limit: {
327 + type: 'number',
328 + description: 'Maximum number of posts to return',
329 + },
330 + },
331 + }),
332 +});
333 +```
334
198 -1. Follow the existing code style and patterns
199 -2. Include proper documentation
200 -3. Add tests for your implementation
201 -4. Update this README if necessary
202 -5. Choose the appropriate base class (agentic or non-agentic) based on your toolset's needs
335 +### Using an Agentic Toolset
336 +
337 +```typescript
338 +import { Composio } from '@composio/core';
339 +import { VercelToolset } from '@composio/vercel-toolset';
340 +import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
341 +
342 +const composio = new Composio({
343 + apiKey: process.env.COMPOSIO_API_KEY,
344 + toolset: new VercelToolset(),
345 +});
346 +
347 +// Get a tool with full modifier support
348 +const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
349 + // Schema modifier
350 + schema: (toolSlug: string, tool: Tool) => ({
351 + ...tool,
352 + description: 'Search HackerNews posts with improved description',
353 + inputParameters: {
354 + ...tool.inputParameters,
355 + limit: {
356 + type: 'number',
357 + description: 'Maximum number of posts to return',
358 + },
359 + },
360 + }),
361 + // Execution modifiers
362 + beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
363 + ...params,
364 + arguments: {
365 + ...params.arguments,
366 + limit: Math.min((params.arguments?.limit as number) || 10, 100),
367 + },
368 + }),
369 + afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
370 + ...response,
371 + data: {
372 + ...response.data,
373 + posts: (response.data?.posts as any[]).map(post => ({
374 + ...post,
375 + url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
376 + })),
377 + },
378 + }),
379 +});
380 +
381 +// Execute the tool with execution modifiers
382 +const result = await composio.toolset.executeTool(
383 + tool,
384 + {
385 + arguments: { query: 'AI', limit: 20 },
386 + },
387 + {
388 + beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
389 + ...params,
390 + arguments: {
391 + ...params.arguments,
392 + limit: Math.min((params.arguments?.limit as number) || 10, 100),
393 + },
394 + }),
395 + afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
396 + ...response,
397 + data: {
398 + ...response.data,
399 + posts: (response.data?.posts as any[]).map(post => ({
400 + ...post,
401 + url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
402 + })),
403 + },
404 + }),
405 + }
406 +);
407 +```