@cloudbase/agent-adapter-langgraph 0.0.13 → 1.0.1-alpha.7
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/README.md +74 -85
- package/dist/index.d.mts +1 -9
- package/dist/index.d.ts +1 -9
- package/dist/index.js +38 -230
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -227
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,136 +1,125 @@
|
|
|
1
1
|
# @cloudbase/agent-adapter-langgraph
|
|
2
2
|
|
|
3
|
-
|
|
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
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @cloudbase/agent-adapter-langgraph
|
|
8
|
+
npm install @cloudbase/agent-agents @cloudbase/agent-adapter-langgraph
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Features
|
|
12
12
|
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
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
|
|
15
17
|
|
|
16
|
-
##
|
|
18
|
+
## Usage
|
|
17
19
|
|
|
18
|
-
###
|
|
20
|
+
### Basic Agent Setup
|
|
19
21
|
|
|
20
22
|
```typescript
|
|
21
|
-
import { run } from "@cloudbase/agent-server";
|
|
22
23
|
import { StateGraph, START, END } from "@langchain/langgraph";
|
|
23
|
-
import {
|
|
24
|
+
import { AGKitStateAnnotation, LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
|
|
25
|
+
import { AgentConfig } from "@cloudbase/agent-agents/abstract";
|
|
24
26
|
|
|
25
|
-
//
|
|
26
|
-
const workflow = new StateGraph(
|
|
27
|
+
// Create your LangGraph workflow
|
|
28
|
+
const workflow = new StateGraph(AGKitStateAnnotation)
|
|
27
29
|
.addNode("chat_node", chatNode)
|
|
28
30
|
.addEdge(START, "chat_node")
|
|
29
31
|
.addEdge("chat_node", END);
|
|
30
32
|
|
|
31
33
|
const compiledWorkflow = workflow.compile();
|
|
32
34
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
port: 9000,
|
|
35
|
+
// Create the agent
|
|
36
|
+
const agent = new LanggraphAgent({
|
|
37
|
+
name: "my-langgraph-agent",
|
|
38
|
+
description: "A LangGraph agent",
|
|
39
|
+
compiledWorkflow,
|
|
39
40
|
});
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
### Using TDAISaver for Checkpoints
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
```typescript
|
|
46
|
+
import { TDAISaver } from "@cloudbase/agent-adapter-langgraph";
|
|
47
|
+
import { MemoryClient } from "@cloudbase/agent-agents";
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
const memoryClient = new MemoryClient({
|
|
50
|
+
endpoint: "https://api.tdai.com",
|
|
51
|
+
apiKey: "your-api-key",
|
|
52
|
+
memoryId: "your-memory-id",
|
|
53
|
+
});
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
55
|
+
const checkpointer = new TDAISaver({
|
|
56
|
+
endpoint: "https://api.tdai.com",
|
|
57
|
+
apiKey: "your-api-key",
|
|
58
|
+
memoryId: "your-memory-id",
|
|
59
|
+
});
|
|
53
60
|
|
|
54
|
-
const
|
|
61
|
+
const compiledWorkflow = workflow.compile({
|
|
62
|
+
checkpointer,
|
|
63
|
+
});
|
|
55
64
|
```
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
- `Logger`:日志接口,详见 [@cloudbase/agent-server 文档](https://www.npmjs.com/package/@cloudbase/agent-server)
|
|
66
|
+
### Using TDAIStore
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
```typescript
|
|
69
|
+
import { TDAIStore } from "@cloudbase/agent-adapter-langgraph";
|
|
70
|
+
import { MemoryClient } from "@cloudbase/agent-agents";
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
const memoryClient = new MemoryClient({
|
|
73
|
+
endpoint: "https://api.tdai.com",
|
|
74
|
+
apiKey: "your-api-key",
|
|
75
|
+
memoryId: "your-memory-id",
|
|
76
|
+
});
|
|
66
77
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
const store = new TDAIStore({
|
|
79
|
+
memoryClient,
|
|
80
|
+
sessionId: "session-123",
|
|
81
|
+
});
|
|
71
82
|
```
|
|
72
83
|
|
|
73
|
-
##
|
|
74
|
-
|
|
75
|
-
AG-UI 支持**客户端工具**(Client Tools):客户端定义工具,Agent 调用后由客户端执行并返回结果。
|
|
84
|
+
## API Reference
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
- 需要访问客户端 API(如获取地理位置、访问剪贴板)
|
|
79
|
-
- 需要用户确认的操作(如发送邮件前确认)
|
|
80
|
-
- 需要展示 UI 交互(如让用户选择文件)
|
|
86
|
+
### LanggraphAgent
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
Agent class that extends `AbstractAgent` and works with compiled LangGraph workflows.
|
|
83
89
|
|
|
90
|
+
**Constructor:**
|
|
84
91
|
```typescript
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
async function chatNode(state: ClientState) {
|
|
88
|
-
const model = new ChatOpenAI({ model: "gpt-4o" });
|
|
89
|
-
|
|
90
|
-
// 合并服务端工具和客户端工具
|
|
91
|
-
const modelWithTools = model.bindTools([
|
|
92
|
-
...serverTools, // 服务端定义的工具
|
|
93
|
-
...(state.client?.tools || []) // 客户端传来的工具
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
const response = await modelWithTools.invoke([...state.messages]);
|
|
97
|
-
return { messages: [response] };
|
|
98
|
-
}
|
|
92
|
+
constructor(config: AgentConfig & { compiledWorkflow: CompiledStateGraph })
|
|
99
93
|
```
|
|
100
94
|
|
|
101
|
-
###
|
|
95
|
+
### TDAISaver
|
|
102
96
|
|
|
103
|
-
|
|
97
|
+
Checkpoint saver implementation for LangGraph using TDAI Memory.
|
|
104
98
|
|
|
99
|
+
**Constructor:**
|
|
105
100
|
```typescript
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
function shouldContinue(state: ClientState): "tools" | "end" {
|
|
109
|
-
const lastMessage = state.messages.at(-1) as AIMessage;
|
|
101
|
+
constructor(config: TDAISaverConfig)
|
|
102
|
+
```
|
|
110
103
|
|
|
111
|
-
|
|
112
|
-
// 如果是服务端工具,继续执行
|
|
113
|
-
const hasServerTool = lastMessage.tool_calls.some(
|
|
114
|
-
tc => serverToolNames.has(tc.name)
|
|
115
|
-
);
|
|
116
|
-
if (hasServerTool) return "tools";
|
|
117
|
-
}
|
|
104
|
+
### TDAIStore
|
|
118
105
|
|
|
119
|
-
|
|
120
|
-
return "end";
|
|
121
|
-
}
|
|
122
|
-
```
|
|
106
|
+
Store implementation for LangGraph using TDAI Memory.
|
|
123
107
|
|
|
124
|
-
|
|
108
|
+
**Constructor:**
|
|
109
|
+
```typescript
|
|
110
|
+
constructor(config: TDAIStoreConfig)
|
|
111
|
+
```
|
|
125
112
|
|
|
126
|
-
|
|
127
|
-
- `@langchain/core`:LangChain 核心工具
|
|
113
|
+
## Requirements
|
|
128
114
|
|
|
129
|
-
|
|
115
|
+
- `@cloudbase/agent-agents`: Core agent functionality
|
|
116
|
+
- `@langchain/langgraph`: LangGraph framework
|
|
117
|
+
- `@langchain/core`: LangChain core utilities
|
|
118
|
+
- `rxjs`: Reactive extensions for JavaScript
|
|
130
119
|
|
|
131
|
-
|
|
120
|
+
## Related Resources
|
|
132
121
|
|
|
133
|
-
|
|
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)
|
|
134
125
|
|
|
135
|
-
- [AG-UI 协议](https://docs.ag-ui.com)
|
|
136
|
-
- [LangGraph 文档](https://langchain-ai.github.io/langgraph/)
|
package/dist/index.d.mts
CHANGED
|
@@ -4,8 +4,6 @@ import { AnnotationRoot, StateDefinition, StateGraph, BaseCheckpointSaver, Check
|
|
|
4
4
|
import { AbstractAgent, AgentConfig, RunAgentInput, EventType, BaseEvent } from '@ag-ui/client';
|
|
5
5
|
import { Observable, Subscriber } from 'rxjs';
|
|
6
6
|
import { InteropZodObject } from '@langchain/core/utils/types';
|
|
7
|
-
import { Logger } from '@cloudbase/agent-shared';
|
|
8
|
-
export { Logger, createConsoleLogger, noopLogger } from '@cloudbase/agent-shared';
|
|
9
7
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
10
8
|
import { IMemoryClientOptions, MemoryClient } from '@cloudbase/agent-agents';
|
|
11
9
|
|
|
@@ -61,14 +59,8 @@ declare const ClientStateAnnotation: AnnotationRoot<{
|
|
|
61
59
|
type ClientState = typeof ClientStateAnnotation.State;
|
|
62
60
|
declare class LanggraphAgent extends AbstractAgent {
|
|
63
61
|
compiledWorkflow?: CompiledStateGraph<ClientStateDefinition>;
|
|
64
|
-
private logger;
|
|
65
62
|
constructor(agentConfig: AgentConfig & {
|
|
66
63
|
compiledWorkflow: any;
|
|
67
|
-
/**
|
|
68
|
-
* Logger instance for structured logging.
|
|
69
|
-
* @default noopLogger (silent)
|
|
70
|
-
*/
|
|
71
|
-
logger?: Logger;
|
|
72
64
|
});
|
|
73
65
|
run(input: RunAgentInput): Observable<{
|
|
74
66
|
type: EventType;
|
|
@@ -76,7 +68,7 @@ declare class LanggraphAgent extends AbstractAgent {
|
|
|
76
68
|
rawEvent?: any;
|
|
77
69
|
}>;
|
|
78
70
|
_run(subscriber: Subscriber<BaseEvent>, input: RunAgentInput): Promise<void>;
|
|
79
|
-
clone():
|
|
71
|
+
clone(): any;
|
|
80
72
|
}
|
|
81
73
|
|
|
82
74
|
type PendingWrite = [string, any];
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { AnnotationRoot, StateDefinition, StateGraph, BaseCheckpointSaver, Check
|
|
|
4
4
|
import { AbstractAgent, AgentConfig, RunAgentInput, EventType, BaseEvent } from '@ag-ui/client';
|
|
5
5
|
import { Observable, Subscriber } from 'rxjs';
|
|
6
6
|
import { InteropZodObject } from '@langchain/core/utils/types';
|
|
7
|
-
import { Logger } from '@cloudbase/agent-shared';
|
|
8
|
-
export { Logger, createConsoleLogger, noopLogger } from '@cloudbase/agent-shared';
|
|
9
7
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
10
8
|
import { IMemoryClientOptions, MemoryClient } from '@cloudbase/agent-agents';
|
|
11
9
|
|
|
@@ -61,14 +59,8 @@ declare const ClientStateAnnotation: AnnotationRoot<{
|
|
|
61
59
|
type ClientState = typeof ClientStateAnnotation.State;
|
|
62
60
|
declare class LanggraphAgent extends AbstractAgent {
|
|
63
61
|
compiledWorkflow?: CompiledStateGraph<ClientStateDefinition>;
|
|
64
|
-
private logger;
|
|
65
62
|
constructor(agentConfig: AgentConfig & {
|
|
66
63
|
compiledWorkflow: any;
|
|
67
|
-
/**
|
|
68
|
-
* Logger instance for structured logging.
|
|
69
|
-
* @default noopLogger (silent)
|
|
70
|
-
*/
|
|
71
|
-
logger?: Logger;
|
|
72
64
|
});
|
|
73
65
|
run(input: RunAgentInput): Observable<{
|
|
74
66
|
type: EventType;
|
|
@@ -76,7 +68,7 @@ declare class LanggraphAgent extends AbstractAgent {
|
|
|
76
68
|
rawEvent?: any;
|
|
77
69
|
}>;
|
|
78
70
|
_run(subscriber: Subscriber<BaseEvent>, input: RunAgentInput): Promise<void>;
|
|
79
|
-
clone():
|
|
71
|
+
clone(): any;
|
|
80
72
|
}
|
|
81
73
|
|
|
82
74
|
type PendingWrite = [string, any];
|