Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Base openai toolset
haxzie committed
Apr 16, 2025 at 13:34 UTC
9461c44145fd9e5cf2e1fd9a7601e74b497ad400
8 files changed
+51
-25
packages/core/package.json
+2
-1
@@ -18,6 +18,7 @@
18
"typescript": "^5.8.3"
19
},
20
"dependencies": {
21
- "@composio/client": "0.1.0-alpha.1"
21
+ "@composio/client": "0.1.0-alpha.1",
22
+ "@composio/openai-toolset": "workspace:^"
23
}
24
}
packages/core/src/composio.ts
+3
-2
@@ -3,8 +3,9 @@ import { Tools } from "./models/Tools";
3
import { Toolkits } from "./models/Toolkits";
4
import { Triggers } from "./models/Triggers";
5
import { ComposioToolset } from "./toolset/ComposioToolset";
6
+import { OpenAIToolset} from "@composio/openai-toolset";
7
import { Toolset, WrappedTool } from "./types/toolset.types.";
7
-import { Tool } from "./types/tool.types";
8
+import { BaseTool, Tool } from "./types/tool.types";
9
import { AuthConfigs } from "./models/AuthConfigs";
10
import { ConnectedAccounts } from "./models/ConnectedAccounts";
11
import { ToolListParams } from "@composio/client/resources/tools";
@@ -69,7 +70,7 @@ export class Composio<T extends Toolset<any>> {
70
/**
71
* Set the default toolset, if not provided by the user.
72
*/
72
- const defaultToolset = new ComposioToolset();
73
+ const defaultToolset = new OpenAIToolset();
74
this.toolset = config.toolset ?? (defaultToolset as unknown as T);
75
this.toolset.setClient(this);
76
packages/core/src/toolset/BaseToolset.ts
+23
-5
@@ -1,5 +1,5 @@
1
import { Toolset } from "../types/toolset.types.";
2
-import { Tool } from "../types/tool.types";
2
+import { Tool, BaseTool } from "../types/tool.types";
3
import { Composio } from "../composio";
4
5
/**
@@ -12,20 +12,38 @@ import { Composio } from "../composio";
12
*
13
* eg:
14
* ```ts
15
- * class MyToolset extends BaseComposioToolset<MyTool> {
16
- * _wrapTool(tool: BaseTool): MyTool {}
17
- * }
15
+ * // Using default BaseTool type
16
+ * class DefaultToolset extends BaseComposioToolset {}
17
+ *
18
+ * // Using a custom tool type
19
+ * class MyToolset extends BaseComposioToolset<MyCustomTool> {}
20
+ *
21
+ * // Using a third-party tool type
22
+ * class ThirdPartyToolset extends BaseComposioToolset<ThirdPartyTool> {}
23
* ```
24
*/
20
-export abstract class BaseComposioToolset<TTool> implements Toolset<TTool> {
25
+export abstract class BaseComposioToolset<TTool = BaseTool> implements Toolset<TTool> {
26
protected client: Composio<Toolset<TTool>> | undefined;
27
28
+ /**
29
+ * Set the client for the toolset. This is automatically done by the Composio class.
30
+ * @param client - The Composio client.
31
+ */
32
setClient(client: Composio<Toolset<TTool>>): void {
33
this.client = client;
34
}
35
36
+ /**
37
+ * Wrap a tool in the toolset.
38
+ * @param tool - The tool to wrap.
39
+ * @returns The wrapped tool.
40
+ */
41
abstract _wrapTool(tool: Tool): TTool;
42
43
+ /**
44
+ * Ensure the client is initialized.
45
+ * This is automatically done by the Composio class.
46
+ */
47
protected ensureClient(): void {
48
if (!this.client) {
49
throw new Error('Client not initialized. Make sure the toolset is properly initialized with Composio.');
packages/core/src/toolset/ComposioToolset.ts
+7
-13
@@ -9,20 +9,14 @@ import { BaseComposioToolset } from "./BaseToolset";
9
* This class shouldn't be used directly or to be extended.
10
*/
11
12
-export class ComposioToolset extends BaseComposioToolset<Tool> {
12
+interface CustomTool {
13
+ name: string;
14
+}
15
+export class ComposioToolset extends BaseComposioToolset<CustomTool> {
16
14
- _wrapTool = (tool: Tool): Tool => {
15
- return tool as Tool;
17
+ _wrapTool = (tool: Tool): CustomTool => {
18
+ return tool as CustomTool;
19
};
20
21
async test() {}
19
-}
20
-
21
-
22
-const composio = new Composio({
23
- apiKey: process.env.COMPOSIO_API_KEY,
24
- toolset: new ComposioToolset(),
25
-});
26
-
27
-composio.toolset.test();
28
-composio.getTool("123");
\ No newline at end of file
22
+}
\ No newline at end of file
packages/core/src/types/Tool.types.ts
+10
-1
@@ -1,3 +1,12 @@
1
import { ToolListResponse, ToolRetrieveResponse } from "@composio/client/resources/tools";
2
3
-export type Tool = ToolRetrieveResponse;
\ No newline at end of file
3
+export type Tool = ToolRetrieveResponse;
4
+
5
+export interface BaseTool {
6
+ name: string;
7
+ description?: string;
8
+ input_parameters?: Record<string, any>;
9
+ output_parameters?: Record<string, any>;
10
+}
11
+
12
+export type ToolType<T extends BaseTool> = T;
\ No newline at end of file
packages/core/src/types/Toolset.types..ts
+2
-2
@@ -1,11 +1,11 @@
1
import { Composio } from "../composio";
2
-import { Tool } from "./tool.types";
2
+import { Tool, BaseTool } from "./tool.types";
3
4
/**
5
* Base toolset implementation, which needs to be implemented by the extended class.
6
* This class is used to create a base toolset by implementing this class.
7
*/
8
-export interface Toolset<TTool> {
8
+export interface Toolset<TTool = BaseTool> {
9
_wrapTool: (tool: Tool) => TTool;
10
setClient<T extends Toolset<TTool>>(client: Composio<T>): void;
11
}
packages/core/src/types/toolset.types.ts
+1
-1
@@ -1,7 +1,7 @@
1
import { Tool } from "./tool.types";
2
import { Composio } from "../composio";
3
4
-export interface Toolset<TTool> {
4
+export interface Toolset<TTool = Tool> {
5
_wrapTool(tool: Tool): TTool;
6
setClient(client: Composio<Toolset<TTool>>): void;
7
}
pnpm-lock.yaml
+3
@@ -13,6 +13,9 @@ importers:
13
'@composio/client':
14
specifier: 0.1.0-alpha.1
15
version: 0.1.0-alpha.1
16
+ '@composio/openai-toolset':
17
+ specifier: workspace:^
18
+ version: link:../toolsets/openai
19
devDependencies:
20
rolldown:
21
specifier: 1.0.0-beta.7