@composio/langchain 0.3.4 → 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.cjs +191 -209
- package/dist/index.d.cts +3314 -158
- package/dist/index.d.mts +3324 -0
- package/dist/index.mjs +193 -0
- package/package.json +19 -11
- package/dist/index.d.ts +0 -168
- package/dist/index.js +0 -189
package/dist/index.cjs
CHANGED
|
@@ -1,211 +1,193 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
let _composio_core = require("@composio/core");
|
|
2
|
+
let _langchain_core_tools = require("@langchain/core/tools");
|
|
19
3
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
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 _composio_core.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 = (0, _composio_core.jsonSchemaToZodSchema)(tool.inputParameters);
|
|
118
|
+
return new _langchain_core_tools.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
|
+
}
|
|
207
190
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
});
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
exports.LangchainProvider = LangchainProvider;
|