@composio/langchain 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,193 @@
1
+ import { BaseAgenticProvider, jsonSchemaToZodSchema } from "@composio/core";
2
+ import { DynamicStructuredTool } from "@langchain/core/tools";
3
+
4
+ //#region src/index.ts
5
+ /**
6
+ * Langchain Provider
7
+ *
8
+ * Author: Musthaq Ahamad <musthaq@composio.dev>
9
+ * Reference: https://github.com/ComposioHQ/composio/blob/master/js/src/frameworks/langchain.ts
10
+ *
11
+ * This provider provides a set of tools for interacting with Langchain.
12
+ *
13
+ * @packageDocumentation
14
+ * @module providers/langchain
15
+ */
16
+ var LangchainProvider = class extends BaseAgenticProvider {
17
+ name = "langchain";
18
+ /**
19
+ * Creates a new instance of the LangchainProvider.
20
+ *
21
+ * This provider enables integration with the Langchain framework,
22
+ * allowing Composio tools to be used with Langchain agents and chains.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Initialize the Langchain provider
27
+ * const provider = new LangchainProvider();
28
+ *
29
+ * // Use with Composio
30
+ * const composio = new Composio({
31
+ * apiKey: 'your-api-key',
32
+ * provider: new LangchainProvider()
33
+ * });
34
+ *
35
+ * // Use the provider to wrap tools for Langchain
36
+ * const langchainTools = provider.wrapTools(composioTools, composio.tools.execute);
37
+ * ```
38
+ */
39
+ constructor() {
40
+ super();
41
+ }
42
+ /**
43
+ * Transform MCP URL response into Anthropic-specific format.
44
+ * By default, Anthropic uses the standard format (same as default),
45
+ * but this method is here to show providers can customize if needed.
46
+ *
47
+ * @param data - The MCP URL response data
48
+ * @returns Standard MCP server response format
49
+ */
50
+ wrapMcpServerResponse(data) {
51
+ return data.map((item) => ({
52
+ url: new URL(item.url),
53
+ name: item.name
54
+ }));
55
+ }
56
+ /**
57
+ * Wraps a Composio tool in the Langchain DynamicStructuredTool format.
58
+ *
59
+ * This method transforms a Composio tool definition into a Langchain
60
+ * DynamicStructuredTool that can be used with Langchain agents and chains.
61
+ *
62
+ * @param tool - The Composio tool to wrap
63
+ * @param executeTool - Function to execute the tool
64
+ * @returns The wrapped tool as a Langchain DynamicStructuredTool
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // Wrap a single tool for use with Langchain
69
+ * const composioTool = {
70
+ * slug: 'SEARCH_TOOL',
71
+ * description: 'Search for information',
72
+ * toolkit: { name: 'search_toolkit' },
73
+ * inputParameters: {
74
+ * type: 'object',
75
+ * properties: {
76
+ * query: { type: 'string' }
77
+ * },
78
+ * required: ['query']
79
+ * }
80
+ * };
81
+ *
82
+ * // Create a Langchain tool using the provider
83
+ * const langchainTool = provider.wrapTool(
84
+ * composioTool,
85
+ * composio.tools.execute
86
+ * );
87
+ *
88
+ * // Use with Langchain
89
+ * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
90
+ * import { ChatOpenAI } from '@langchain/openai';
91
+ *
92
+ * const model = new ChatOpenAI({ temperature: 0 });
93
+ * const agent = await createOpenAIFunctionsAgent({
94
+ * llm: model,
95
+ * tools: [langchainTool]
96
+ * });
97
+ *
98
+ * const executor = new AgentExecutor({
99
+ * agent,
100
+ * tools: [langchainTool]
101
+ * });
102
+ *
103
+ * const result = await executor.invoke({
104
+ * input: "Search for information about Composio"
105
+ * });
106
+ * ```
107
+ */
108
+ wrapTool(tool, executeTool) {
109
+ const toolName = tool.slug;
110
+ const description = tool.description;
111
+ if (!tool.toolkit?.name?.toLowerCase()) throw new Error("App name is not defined");
112
+ const func = async (...args) => {
113
+ const result = await executeTool(toolName, args[0]);
114
+ return JSON.stringify(result);
115
+ };
116
+ if (!tool.inputParameters) throw new Error("Tool input parameters are not defined");
117
+ const parameters = jsonSchemaToZodSchema(tool.inputParameters);
118
+ return new DynamicStructuredTool({
119
+ name: toolName,
120
+ description: description || "",
121
+ schema: parameters,
122
+ func
123
+ });
124
+ }
125
+ /**
126
+ * Wraps a list of Composio tools in the Langchain DynamicStructuredTool format.
127
+ *
128
+ * This method transforms multiple Composio tool definitions into Langchain
129
+ * DynamicStructuredTools that can be used with Langchain agents and chains.
130
+ *
131
+ * @param tools - Array of Composio tools to wrap
132
+ * @param executeTool - Function to execute the tools
133
+ * @returns Array of wrapped tools as Langchain DynamicStructuredTools
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // Wrap multiple tools for use with Langchain
138
+ * const composioTools = [
139
+ * {
140
+ * slug: 'SEARCH_TOOL',
141
+ * description: 'Search for information',
142
+ * toolkit: { name: 'search_toolkit' },
143
+ * inputParameters: {
144
+ * type: 'object',
145
+ * properties: {
146
+ * query: { type: 'string' }
147
+ * },
148
+ * required: ['query']
149
+ * }
150
+ * },
151
+ * {
152
+ * slug: 'WEATHER_TOOL',
153
+ * description: 'Get weather information',
154
+ * toolkit: { name: 'weather_toolkit' },
155
+ * inputParameters: {
156
+ * type: 'object',
157
+ * properties: {
158
+ * location: { type: 'string' }
159
+ * },
160
+ * required: ['location']
161
+ * }
162
+ * }
163
+ * ];
164
+ *
165
+ * // Create Langchain tools using the provider
166
+ * const langchainTools = provider.wrapTools(
167
+ * composioTools,
168
+ * composio.tools.execute
169
+ * );
170
+ *
171
+ * // Use with Langchain
172
+ * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
173
+ * import { ChatOpenAI } from '@langchain/openai';
174
+ *
175
+ * const model = new ChatOpenAI({ temperature: 0 });
176
+ * const agent = await createOpenAIFunctionsAgent({
177
+ * llm: model,
178
+ * tools: langchainTools
179
+ * });
180
+ *
181
+ * const executor = new AgentExecutor({
182
+ * agent,
183
+ * tools: langchainTools
184
+ * });
185
+ * ```
186
+ */
187
+ wrapTools(tools, executeTool) {
188
+ return tools.map((tool) => this.wrapTool(tool, executeTool));
189
+ }
190
+ };
191
+
192
+ //#endregion
193
+ export { LangchainProvider };
package/package.json CHANGED
@@ -1,17 +1,25 @@
1
1
  {
2
2
  "name": "@composio/langchain",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
- "main": "dist/index.js",
6
- "type": "module",
5
+ "main": "dist/index.mjs",
7
6
  "publishConfig": {
8
7
  "access": "public"
9
8
  },
10
9
  "exports": {
11
10
  ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
- "require": "./dist/index.cjs"
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ },
19
+ "default": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
15
23
  }
16
24
  },
17
25
  "files": [
@@ -22,22 +30,22 @@
22
30
  "author": "",
23
31
  "license": "ISC",
24
32
  "peerDependencies": {
25
- "@composio/core": "0.4.0",
33
+ "@composio/core": "0.5.0",
26
34
  "@langchain/core": "^1.1.4"
27
35
  },
28
36
  "devDependencies": {
29
37
  "@langchain/core": "^1.1.4",
30
- "tsup": "^8.5.0",
38
+ "tsdown": "^0.18.4",
31
39
  "typescript": "^5.9.2",
32
40
  "vitest": "^3.2.4",
33
41
  "zod": "^4.1.0",
34
- "@composio/core": "0.4.0"
42
+ "@composio/core": "0.5.0"
35
43
  },
36
44
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
37
45
  "scripts": {
38
46
  "clean": "git clean -xdf node_modules",
39
- "build": "tsup",
47
+ "build": "tsdown",
40
48
  "test": "vitest run"
41
49
  },
42
- "types": "dist/index.d.ts"
50
+ "types": "dist/index.d.mts"
43
51
  }
package/dist/index.d.ts DELETED
@@ -1,168 +0,0 @@
1
- import { BaseAgenticProvider, McpServerGetResponse, McpUrlResponse, Tool, ExecuteToolFn } from '@composio/core';
2
- import { DynamicStructuredTool } from '@langchain/core/tools';
3
-
4
- /**
5
- * Langchain Provider
6
- *
7
- * Author: Musthaq Ahamad <musthaq@composio.dev>
8
- * Reference: https://github.com/ComposioHQ/composio/blob/master/js/src/frameworks/langchain.ts
9
- *
10
- * This provider provides a set of tools for interacting with Langchain.
11
- *
12
- * @packageDocumentation
13
- * @module providers/langchain
14
- */
15
-
16
- type LangChainToolCollection = Array<DynamicStructuredTool>;
17
- declare class LangchainProvider extends BaseAgenticProvider<LangChainToolCollection, DynamicStructuredTool, McpServerGetResponse> {
18
- readonly name = "langchain";
19
- /**
20
- * Creates a new instance of the LangchainProvider.
21
- *
22
- * This provider enables integration with the Langchain framework,
23
- * allowing Composio tools to be used with Langchain agents and chains.
24
- *
25
- * @example
26
- * ```typescript
27
- * // Initialize the Langchain provider
28
- * const provider = new LangchainProvider();
29
- *
30
- * // Use with Composio
31
- * const composio = new Composio({
32
- * apiKey: 'your-api-key',
33
- * provider: new LangchainProvider()
34
- * });
35
- *
36
- * // Use the provider to wrap tools for Langchain
37
- * const langchainTools = provider.wrapTools(composioTools, composio.tools.execute);
38
- * ```
39
- */
40
- constructor();
41
- /**
42
- * Transform MCP URL response into Anthropic-specific format.
43
- * By default, Anthropic uses the standard format (same as default),
44
- * but this method is here to show providers can customize if needed.
45
- *
46
- * @param data - The MCP URL response data
47
- * @returns Standard MCP server response format
48
- */
49
- wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
50
- /**
51
- * Wraps a Composio tool in the Langchain DynamicStructuredTool format.
52
- *
53
- * This method transforms a Composio tool definition into a Langchain
54
- * DynamicStructuredTool that can be used with Langchain agents and chains.
55
- *
56
- * @param tool - The Composio tool to wrap
57
- * @param executeTool - Function to execute the tool
58
- * @returns The wrapped tool as a Langchain DynamicStructuredTool
59
- *
60
- * @example
61
- * ```typescript
62
- * // Wrap a single tool for use with Langchain
63
- * const composioTool = {
64
- * slug: 'SEARCH_TOOL',
65
- * description: 'Search for information',
66
- * toolkit: { name: 'search_toolkit' },
67
- * inputParameters: {
68
- * type: 'object',
69
- * properties: {
70
- * query: { type: 'string' }
71
- * },
72
- * required: ['query']
73
- * }
74
- * };
75
- *
76
- * // Create a Langchain tool using the provider
77
- * const langchainTool = provider.wrapTool(
78
- * composioTool,
79
- * composio.tools.execute
80
- * );
81
- *
82
- * // Use with Langchain
83
- * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
84
- * import { ChatOpenAI } from '@langchain/openai';
85
- *
86
- * const model = new ChatOpenAI({ temperature: 0 });
87
- * const agent = await createOpenAIFunctionsAgent({
88
- * llm: model,
89
- * tools: [langchainTool]
90
- * });
91
- *
92
- * const executor = new AgentExecutor({
93
- * agent,
94
- * tools: [langchainTool]
95
- * });
96
- *
97
- * const result = await executor.invoke({
98
- * input: "Search for information about Composio"
99
- * });
100
- * ```
101
- */
102
- wrapTool(tool: Tool, executeTool: ExecuteToolFn): DynamicStructuredTool;
103
- /**
104
- * Wraps a list of Composio tools in the Langchain DynamicStructuredTool format.
105
- *
106
- * This method transforms multiple Composio tool definitions into Langchain
107
- * DynamicStructuredTools that can be used with Langchain agents and chains.
108
- *
109
- * @param tools - Array of Composio tools to wrap
110
- * @param executeTool - Function to execute the tools
111
- * @returns Array of wrapped tools as Langchain DynamicStructuredTools
112
- *
113
- * @example
114
- * ```typescript
115
- * // Wrap multiple tools for use with Langchain
116
- * const composioTools = [
117
- * {
118
- * slug: 'SEARCH_TOOL',
119
- * description: 'Search for information',
120
- * toolkit: { name: 'search_toolkit' },
121
- * inputParameters: {
122
- * type: 'object',
123
- * properties: {
124
- * query: { type: 'string' }
125
- * },
126
- * required: ['query']
127
- * }
128
- * },
129
- * {
130
- * slug: 'WEATHER_TOOL',
131
- * description: 'Get weather information',
132
- * toolkit: { name: 'weather_toolkit' },
133
- * inputParameters: {
134
- * type: 'object',
135
- * properties: {
136
- * location: { type: 'string' }
137
- * },
138
- * required: ['location']
139
- * }
140
- * }
141
- * ];
142
- *
143
- * // Create Langchain tools using the provider
144
- * const langchainTools = provider.wrapTools(
145
- * composioTools,
146
- * composio.tools.execute
147
- * );
148
- *
149
- * // Use with Langchain
150
- * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
151
- * import { ChatOpenAI } from '@langchain/openai';
152
- *
153
- * const model = new ChatOpenAI({ temperature: 0 });
154
- * const agent = await createOpenAIFunctionsAgent({
155
- * llm: model,
156
- * tools: langchainTools
157
- * });
158
- *
159
- * const executor = new AgentExecutor({
160
- * agent,
161
- * tools: langchainTools
162
- * });
163
- * ```
164
- */
165
- wrapTools(tools: Tool[], executeTool: ExecuteToolFn): LangChainToolCollection;
166
- }
167
-
168
- export { type LangChainToolCollection, LangchainProvider };
package/dist/index.js DELETED
@@ -1,189 +0,0 @@
1
- // src/index.ts
2
- import {
3
- BaseAgenticProvider,
4
- jsonSchemaToZodSchema
5
- } from "@composio/core";
6
- import { DynamicStructuredTool } from "@langchain/core/tools";
7
- var LangchainProvider = class extends BaseAgenticProvider {
8
- name = "langchain";
9
- /**
10
- * Creates a new instance of the LangchainProvider.
11
- *
12
- * This provider enables integration with the Langchain framework,
13
- * allowing Composio tools to be used with Langchain agents and chains.
14
- *
15
- * @example
16
- * ```typescript
17
- * // Initialize the Langchain provider
18
- * const provider = new LangchainProvider();
19
- *
20
- * // Use with Composio
21
- * const composio = new Composio({
22
- * apiKey: 'your-api-key',
23
- * provider: new LangchainProvider()
24
- * });
25
- *
26
- * // Use the provider to wrap tools for Langchain
27
- * const langchainTools = provider.wrapTools(composioTools, composio.tools.execute);
28
- * ```
29
- */
30
- constructor() {
31
- super();
32
- }
33
- /**
34
- * Transform MCP URL response into Anthropic-specific format.
35
- * By default, Anthropic uses the standard format (same as default),
36
- * but this method is here to show providers can customize if needed.
37
- *
38
- * @param data - The MCP URL response data
39
- * @returns Standard MCP server response format
40
- */
41
- wrapMcpServerResponse(data) {
42
- return data.map((item) => ({
43
- url: new URL(item.url),
44
- name: item.name
45
- }));
46
- }
47
- /**
48
- * Wraps a Composio tool in the Langchain DynamicStructuredTool format.
49
- *
50
- * This method transforms a Composio tool definition into a Langchain
51
- * DynamicStructuredTool that can be used with Langchain agents and chains.
52
- *
53
- * @param tool - The Composio tool to wrap
54
- * @param executeTool - Function to execute the tool
55
- * @returns The wrapped tool as a Langchain DynamicStructuredTool
56
- *
57
- * @example
58
- * ```typescript
59
- * // Wrap a single tool for use with Langchain
60
- * const composioTool = {
61
- * slug: 'SEARCH_TOOL',
62
- * description: 'Search for information',
63
- * toolkit: { name: 'search_toolkit' },
64
- * inputParameters: {
65
- * type: 'object',
66
- * properties: {
67
- * query: { type: 'string' }
68
- * },
69
- * required: ['query']
70
- * }
71
- * };
72
- *
73
- * // Create a Langchain tool using the provider
74
- * const langchainTool = provider.wrapTool(
75
- * composioTool,
76
- * composio.tools.execute
77
- * );
78
- *
79
- * // Use with Langchain
80
- * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
81
- * import { ChatOpenAI } from '@langchain/openai';
82
- *
83
- * const model = new ChatOpenAI({ temperature: 0 });
84
- * const agent = await createOpenAIFunctionsAgent({
85
- * llm: model,
86
- * tools: [langchainTool]
87
- * });
88
- *
89
- * const executor = new AgentExecutor({
90
- * agent,
91
- * tools: [langchainTool]
92
- * });
93
- *
94
- * const result = await executor.invoke({
95
- * input: "Search for information about Composio"
96
- * });
97
- * ```
98
- */
99
- wrapTool(tool, executeTool) {
100
- const toolName = tool.slug;
101
- const description = tool.description;
102
- const appName = tool.toolkit?.name?.toLowerCase();
103
- if (!appName) {
104
- throw new Error("App name is not defined");
105
- }
106
- const func = async (...args) => {
107
- const result = await executeTool(toolName, args[0]);
108
- return JSON.stringify(result);
109
- };
110
- if (!tool.inputParameters) {
111
- throw new Error("Tool input parameters are not defined");
112
- }
113
- const parameters = jsonSchemaToZodSchema(tool.inputParameters);
114
- return new DynamicStructuredTool({
115
- name: toolName,
116
- description: description || "",
117
- schema: parameters,
118
- func
119
- });
120
- }
121
- /**
122
- * Wraps a list of Composio tools in the Langchain DynamicStructuredTool format.
123
- *
124
- * This method transforms multiple Composio tool definitions into Langchain
125
- * DynamicStructuredTools that can be used with Langchain agents and chains.
126
- *
127
- * @param tools - Array of Composio tools to wrap
128
- * @param executeTool - Function to execute the tools
129
- * @returns Array of wrapped tools as Langchain DynamicStructuredTools
130
- *
131
- * @example
132
- * ```typescript
133
- * // Wrap multiple tools for use with Langchain
134
- * const composioTools = [
135
- * {
136
- * slug: 'SEARCH_TOOL',
137
- * description: 'Search for information',
138
- * toolkit: { name: 'search_toolkit' },
139
- * inputParameters: {
140
- * type: 'object',
141
- * properties: {
142
- * query: { type: 'string' }
143
- * },
144
- * required: ['query']
145
- * }
146
- * },
147
- * {
148
- * slug: 'WEATHER_TOOL',
149
- * description: 'Get weather information',
150
- * toolkit: { name: 'weather_toolkit' },
151
- * inputParameters: {
152
- * type: 'object',
153
- * properties: {
154
- * location: { type: 'string' }
155
- * },
156
- * required: ['location']
157
- * }
158
- * }
159
- * ];
160
- *
161
- * // Create Langchain tools using the provider
162
- * const langchainTools = provider.wrapTools(
163
- * composioTools,
164
- * composio.tools.execute
165
- * );
166
- *
167
- * // Use with Langchain
168
- * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
169
- * import { ChatOpenAI } from '@langchain/openai';
170
- *
171
- * const model = new ChatOpenAI({ temperature: 0 });
172
- * const agent = await createOpenAIFunctionsAgent({
173
- * llm: model,
174
- * tools: langchainTools
175
- * });
176
- *
177
- * const executor = new AgentExecutor({
178
- * agent,
179
- * tools: langchainTools
180
- * });
181
- * ```
182
- */
183
- wrapTools(tools, executeTool) {
184
- return tools.map((tool) => this.wrapTool(tool, executeTool));
185
- }
186
- };
187
- export {
188
- LangchainProvider
189
- };