@cloudbase/agent-adapter-langgraph 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,37 @@
1
+ # @cloudbase/agent-adapter-langgraph
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-agents@0.0.10
14
+
15
+ ## 0.0.10-alpha.1
16
+
17
+ ### Patch Changes
18
+
19
+ - alpha release 0.0.9-alpha.3
20
+ - Update all public packages to version 0.0.9-alpha.3
21
+ - Trigger automated alpha release workflow
22
+ - Includes latest features and improvements
23
+
24
+ - Updated dependencies
25
+ - @cloudbase/agent-agents@0.0.10-alpha.1
26
+
27
+ ## 0.0.10-alpha.0
28
+
29
+ ### Patch Changes
30
+
31
+ - alpha release 0.0.9-alpha.3
32
+ - Update all public packages to version 0.0.9-alpha.3
33
+ - Trigger automated alpha release workflow
34
+ - Includes latest features and improvements
35
+
36
+ - Updated dependencies
37
+ - @cloudbase/agent-agents@0.0.10-alpha.0
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # @cloudbase/agent-adapter-langgraph
2
+
3
+ LangGraph adapter for AG-Kit agents. This package provides integration between AG-Kit and LangGraph framework, enabling you to use LangGraph workflows with AG-Kit's agent infrastructure.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cloudbase/agent-agents @cloudbase/agent-adapter-langgraph
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **LangGraphAgent**: Agent implementation that works with compiled LangGraph workflows
14
+ - **TDAISaver**: Checkpoint saver implementation using TDAI Memory
15
+ - **TDAIStore**: Store implementation for LangGraph using TDAI Memory
16
+ - **AGKitStateAnnotation**: Pre-configured state annotation for AG-Kit integration
17
+
18
+ ## Usage
19
+
20
+ ### Basic Agent Setup
21
+
22
+ ```typescript
23
+ import { StateGraph, START, END } from "@langchain/langgraph";
24
+ import { AGKitStateAnnotation, LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
25
+ import { AgentConfig } from "@cloudbase/agent-agents/abstract";
26
+
27
+ // Create your LangGraph workflow
28
+ const workflow = new StateGraph(AGKitStateAnnotation)
29
+ .addNode("chat_node", chatNode)
30
+ .addEdge(START, "chat_node")
31
+ .addEdge("chat_node", END);
32
+
33
+ const compiledWorkflow = workflow.compile();
34
+
35
+ // Create the agent
36
+ const agent = new LanggraphAgent({
37
+ name: "my-langgraph-agent",
38
+ description: "A LangGraph agent",
39
+ compiledWorkflow,
40
+ });
41
+ ```
42
+
43
+ ### Using TDAISaver for Checkpoints
44
+
45
+ ```typescript
46
+ import { TDAISaver } from "@cloudbase/agent-adapter-langgraph";
47
+ import { MemoryClient } from "@cloudbase/agent-agents";
48
+
49
+ const memoryClient = new MemoryClient({
50
+ endpoint: "https://api.tdai.com",
51
+ apiKey: "your-api-key",
52
+ memoryId: "your-memory-id",
53
+ });
54
+
55
+ const checkpointer = new TDAISaver({
56
+ endpoint: "https://api.tdai.com",
57
+ apiKey: "your-api-key",
58
+ memoryId: "your-memory-id",
59
+ });
60
+
61
+ const compiledWorkflow = workflow.compile({
62
+ checkpointer,
63
+ });
64
+ ```
65
+
66
+ ### Using TDAIStore
67
+
68
+ ```typescript
69
+ import { TDAIStore } from "@cloudbase/agent-adapter-langgraph";
70
+ import { MemoryClient } from "@cloudbase/agent-agents";
71
+
72
+ const memoryClient = new MemoryClient({
73
+ endpoint: "https://api.tdai.com",
74
+ apiKey: "your-api-key",
75
+ memoryId: "your-memory-id",
76
+ });
77
+
78
+ const store = new TDAIStore({
79
+ memoryClient,
80
+ sessionId: "session-123",
81
+ });
82
+ ```
83
+
84
+ ## API Reference
85
+
86
+ ### LanggraphAgent
87
+
88
+ Agent class that extends `AbstractAgent` and works with compiled LangGraph workflows.
89
+
90
+ **Constructor:**
91
+ ```typescript
92
+ constructor(config: AgentConfig & { compiledWorkflow: CompiledStateGraph })
93
+ ```
94
+
95
+ ### TDAISaver
96
+
97
+ Checkpoint saver implementation for LangGraph using TDAI Memory.
98
+
99
+ **Constructor:**
100
+ ```typescript
101
+ constructor(config: TDAISaverConfig)
102
+ ```
103
+
104
+ ### TDAIStore
105
+
106
+ Store implementation for LangGraph using TDAI Memory.
107
+
108
+ **Constructor:**
109
+ ```typescript
110
+ constructor(config: TDAIStoreConfig)
111
+ ```
112
+
113
+ ## Requirements
114
+
115
+ - `@cloudbase/agent-agents`: Core agent functionality
116
+ - `@langchain/langgraph`: LangGraph framework
117
+ - `@langchain/core`: LangChain core utilities
118
+ - `rxjs`: Reactive extensions for JavaScript
119
+
120
+ ## Related Resources
121
+
122
+ - [AG-Kit Documentation](https://docs.agkit.dev)
123
+ - [LangGraph Documentation](https://langchain-ai.github.io/langgraph/)
124
+ - [AG-Kit Examples](https://github.com/agkit/agkit/tree/main/typescript-sdk/packages/examples)
125
+
@@ -0,0 +1,289 @@
1
+ import * as _langchain_core_messages from '@langchain/core/messages';
2
+ import * as _langchain_langgraph from '@langchain/langgraph';
3
+ import { AnnotationRoot, StateDefinition, StateGraph, BaseCheckpointSaver, CheckpointTuple, Checkpoint, CheckpointMetadata, BaseStore, Item, Operation, OperationResults } from '@langchain/langgraph';
4
+ import { RunAgentInput, EventType, BaseEvent } from '@ag-ui/client';
5
+ import { AbstractAgent, AgentConfig } from '@cloudbase/agent-agents/abstract';
6
+ import { Observable, Subscriber } from 'rxjs';
7
+ import { InteropZodObject } from '@langchain/core/utils/types';
8
+ import { RunnableConfig } from '@langchain/core/runnables';
9
+ import { IMemoryClientOptions, MemoryClient } from '@cloudbase/agent-agents';
10
+
11
+ type SDZod = StateDefinition | InteropZodObject;
12
+ type CompiledStateGraph<SD extends SDZod> = ReturnType<StateGraph<SD>["compile"]>;
13
+ type AnnotationInside<T> = T extends AnnotationRoot<infer U> ? U : never;
14
+ type AGKitStateDefinition = AnnotationInside<typeof AGKitStateAnnotation>;
15
+ declare const AGKitPropertiesAnnotation: AnnotationRoot<{
16
+ actions: {
17
+ (): _langchain_langgraph.LastValue<any[]>;
18
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
19
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
20
+ };
21
+ }>;
22
+ declare const AGKitStateAnnotation: AnnotationRoot<{
23
+ messages: _langchain_langgraph.BinaryOperatorAggregate<_langchain_core_messages.BaseMessage<_langchain_core_messages.MessageStructure, _langchain_core_messages.MessageType>[], _langchain_langgraph.Messages>;
24
+ agKit: {
25
+ (): _langchain_langgraph.LastValue<_langchain_langgraph.StateType<{
26
+ actions: {
27
+ (): _langchain_langgraph.LastValue<any[]>;
28
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
29
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
30
+ };
31
+ }>>;
32
+ (annotation: _langchain_langgraph.SingleReducer<_langchain_langgraph.StateType<{
33
+ actions: {
34
+ (): _langchain_langgraph.LastValue<any[]>;
35
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
36
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
37
+ };
38
+ }>, _langchain_langgraph.StateType<{
39
+ actions: {
40
+ (): _langchain_langgraph.LastValue<any[]>;
41
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
42
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
43
+ };
44
+ }>>): _langchain_langgraph.BinaryOperatorAggregate<_langchain_langgraph.StateType<{
45
+ actions: {
46
+ (): _langchain_langgraph.LastValue<any[]>;
47
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
48
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
49
+ };
50
+ }>, _langchain_langgraph.StateType<{
51
+ actions: {
52
+ (): _langchain_langgraph.LastValue<any[]>;
53
+ (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
54
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
55
+ };
56
+ }>>;
57
+ Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
58
+ };
59
+ }>;
60
+ type AGKitState = typeof AGKitStateAnnotation.State;
61
+ declare class LanggraphAgent extends AbstractAgent {
62
+ compiledWorkflow?: CompiledStateGraph<AGKitStateDefinition>;
63
+ constructor(agentConfig: AgentConfig & {
64
+ compiledWorkflow: any;
65
+ });
66
+ run(input: RunAgentInput): Observable<{
67
+ type: EventType;
68
+ timestamp?: number | undefined;
69
+ rawEvent?: any;
70
+ }>;
71
+ _run(subscriber: Subscriber<BaseEvent>, input: RunAgentInput): Promise<void>;
72
+ clone(): any;
73
+ }
74
+
75
+ type PendingWrite = [string, any];
76
+ interface CheckpointListOptions {
77
+ limit?: number;
78
+ before?: RunnableConfig;
79
+ filter?: Record<string, any>;
80
+ }
81
+ interface TDAISaverConfig extends IMemoryClientOptions {
82
+ checkpointType?: string;
83
+ checkpointWritesType?: string;
84
+ }
85
+ /**
86
+ * TDAISaver - LangGraph checkpoint saver implementation using TDAI Memory
87
+ *
88
+ * Storage Strategy:
89
+ * - Events (NoSQL): Store checkpoint data and pending writes in separate collections
90
+ * - Supports namespaces and parent checkpoint relationships
91
+ */
92
+ declare class TDAISaver extends BaseCheckpointSaver {
93
+ private memoryClient;
94
+ private checkpointType;
95
+ private checkpointWritesType;
96
+ constructor(config: TDAISaverConfig);
97
+ /**
98
+ * Retrieves a checkpoint from TDAI Memory based on the provided config.
99
+ * If the config contains a "checkpoint_id" key, the checkpoint with the matching
100
+ * thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
101
+ * for the given thread ID is retrieved.
102
+ */
103
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
104
+ /**
105
+ * Retrieve a list of checkpoint tuples from TDAI Memory based on the provided config.
106
+ * The checkpoints are ordered by checkpoint ID in descending order (newest first).
107
+ */
108
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
109
+ /**
110
+ * Saves a checkpoint to TDAI Memory. The checkpoint is associated with the
111
+ * provided config and its parent config (if any).
112
+ */
113
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
114
+ /**
115
+ * Saves intermediate writes associated with a checkpoint to TDAI Memory.
116
+ */
117
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
118
+ /**
119
+ * Delete all checkpoints and writes for a thread from TDAI Memory.
120
+ */
121
+ deleteThread(threadId: string): Promise<void>;
122
+ /**
123
+ * Close the memory client connection
124
+ */
125
+ close(): void;
126
+ }
127
+
128
+ /**
129
+ * TDAI Store configuration
130
+ */
131
+ interface TDAIStoreConfig {
132
+ /**
133
+ * TDAI Memory Client instance for long-term storage
134
+ */
135
+ memoryClient: MemoryClient;
136
+ /**
137
+ * Session ID for storing records
138
+ */
139
+ sessionId: string;
140
+ /**
141
+ * Optional namespace prefix for all operations
142
+ */
143
+ namespacePrefix?: string[];
144
+ /**
145
+ * TTL configuration for records
146
+ */
147
+ ttl?: {
148
+ defaultTtlSeconds?: number;
149
+ sweepIntervalMinutes?: number;
150
+ };
151
+ /**
152
+ * Whether to ensure tables/collections exist on startup
153
+ */
154
+ ensureTables?: boolean;
155
+ /**
156
+ * Default strategy for storing records
157
+ */
158
+ defaultStrategy?: string;
159
+ }
160
+ /**
161
+ * Filter operators for advanced filtering
162
+ */
163
+ interface FilterOperators {
164
+ $eq?: unknown;
165
+ $ne?: unknown;
166
+ $gt?: number | Date;
167
+ $gte?: number | Date;
168
+ $lt?: number | Date;
169
+ $lte?: number | Date;
170
+ $in?: unknown[];
171
+ $nin?: unknown[];
172
+ $exists?: boolean;
173
+ $regex?: string;
174
+ }
175
+ /**
176
+ * TDAI implementation of the BaseStore interface.
177
+ * Uses TDAI Memory Client for long-term record storage.
178
+ */
179
+ declare class TDAIStore extends BaseStore {
180
+ private client;
181
+ private namespacePrefix;
182
+ private ttlConfig?;
183
+ private ensureTables;
184
+ private isSetup;
185
+ private isClosed;
186
+ private sweepInterval?;
187
+ private sessionId;
188
+ private defaultStrategy;
189
+ constructor(config: TDAIStoreConfig);
190
+ /**
191
+ * Create a storage key from namespace and key
192
+ */
193
+ private createStorageKey;
194
+ /**
195
+ * Parse a storage key back to namespace and key
196
+ */
197
+ private parseStorageKey;
198
+ /**
199
+ * Put an item with optional TTL.
200
+ */
201
+ put(namespace: string[], key: string, value: Record<string, unknown>, index?: false | string[], options?: {
202
+ ttl?: number;
203
+ }): Promise<void>;
204
+ /**
205
+ * Get an item by namespace and key.
206
+ */
207
+ get(namespace: string[], key: string): Promise<Item | null>;
208
+ /**
209
+ * Delete an item by namespace and key.
210
+ */
211
+ delete(namespace: string[], key: string): Promise<void>;
212
+ /**
213
+ * List namespaces with optional filtering.
214
+ */
215
+ listNamespaces(options?: {
216
+ prefix?: string[];
217
+ suffix?: string[];
218
+ maxDepth?: number;
219
+ limit?: number;
220
+ offset?: number;
221
+ }): Promise<string[][]>;
222
+ /**
223
+ * Execute multiple operations in a single batch.
224
+ */
225
+ batch<Op extends Operation[]>(operations: Op): Promise<OperationResults<Op>>;
226
+ /**
227
+ * Execute search operation
228
+ */
229
+ private executeSearch;
230
+ /**
231
+ * Execute list namespaces operation
232
+ */
233
+ private executeListNamespaces;
234
+ /**
235
+ * Initialize the store.
236
+ */
237
+ setup(): Promise<void>;
238
+ /**
239
+ * Start the store.
240
+ */
241
+ start(): Promise<void>;
242
+ /**
243
+ * Stop the store and close all connections.
244
+ */
245
+ stop(): Promise<void>;
246
+ /**
247
+ * Manually sweep expired items from the store.
248
+ */
249
+ sweepExpiredItems(): Promise<number>;
250
+ /**
251
+ * Get statistics about the store.
252
+ */
253
+ getStats(): Promise<{
254
+ totalItems: number;
255
+ expiredItems: number;
256
+ namespaceCount: number;
257
+ oldestItem: Date | null;
258
+ newestItem: Date | null;
259
+ }>;
260
+ /**
261
+ * Search for items in the store with support for text search and filtering.
262
+ */
263
+ search(namespacePrefix: string[], options?: {
264
+ /**
265
+ * Filter conditions with support for advanced operators.
266
+ */
267
+ filter?: Record<string, string | number | boolean | null | FilterOperators>;
268
+ /**
269
+ * Natural language search query.
270
+ */
271
+ query?: string;
272
+ /**
273
+ * Maximum number of results to return.
274
+ * @default 10
275
+ */
276
+ limit?: number;
277
+ /**
278
+ * Number of results to skip for pagination.
279
+ * @default 0
280
+ */
281
+ offset?: number;
282
+ /**
283
+ * Whether to refresh TTL for returned items.
284
+ */
285
+ refreshTtl?: boolean;
286
+ }): Promise<Item[]>;
287
+ }
288
+
289
+ export { AGKitPropertiesAnnotation, type AGKitState, AGKitStateAnnotation, LanggraphAgent, TDAISaver, type TDAISaverConfig, TDAIStore, type TDAIStoreConfig };