@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 CHANGED
@@ -1,136 +1,125 @@
1
1
  # @cloudbase/agent-adapter-langgraph
2
2
 
3
- LangGraph 工作流转换为符合 [AG-UI 协议](https://docs.ag-ui.com) Agent。
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
- - **LanggraphAgent**:将编译后的 LangGraph 工作流包装为 AG-UI 兼容的 Agent
14
- - **ClientStateAnnotation**:工作流状态定义,包含 messages client tools
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
- ### 配合 @cloudbase/agent-server 使用
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 { ClientStateAnnotation, LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
24
+ import { AGKitStateAnnotation, LanggraphAgent } from "@cloudbase/agent-adapter-langgraph";
25
+ import { AgentConfig } from "@cloudbase/agent-agents/abstract";
24
26
 
25
- // 创建 LangGraph 工作流
26
- const workflow = new StateGraph(ClientStateAnnotation)
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
- // 部署为 HTTP 服务
34
- run({
35
- createAgent: () => ({
36
- agent: new LanggraphAgent({ compiledWorkflow }),
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
- ## API 参考
43
+ ### Using TDAISaver for Checkpoints
43
44
 
44
- ### LanggraphAgent
45
+ ```typescript
46
+ import { TDAISaver } from "@cloudbase/agent-adapter-langgraph";
47
+ import { MemoryClient } from "@cloudbase/agent-agents";
45
48
 
46
- 将编译后的 LangGraph 工作流转换为 AG-UI 兼容的 Agent。
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
- ```typescript
49
- type LanggraphAgentConfig = AgentConfig & {
50
- compiledWorkflow: CompiledStateGraph; // 编译后的 LangGraph 工作流
51
- logger?: Logger; // 可选,日志实例
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 agent = new LanggraphAgent(config);
61
+ const compiledWorkflow = workflow.compile({
62
+ checkpointer,
63
+ });
55
64
  ```
56
65
 
57
- - `AgentConfig`:来自 [AG-UI 协议](https://docs.ag-ui.com)
58
- - `Logger`:日志接口,详见 [@cloudbase/agent-server 文档](https://www.npmjs.com/package/@cloudbase/agent-server)
66
+ ### Using TDAIStore
59
67
 
60
- ### ClientStateAnnotation
61
-
62
- 创建 LangGraph 工作流时使用的状态定义,已包含 AG-UI 需要的字段:
68
+ ```typescript
69
+ import { TDAIStore } from "@cloudbase/agent-adapter-langgraph";
70
+ import { MemoryClient } from "@cloudbase/agent-agents";
63
71
 
64
- - `messages`:消息历史
65
- - `client.tools`:客户端传来的工具列表
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
- ```typescript
68
- const workflow = new StateGraph(ClientStateAnnotation)
69
- .addNode("chat_node", chatNode)
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
- ### chatNode 中使用客户端工具
88
+ Agent class that extends `AbstractAgent` and works with compiled LangGraph workflows.
83
89
 
90
+ **Constructor:**
84
91
  ```typescript
85
- import { ClientState } from "@cloudbase/agent-adapter-langgraph";
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
- Agent 调用工具时,需要判断是服务端执行还是交给客户端:
97
+ Checkpoint saver implementation for LangGraph using TDAI Memory.
104
98
 
99
+ **Constructor:**
105
100
  ```typescript
106
- const serverToolNames = new Set(serverTools.map(t => t.name));
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
- if (lastMessage.tool_calls?.length) {
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
- - `@langchain/langgraph`:LangGraph 框架
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
- 📚 完整文档请参阅 [云开发 Agent 开发指南](https://docs.cloudbase.net/ai/agent-development/)
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(): LanggraphAgent;
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(): LanggraphAgent;
71
+ clone(): any;
80
72
  }
81
73
 
82
74
  type PendingWrite = [string, any];