@cloudbase/agent-adapter-langchain 0.0.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # @cloudbase/agent-adapter-langchain
2
+
3
+ ## 0.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - stable release 0.0.10
8
+ - Update all public packages to version 0.0.10
9
+ - Trigger automated stable release workflow
10
+ - Includes latest features and improvements
11
+
12
+ - Updated dependencies
13
+ - @cloudbase/agent-tools@0.0.10
14
+ - @cloudbase/agent-agents@0.0.10
15
+ - @cloudbase/agent-adapter-langgraph@0.0.10
16
+
17
+ ## 0.0.10-alpha.1
18
+
19
+ ### Patch Changes
20
+
21
+ - alpha release 0.0.9-alpha.3
22
+ - Update all public packages to version 0.0.9-alpha.3
23
+ - Trigger automated alpha release workflow
24
+ - Includes latest features and improvements
25
+
26
+ - Updated dependencies
27
+ - @cloudbase/agent-tools@0.0.10-alpha.1
28
+ - @cloudbase/agent-agents@0.0.10-alpha.1
29
+ - @cloudbase/agent-adapter-langgraph@0.0.10-alpha.1
30
+
31
+ ## 0.0.10-alpha.0
32
+
33
+ ### Patch Changes
34
+
35
+ - alpha release 0.0.9-alpha.3
36
+ - Update all public packages to version 0.0.9-alpha.3
37
+ - Trigger automated alpha release workflow
38
+ - Includes latest features and improvements
39
+
40
+ - Updated dependencies
41
+ - @cloudbase/agent-tools@0.0.10-alpha.0
42
+ - @cloudbase/agent-agents@0.0.10-alpha.0
43
+ - @cloudbase/agent-adapter-langgraph@0.0.10-alpha.0
@@ -0,0 +1,219 @@
1
+ import { MemoryClient, IMemoryClientOptions } from '@cloudbase/agent-agents';
2
+ import { BaseStore } from '@langchain/core/stores';
3
+ import * as _cloudbase_agent_tools from '@cloudbase/agent-tools';
4
+ import { BaseTool } from '@cloudbase/agent-tools';
5
+ import * as langchain from 'langchain';
6
+ import { createAgent } from 'langchain';
7
+ import { StructuredTool } from '@langchain/core/tools';
8
+ import { z } from 'zod/v3';
9
+ import { AgentConfig } from '@cloudbase/agent-agents/abstract';
10
+ import { LanggraphAgent } from '@cloudbase/agent-adapter-langgraph';
11
+ import { BaseListChatMessageHistory } from '@langchain/core/chat_history';
12
+ import { BaseMessage } from '@langchain/core/messages';
13
+
14
+ /**
15
+ * Configuration options for TDAIStore
16
+ */
17
+ interface TDAIStoreInput {
18
+ /**
19
+ * The TDAI Memory Client instance
20
+ */
21
+ client: MemoryClient;
22
+ /**
23
+ * The amount of keys to retrieve per batch when yielding keys.
24
+ * @default 1000
25
+ */
26
+ yieldKeysScanBatchSize?: number;
27
+ /**
28
+ * The namespace to use for the keys in the database.
29
+ */
30
+ namespace?: string;
31
+ /**
32
+ * Default session ID for storing records
33
+ */
34
+ defaultSessionId?: string;
35
+ /**
36
+ * Default strategy for storing records
37
+ */
38
+ defaultStrategy?: string;
39
+ /**
40
+ * TTL for records in seconds
41
+ */
42
+ ttlSeconds?: number;
43
+ }
44
+ /**
45
+ * TDAI implementation of the BaseStore for key-value caching.
46
+ * Uses TDAI Memory Client for persistent storage.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const client = new MemoryClient({
51
+ * endpoint: "https://memory.tdai.tencentyun.com",
52
+ * apiKey: "your-api-key",
53
+ * memoryId: "your-memory-id",
54
+ * });
55
+ *
56
+ * const store = new TDAIStore({
57
+ * client,
58
+ * namespace: "cache",
59
+ * });
60
+ *
61
+ * const encoder = new TextEncoder();
62
+ * await store.mset([
63
+ * ["key1", encoder.encode("value1")],
64
+ * ["key2", encoder.encode("value2")],
65
+ * ]);
66
+ *
67
+ * const values = await store.mget(["key1", "key2"]);
68
+ * ```
69
+ */
70
+ declare class TDAIStore extends BaseStore<string, Uint8Array> {
71
+ lc_namespace: string[];
72
+ protected client: MemoryClient;
73
+ protected namespace?: string;
74
+ protected yieldKeysScanBatchSize: number;
75
+ protected defaultSessionId: string;
76
+ protected defaultStrategy: string;
77
+ protected ttlSeconds?: number;
78
+ private sessionCache?;
79
+ constructor(fields: TDAIStoreInput);
80
+ /**
81
+ * Get prefixed key with namespace
82
+ */
83
+ private _getPrefixedKey;
84
+ /**
85
+ * Remove prefix from key
86
+ */
87
+ private _getDeprefixedKey;
88
+ /**
89
+ * Get or create session for the store
90
+ */
91
+ private _getSession;
92
+ /**
93
+ * Create record content for storage
94
+ */
95
+ private _createRecordContent;
96
+ /**
97
+ * Parse record content from storage
98
+ */
99
+ private _parseRecordContent;
100
+ /**
101
+ * Gets multiple keys from the TDAI store.
102
+ * @param keys Array of keys to be retrieved.
103
+ * @returns An array of retrieved values.
104
+ */
105
+ mget(keys: string[]): Promise<(Uint8Array | undefined)[]>;
106
+ /**
107
+ * Sets multiple keys in the TDAI store.
108
+ * @param keyValuePairs Array of key-value pairs to be set.
109
+ * @returns Promise that resolves when all keys have been set.
110
+ */
111
+ mset(keyValuePairs: [string, Uint8Array][]): Promise<void>;
112
+ /**
113
+ * Deletes multiple keys from the TDAI store.
114
+ * @param keys Array of keys to be deleted.
115
+ * @returns Promise that resolves when all keys have been deleted.
116
+ */
117
+ mdelete(keys: string[]): Promise<void>;
118
+ /**
119
+ * Yields keys from the TDAI store.
120
+ * @param prefix Optional prefix to filter the keys.
121
+ * @returns An AsyncGenerator that yields keys from the TDAI store.
122
+ */
123
+ yieldKeys(prefix?: string): AsyncGenerator<string>;
124
+ /**
125
+ * Close the TDAI client connection
126
+ */
127
+ close(): void;
128
+ }
129
+
130
+ /**
131
+ * Convert AG-Kit BaseTool to LangChain DynamicStructuredTool
132
+ *
133
+ * @param agkitTool - AG-Kit BaseTool instance
134
+ * @param implFunc - Optional custom implementation function
135
+ * @returns LangChain DynamicStructuredTool instance
136
+ */
137
+ declare function convert2LangChain(agkitTool: BaseTool, implFunc?: (tool: BaseTool) => Function): langchain.DynamicTool<any>;
138
+ /**
139
+ * Convert LangChain Tool to AG-Kit DynamicTool
140
+ *
141
+ * @param langchainTool - LangChain tool instance (DynamicStructuredTool or StructuredTool)
142
+ * @returns AG-Kit DynamicTool instance
143
+ */
144
+ declare function convertLangChain2AGKit(langchainTool: StructuredTool): _cloudbase_agent_tools.DynamicTool<any, Record<string, unknown>, any>;
145
+
146
+ declare class LangchainAgent extends LanggraphAgent {
147
+ constructor(config: AgentConfig & {
148
+ agent: ReturnType<typeof createAgent>;
149
+ });
150
+ }
151
+ declare function agKitClientTools(): langchain.AgentMiddleware<z.ZodObject<{
152
+ agKit: z.ZodObject<{
153
+ actions: z.ZodArray<z.ZodObject<{
154
+ name: z.ZodString;
155
+ description: z.ZodString;
156
+ schema: z.ZodAny;
157
+ }, "strip", z.ZodTypeAny, {
158
+ name: string;
159
+ description: string;
160
+ schema?: any;
161
+ }, {
162
+ name: string;
163
+ description: string;
164
+ schema?: any;
165
+ }>, "many">;
166
+ }, "strip", z.ZodTypeAny, {
167
+ actions: {
168
+ name: string;
169
+ description: string;
170
+ schema?: any;
171
+ }[];
172
+ }, {
173
+ actions: {
174
+ name: string;
175
+ description: string;
176
+ schema?: any;
177
+ }[];
178
+ }>;
179
+ }, "strip", z.ZodTypeAny, {
180
+ agKit: {
181
+ actions: {
182
+ name: string;
183
+ description: string;
184
+ schema?: any;
185
+ }[];
186
+ };
187
+ }, {
188
+ agKit: {
189
+ actions: {
190
+ name: string;
191
+ description: string;
192
+ schema?: any;
193
+ }[];
194
+ };
195
+ }>, undefined, any>;
196
+
197
+ declare class TDAIChatHistory extends BaseListChatMessageHistory {
198
+ lc_namespace: string[];
199
+ client: MemoryClient;
200
+ private sessionId;
201
+ constructor(options: IMemoryClientOptions & {
202
+ sessionId: string;
203
+ });
204
+ getMessages(): Promise<BaseMessage[]>;
205
+ /**
206
+ * Method to add a new message to the Firestore collection. The message is
207
+ * passed as a BaseMessage object.
208
+ * @param message The message to be added as a BaseMessage object.
209
+ */
210
+ addMessage(message: BaseMessage): Promise<void>;
211
+ private appendMessage;
212
+ /**
213
+ * Method to delete all messages from the Firestore collection associated
214
+ * with the current session.
215
+ */
216
+ clear(): Promise<void>;
217
+ }
218
+
219
+ export { LangchainAgent, TDAIChatHistory, TDAIStore, type TDAIStoreInput, agKitClientTools, convert2LangChain, convertLangChain2AGKit };
@@ -0,0 +1,219 @@
1
+ import { MemoryClient, IMemoryClientOptions } from '@cloudbase/agent-agents';
2
+ import { BaseStore } from '@langchain/core/stores';
3
+ import * as _cloudbase_agent_tools from '@cloudbase/agent-tools';
4
+ import { BaseTool } from '@cloudbase/agent-tools';
5
+ import * as langchain from 'langchain';
6
+ import { createAgent } from 'langchain';
7
+ import { StructuredTool } from '@langchain/core/tools';
8
+ import { z } from 'zod/v3';
9
+ import { AgentConfig } from '@cloudbase/agent-agents/abstract';
10
+ import { LanggraphAgent } from '@cloudbase/agent-adapter-langgraph';
11
+ import { BaseListChatMessageHistory } from '@langchain/core/chat_history';
12
+ import { BaseMessage } from '@langchain/core/messages';
13
+
14
+ /**
15
+ * Configuration options for TDAIStore
16
+ */
17
+ interface TDAIStoreInput {
18
+ /**
19
+ * The TDAI Memory Client instance
20
+ */
21
+ client: MemoryClient;
22
+ /**
23
+ * The amount of keys to retrieve per batch when yielding keys.
24
+ * @default 1000
25
+ */
26
+ yieldKeysScanBatchSize?: number;
27
+ /**
28
+ * The namespace to use for the keys in the database.
29
+ */
30
+ namespace?: string;
31
+ /**
32
+ * Default session ID for storing records
33
+ */
34
+ defaultSessionId?: string;
35
+ /**
36
+ * Default strategy for storing records
37
+ */
38
+ defaultStrategy?: string;
39
+ /**
40
+ * TTL for records in seconds
41
+ */
42
+ ttlSeconds?: number;
43
+ }
44
+ /**
45
+ * TDAI implementation of the BaseStore for key-value caching.
46
+ * Uses TDAI Memory Client for persistent storage.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const client = new MemoryClient({
51
+ * endpoint: "https://memory.tdai.tencentyun.com",
52
+ * apiKey: "your-api-key",
53
+ * memoryId: "your-memory-id",
54
+ * });
55
+ *
56
+ * const store = new TDAIStore({
57
+ * client,
58
+ * namespace: "cache",
59
+ * });
60
+ *
61
+ * const encoder = new TextEncoder();
62
+ * await store.mset([
63
+ * ["key1", encoder.encode("value1")],
64
+ * ["key2", encoder.encode("value2")],
65
+ * ]);
66
+ *
67
+ * const values = await store.mget(["key1", "key2"]);
68
+ * ```
69
+ */
70
+ declare class TDAIStore extends BaseStore<string, Uint8Array> {
71
+ lc_namespace: string[];
72
+ protected client: MemoryClient;
73
+ protected namespace?: string;
74
+ protected yieldKeysScanBatchSize: number;
75
+ protected defaultSessionId: string;
76
+ protected defaultStrategy: string;
77
+ protected ttlSeconds?: number;
78
+ private sessionCache?;
79
+ constructor(fields: TDAIStoreInput);
80
+ /**
81
+ * Get prefixed key with namespace
82
+ */
83
+ private _getPrefixedKey;
84
+ /**
85
+ * Remove prefix from key
86
+ */
87
+ private _getDeprefixedKey;
88
+ /**
89
+ * Get or create session for the store
90
+ */
91
+ private _getSession;
92
+ /**
93
+ * Create record content for storage
94
+ */
95
+ private _createRecordContent;
96
+ /**
97
+ * Parse record content from storage
98
+ */
99
+ private _parseRecordContent;
100
+ /**
101
+ * Gets multiple keys from the TDAI store.
102
+ * @param keys Array of keys to be retrieved.
103
+ * @returns An array of retrieved values.
104
+ */
105
+ mget(keys: string[]): Promise<(Uint8Array | undefined)[]>;
106
+ /**
107
+ * Sets multiple keys in the TDAI store.
108
+ * @param keyValuePairs Array of key-value pairs to be set.
109
+ * @returns Promise that resolves when all keys have been set.
110
+ */
111
+ mset(keyValuePairs: [string, Uint8Array][]): Promise<void>;
112
+ /**
113
+ * Deletes multiple keys from the TDAI store.
114
+ * @param keys Array of keys to be deleted.
115
+ * @returns Promise that resolves when all keys have been deleted.
116
+ */
117
+ mdelete(keys: string[]): Promise<void>;
118
+ /**
119
+ * Yields keys from the TDAI store.
120
+ * @param prefix Optional prefix to filter the keys.
121
+ * @returns An AsyncGenerator that yields keys from the TDAI store.
122
+ */
123
+ yieldKeys(prefix?: string): AsyncGenerator<string>;
124
+ /**
125
+ * Close the TDAI client connection
126
+ */
127
+ close(): void;
128
+ }
129
+
130
+ /**
131
+ * Convert AG-Kit BaseTool to LangChain DynamicStructuredTool
132
+ *
133
+ * @param agkitTool - AG-Kit BaseTool instance
134
+ * @param implFunc - Optional custom implementation function
135
+ * @returns LangChain DynamicStructuredTool instance
136
+ */
137
+ declare function convert2LangChain(agkitTool: BaseTool, implFunc?: (tool: BaseTool) => Function): langchain.DynamicTool<any>;
138
+ /**
139
+ * Convert LangChain Tool to AG-Kit DynamicTool
140
+ *
141
+ * @param langchainTool - LangChain tool instance (DynamicStructuredTool or StructuredTool)
142
+ * @returns AG-Kit DynamicTool instance
143
+ */
144
+ declare function convertLangChain2AGKit(langchainTool: StructuredTool): _cloudbase_agent_tools.DynamicTool<any, Record<string, unknown>, any>;
145
+
146
+ declare class LangchainAgent extends LanggraphAgent {
147
+ constructor(config: AgentConfig & {
148
+ agent: ReturnType<typeof createAgent>;
149
+ });
150
+ }
151
+ declare function agKitClientTools(): langchain.AgentMiddleware<z.ZodObject<{
152
+ agKit: z.ZodObject<{
153
+ actions: z.ZodArray<z.ZodObject<{
154
+ name: z.ZodString;
155
+ description: z.ZodString;
156
+ schema: z.ZodAny;
157
+ }, "strip", z.ZodTypeAny, {
158
+ name: string;
159
+ description: string;
160
+ schema?: any;
161
+ }, {
162
+ name: string;
163
+ description: string;
164
+ schema?: any;
165
+ }>, "many">;
166
+ }, "strip", z.ZodTypeAny, {
167
+ actions: {
168
+ name: string;
169
+ description: string;
170
+ schema?: any;
171
+ }[];
172
+ }, {
173
+ actions: {
174
+ name: string;
175
+ description: string;
176
+ schema?: any;
177
+ }[];
178
+ }>;
179
+ }, "strip", z.ZodTypeAny, {
180
+ agKit: {
181
+ actions: {
182
+ name: string;
183
+ description: string;
184
+ schema?: any;
185
+ }[];
186
+ };
187
+ }, {
188
+ agKit: {
189
+ actions: {
190
+ name: string;
191
+ description: string;
192
+ schema?: any;
193
+ }[];
194
+ };
195
+ }>, undefined, any>;
196
+
197
+ declare class TDAIChatHistory extends BaseListChatMessageHistory {
198
+ lc_namespace: string[];
199
+ client: MemoryClient;
200
+ private sessionId;
201
+ constructor(options: IMemoryClientOptions & {
202
+ sessionId: string;
203
+ });
204
+ getMessages(): Promise<BaseMessage[]>;
205
+ /**
206
+ * Method to add a new message to the Firestore collection. The message is
207
+ * passed as a BaseMessage object.
208
+ * @param message The message to be added as a BaseMessage object.
209
+ */
210
+ addMessage(message: BaseMessage): Promise<void>;
211
+ private appendMessage;
212
+ /**
213
+ * Method to delete all messages from the Firestore collection associated
214
+ * with the current session.
215
+ */
216
+ clear(): Promise<void>;
217
+ }
218
+
219
+ export { LangchainAgent, TDAIChatHistory, TDAIStore, type TDAIStoreInput, agKitClientTools, convert2LangChain, convertLangChain2AGKit };