@mondaydotcomorg/atp-langchain 0.17.14
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 +434 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/langgraph-client.d.ts +156 -0
- package/dist/langgraph-client.d.ts.map +1 -0
- package/dist/langgraph-client.js +231 -0
- package/dist/langgraph-client.js.map +1 -0
- package/dist/langgraph-tools.d.ts +79 -0
- package/dist/langgraph-tools.d.ts.map +1 -0
- package/dist/langgraph-tools.js +149 -0
- package/dist/langgraph-tools.js.map +1 -0
- package/dist/node.d.ts +29 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +49 -0
- package/dist/node.js.map +1 -0
- package/dist/tools.d.ts +39 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +52 -0
- package/dist/tools.js.map +1 -0
- package/package.json +45 -0
- package/src/index.ts +11 -0
- package/src/langgraph-client.ts +369 -0
- package/src/langgraph-tools.ts +219 -0
- package/src/node.ts +60 -0
- package/src/tools.ts +72 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph-aware ATP Client
|
|
3
|
+
*
|
|
4
|
+
* This client integrates ATP execution with LangGraph's interrupt-based
|
|
5
|
+
* human-in-the-loop (HITL) system. When ATP code calls atp.approval.request(),
|
|
6
|
+
* it triggers a LangGraph interrupt for production-ready async approval flows.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - LangGraph interrupt integration for approvals
|
|
10
|
+
* - LLM sampling via LangChain models
|
|
11
|
+
* - Checkpoint-aware state management
|
|
12
|
+
* - Production-ready async approval workflows
|
|
13
|
+
*/
|
|
14
|
+
import { AgentToolProtocolClient, ClientCallbackError } from '@mondaydotcomorg/atp-client';
|
|
15
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
16
|
+
/**
|
|
17
|
+
* Exception thrown when approval is needed - this triggers LangGraph interrupt
|
|
18
|
+
*/
|
|
19
|
+
export class ApprovalRequiredException extends ClientCallbackError {
|
|
20
|
+
approvalRequest;
|
|
21
|
+
constructor(approvalRequest) {
|
|
22
|
+
super(`Approval required: ${approvalRequest.message}`);
|
|
23
|
+
this.approvalRequest = approvalRequest;
|
|
24
|
+
this.name = 'ApprovalRequiredException';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* LangGraph-aware ATP Client
|
|
29
|
+
*
|
|
30
|
+
* Integrates ATP with LangGraph's production-ready interrupt system:
|
|
31
|
+
* - atp.llm.call() → Routes to LangChain LLM (no interrupt)
|
|
32
|
+
* - atp.approval.request() → Throws ApprovalRequiredException (triggers LangGraph interrupt)
|
|
33
|
+
* - Supports checkpoint-based state persistence
|
|
34
|
+
* - Enables async approval workflows
|
|
35
|
+
*/
|
|
36
|
+
export class LangGraphATPClient {
|
|
37
|
+
client;
|
|
38
|
+
llm;
|
|
39
|
+
embeddings;
|
|
40
|
+
useLangGraphInterrupts;
|
|
41
|
+
directApprovalHandler;
|
|
42
|
+
pendingApprovals = new Map();
|
|
43
|
+
constructor(options) {
|
|
44
|
+
const { serverUrl, headers, llm, embeddings, tools, useLangGraphInterrupts = true, approvalHandler, hooks, } = options;
|
|
45
|
+
this.client = new AgentToolProtocolClient({
|
|
46
|
+
baseUrl: serverUrl,
|
|
47
|
+
headers,
|
|
48
|
+
hooks,
|
|
49
|
+
serviceProviders: tools ? { tools } : undefined,
|
|
50
|
+
});
|
|
51
|
+
this.llm = llm;
|
|
52
|
+
this.embeddings = embeddings;
|
|
53
|
+
this.useLangGraphInterrupts = useLangGraphInterrupts;
|
|
54
|
+
this.directApprovalHandler = approvalHandler;
|
|
55
|
+
this.client.provideLLM({
|
|
56
|
+
call: async (prompt, options) => {
|
|
57
|
+
return await this.handleLLMCall(prompt, options);
|
|
58
|
+
},
|
|
59
|
+
extract: async (prompt, schema, options) => {
|
|
60
|
+
return await this.handleLLMExtract(prompt, schema, options);
|
|
61
|
+
},
|
|
62
|
+
classify: async (text, categories, options) => {
|
|
63
|
+
return await this.handleLLMClassify(text, categories, options);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
if (this.embeddings) {
|
|
67
|
+
this.client.provideEmbedding({
|
|
68
|
+
embed: async (text) => {
|
|
69
|
+
return await this.handleEmbedding(text);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
this.client.provideApproval({
|
|
74
|
+
request: async (message, context) => {
|
|
75
|
+
return await this.handleApprovalRequest(message, context);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Initialize the client connection
|
|
81
|
+
*/
|
|
82
|
+
async connect() {
|
|
83
|
+
await this.client.init({ name: 'langgraph-atp-client', version: '1.0.0' });
|
|
84
|
+
await this.client.connect();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get TypeScript API definitions
|
|
88
|
+
*/
|
|
89
|
+
getTypeDefinitions() {
|
|
90
|
+
return this.client.getTypeDefinitions();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Execute ATP code with LangGraph interrupt support
|
|
94
|
+
*
|
|
95
|
+
* When approval is needed:
|
|
96
|
+
* - If useLangGraphInterrupts=true: Throws ApprovalRequiredException
|
|
97
|
+
* - If useLangGraphInterrupts=false: Uses direct approval handler
|
|
98
|
+
*
|
|
99
|
+
* @throws ApprovalRequiredException when approval is needed (interrupt mode)
|
|
100
|
+
*/
|
|
101
|
+
async execute(code, config) {
|
|
102
|
+
const result = await this.client.execute(code, config);
|
|
103
|
+
return {
|
|
104
|
+
result,
|
|
105
|
+
needsApproval: false,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Resume execution after approval decision
|
|
110
|
+
*
|
|
111
|
+
* Call this after LangGraph resumes from interrupt with approval decision.
|
|
112
|
+
*/
|
|
113
|
+
async resumeWithApproval(executionId, approved, reason) {
|
|
114
|
+
const approvalResponse = {
|
|
115
|
+
approved,
|
|
116
|
+
reason,
|
|
117
|
+
timestamp: Date.now(),
|
|
118
|
+
};
|
|
119
|
+
this.pendingApprovals.delete(executionId);
|
|
120
|
+
return await this.client.resume(executionId, approvalResponse);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get pending approval request for an execution
|
|
124
|
+
*/
|
|
125
|
+
getPendingApproval(executionId) {
|
|
126
|
+
return this.pendingApprovals.get(executionId);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Handle LLM call - route to LangChain LLM
|
|
130
|
+
*/
|
|
131
|
+
async handleLLMCall(prompt, options) {
|
|
132
|
+
const messages = [];
|
|
133
|
+
if (options?.systemPrompt) {
|
|
134
|
+
messages.push(new SystemMessage(options.systemPrompt));
|
|
135
|
+
}
|
|
136
|
+
messages.push(new HumanMessage(prompt));
|
|
137
|
+
const response = await this.llm.invoke(messages);
|
|
138
|
+
return typeof response.content === 'string'
|
|
139
|
+
? response.content
|
|
140
|
+
: JSON.stringify(response.content);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Handle LLM extract - route to LangChain LLM with structured output
|
|
144
|
+
*/
|
|
145
|
+
async handleLLMExtract(prompt, schema, options) {
|
|
146
|
+
const structuredLLM = this.llm.withStructuredOutput(schema);
|
|
147
|
+
const messages = [];
|
|
148
|
+
if (options?.systemPrompt) {
|
|
149
|
+
messages.push(new SystemMessage(options.systemPrompt));
|
|
150
|
+
}
|
|
151
|
+
messages.push(new HumanMessage(prompt));
|
|
152
|
+
const result = await structuredLLM.invoke(messages);
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Handle LLM classify - route to LangChain LLM
|
|
157
|
+
*/
|
|
158
|
+
async handleLLMClassify(text, categories, options) {
|
|
159
|
+
const prompt = `Classify the following text into one of these categories: ${categories.join(', ')}\n\nText: ${text}\n\nCategory:`;
|
|
160
|
+
const messages = [];
|
|
161
|
+
if (options?.systemPrompt) {
|
|
162
|
+
messages.push(new SystemMessage(options.systemPrompt));
|
|
163
|
+
}
|
|
164
|
+
messages.push(new HumanMessage(prompt));
|
|
165
|
+
const response = await this.llm.invoke(messages);
|
|
166
|
+
const result = typeof response.content === 'string'
|
|
167
|
+
? response.content.trim()
|
|
168
|
+
: JSON.stringify(response.content).trim();
|
|
169
|
+
if (!categories.includes(result)) {
|
|
170
|
+
for (const category of categories) {
|
|
171
|
+
if (result.toLowerCase().includes(category.toLowerCase())) {
|
|
172
|
+
return category;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const fallback = categories[0];
|
|
176
|
+
if (!fallback) {
|
|
177
|
+
throw new Error('No categories provided for classification');
|
|
178
|
+
}
|
|
179
|
+
return fallback;
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Handle embedding - route to LangChain embeddings model
|
|
185
|
+
*/
|
|
186
|
+
async handleEmbedding(text) {
|
|
187
|
+
if (!this.embeddings) {
|
|
188
|
+
throw new Error('Embeddings model not provided. Pass embeddings option when creating LangGraphATPClient.');
|
|
189
|
+
}
|
|
190
|
+
return await this.embeddings.embedQuery(text);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get the underlying ATP client for advanced usage
|
|
194
|
+
*/
|
|
195
|
+
getUnderlyingClient() {
|
|
196
|
+
return this.client;
|
|
197
|
+
}
|
|
198
|
+
async handleApprovalRequest(message, context) {
|
|
199
|
+
const executionId = context?.executionId;
|
|
200
|
+
const cleanContext = context ? { ...context } : undefined;
|
|
201
|
+
if (cleanContext) {
|
|
202
|
+
delete cleanContext.executionId;
|
|
203
|
+
}
|
|
204
|
+
if (this.useLangGraphInterrupts) {
|
|
205
|
+
if (typeof executionId !== 'string' || !executionId) {
|
|
206
|
+
throw new Error('executionId is missing in approval request context');
|
|
207
|
+
}
|
|
208
|
+
const approvalRequest = {
|
|
209
|
+
message,
|
|
210
|
+
context: cleanContext,
|
|
211
|
+
executionId,
|
|
212
|
+
timestamp: Date.now(),
|
|
213
|
+
};
|
|
214
|
+
this.pendingApprovals.set(executionId, approvalRequest);
|
|
215
|
+
throw new ApprovalRequiredException(approvalRequest);
|
|
216
|
+
}
|
|
217
|
+
if (this.directApprovalHandler) {
|
|
218
|
+
const approved = await this.directApprovalHandler(message, cleanContext);
|
|
219
|
+
return {
|
|
220
|
+
approved,
|
|
221
|
+
timestamp: Date.now(),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
console.warn(`Approval request rejected (no handler): ${message}`);
|
|
225
|
+
return {
|
|
226
|
+
approved: false,
|
|
227
|
+
timestamp: Date.now(),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=langgraph-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph-client.js","sourceRoot":"","sources":["../src/langgraph-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAM3F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAa,MAAM,0BAA0B,CAAC;AAsElF;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,mBAAmB;IACrC;IAA5B,YAA4B,eAAgC;QAC3D,KAAK,CAAC,sBAAsB,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAD5B,oBAAe,GAAf,eAAe,CAAiB;QAE3D,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACzC,CAAC;CACD;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IACtB,MAAM,CAA0B;IAChC,GAAG,CAAgB;IACnB,UAAU,CAAc;IACxB,sBAAsB,CAAU;IAChC,qBAAqB,CAGP;IAEd,gBAAg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AAC;QAED,OAAO,CAAC,IAAI,CAAC,2CAA2C,OAAO,EAAE,CAAC,CAAC;QACnE,OAAO;YACN,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACrB,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph Tools Integration for ATP
|
|
3
|
+
*
|
|
4
|
+
* Creates LangChain-compatible tools from ATP with full support for:
|
|
5
|
+
* - LangGraph interrupts for human-in-the-loop approvals
|
|
6
|
+
* - LLM sampling via LangChain models
|
|
7
|
+
* - Checkpoint-based state persistence
|
|
8
|
+
*/
|
|
9
|
+
import { Tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
10
|
+
import { LangGraphATPClient, type LangGraphATPClientOptions, ApprovalRequiredException } from './langgraph-client.js';
|
|
11
|
+
import { type ExecutionConfig } from '@mondaydotcomorg/atp-protocol';
|
|
12
|
+
/**
|
|
13
|
+
* Options for creating ATP tools with LangGraph integration
|
|
14
|
+
*/
|
|
15
|
+
export interface CreateATPToolsOptions extends Omit<LangGraphATPClientOptions, 'serverUrl'> {
|
|
16
|
+
/** ATP server URL */
|
|
17
|
+
serverUrl: string;
|
|
18
|
+
/**
|
|
19
|
+
* Default execution config for all ATP code executions
|
|
20
|
+
*/
|
|
21
|
+
defaultExecutionConfig?: Partial<ExecutionConfig>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of creating ATP tools
|
|
25
|
+
*/
|
|
26
|
+
export interface ATPToolsResult {
|
|
27
|
+
/** The LangGraph-aware ATP client */
|
|
28
|
+
client: LangGraphATPClient;
|
|
29
|
+
/** LangChain tools for agent use */
|
|
30
|
+
tools: (Tool | DynamicStructuredTool)[];
|
|
31
|
+
/**
|
|
32
|
+
* Helper to check if an error is an approval request
|
|
33
|
+
*/
|
|
34
|
+
isApprovalRequired: (error: any) => error is ApprovalRequiredException;
|
|
35
|
+
/**
|
|
36
|
+
* Helper to resume after approval
|
|
37
|
+
*/
|
|
38
|
+
resumeWithApproval: (executionId: string, approved: boolean, reason?: string) => Promise<any>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates LangChain tools from ATP server with LangGraph interrupt support
|
|
42
|
+
*
|
|
43
|
+
* Example usage with LangGraph:
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { StateGraph } from "@langchain/langgraph";
|
|
46
|
+
* import { MemorySaver } from "@langchain/langgraph";
|
|
47
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
48
|
+
*
|
|
49
|
+
* const llm = new ChatOpenAI({ modelName: "gpt-4" });
|
|
50
|
+
* const { client, tools, isApprovalRequired, resumeWithApproval } = await createATPTools({
|
|
51
|
+
* serverUrl: 'http://localhost:3333',
|
|
52
|
+
* headers: { Authorization: 'Bearer test-key' }, // Optional
|
|
53
|
+
* llm,
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Use tools in LangGraph agent
|
|
57
|
+
* const graph = new StateGraph({...})
|
|
58
|
+
* .addNode("agent", agentNode)
|
|
59
|
+
* .addNode("approval", async (state) => {
|
|
60
|
+
* // Human reviews state.approvalRequest
|
|
61
|
+
* return interrupt({ value: state.approvalRequest });
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const checkpointer = new MemorySaver();
|
|
65
|
+
* const app = graph.compile({
|
|
66
|
+
* checkpointer,
|
|
67
|
+
* interruptBefore: ["approval"]
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function createATPTools(options: CreateATPToolsOptions): Promise<ATPToolsResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Helper to create a simple ATP tool for existing LangGraph agents
|
|
74
|
+
*
|
|
75
|
+
* This creates a single tool that can execute ATP code. For more control,
|
|
76
|
+
* use createATPTools() directly.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createSimpleATPTool(serverUrl: string, llm: any, headers?: Record<string, string>): Promise<Tool | DynamicStructuredTool>;
|
|
79
|
+
//# sourceMappingURL=langgraph-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph-tools.d.ts","sourceRoot":"","sources":["../src/langgraph-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAe,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EACN,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,yBAAyB,EACzB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,yBAAyB,EAAE,WAAW,CAAC;IAC1F,qBAAqB;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,oCAAoC;IACpC,KAAK,EAAE,CAAC,IAAI,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACxC;;OAEG;IACH,kBAAkB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,IAAI,yBAAyB,CAAC;IACvE;;OAEG;IACH,kBAAkB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC9F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CA+G5F;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACxC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,GAAG,qBAAqB,CAAC,CAWvC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph Tools Integration for ATP
|
|
3
|
+
*
|
|
4
|
+
* Creates LangChain-compatible tools from ATP with full support for:
|
|
5
|
+
* - LangGraph interrupts for human-in-the-loop approvals
|
|
6
|
+
* - LLM sampling via LangChain models
|
|
7
|
+
* - Checkpoint-based state persistence
|
|
8
|
+
*/
|
|
9
|
+
import { Tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
10
|
+
import { LangGraphATPClient, ApprovalRequiredException, } from './langgraph-client.js';
|
|
11
|
+
import { createToolsFromATPClient, ToolNames, } from '@mondaydotcomorg/atp-client';
|
|
12
|
+
import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
|
|
13
|
+
/**
|
|
14
|
+
* Creates LangChain tools from ATP server with LangGraph interrupt support
|
|
15
|
+
*
|
|
16
|
+
* Example usage with LangGraph:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { StateGraph } from "@langchain/langgraph";
|
|
19
|
+
* import { MemorySaver } from "@langchain/langgraph";
|
|
20
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
21
|
+
*
|
|
22
|
+
* const llm = new ChatOpenAI({ modelName: "gpt-4" });
|
|
23
|
+
* const { client, tools, isApprovalRequired, resumeWithApproval } = await createATPTools({
|
|
24
|
+
* serverUrl: 'http://localhost:3333',
|
|
25
|
+
* headers: { Authorization: 'Bearer test-key' }, // Optional
|
|
26
|
+
* llm,
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Use tools in LangGraph agent
|
|
30
|
+
* const graph = new StateGraph({...})
|
|
31
|
+
* .addNode("agent", agentNode)
|
|
32
|
+
* .addNode("approval", async (state) => {
|
|
33
|
+
* // Human reviews state.approvalRequest
|
|
34
|
+
* return interrupt({ value: state.approvalRequest });
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const checkpointer = new MemorySaver();
|
|
38
|
+
* const app = graph.compile({
|
|
39
|
+
* checkpointer,
|
|
40
|
+
* interruptBefore: ["approval"]
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export async function createATPTools(options) {
|
|
45
|
+
const { serverUrl, defaultExecutionConfig, ...clientOptions } = options;
|
|
46
|
+
const client = new LangGraphATPClient({
|
|
47
|
+
serverUrl,
|
|
48
|
+
...clientOptions,
|
|
49
|
+
});
|
|
50
|
+
await client.connect();
|
|
51
|
+
const atpTools = createToolsFromATPClient(client.getUnderlyingClient());
|
|
52
|
+
const tools = atpTools.map((atpTool) => {
|
|
53
|
+
if (atpTool.name === ToolNames.EXECUTE_CODE) {
|
|
54
|
+
class ATPExecuteTool extends Tool {
|
|
55
|
+
name = `atp_${atpTool.name}`;
|
|
56
|
+
description = atpTool.description || 'Execute TypeScript code in ATP sandbox';
|
|
57
|
+
async _call(input) {
|
|
58
|
+
try {
|
|
59
|
+
let code;
|
|
60
|
+
try {
|
|
61
|
+
const parsed = JSON.parse(input);
|
|
62
|
+
code = parsed.code || input;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
code = input;
|
|
66
|
+
}
|
|
67
|
+
const result = await client.execute(code, defaultExecutionConfig);
|
|
68
|
+
if (result.result.status === ExecutionStatus.COMPLETED) {
|
|
69
|
+
return JSON.stringify({
|
|
70
|
+
success: true,
|
|
71
|
+
result: result.result.result,
|
|
72
|
+
stats: result.result.stats,
|
|
73
|
+
}, null, 2);
|
|
74
|
+
}
|
|
75
|
+
else if (result.result.status === ExecutionStatus.FAILED) {
|
|
76
|
+
return JSON.stringify({
|
|
77
|
+
success: false,
|
|
78
|
+
error: result.result.error,
|
|
79
|
+
stats: result.result.stats,
|
|
80
|
+
}, null, 2);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return JSON.stringify({
|
|
84
|
+
success: false,
|
|
85
|
+
error: 'Execution in unexpected state: ' + result.result.status,
|
|
86
|
+
}, null, 2);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error instanceof ApprovalRequiredException) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
return JSON.stringify({
|
|
94
|
+
success: false,
|
|
95
|
+
error: error.message || 'Unknown error',
|
|
96
|
+
}, null, 2);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return new ATPExecuteTool();
|
|
101
|
+
}
|
|
102
|
+
return new DynamicStructuredTool({
|
|
103
|
+
name: `atp_${atpTool.name}`,
|
|
104
|
+
description: atpTool.description || '',
|
|
105
|
+
schema: atpTool.zodSchema || atpTool.inputSchema,
|
|
106
|
+
func: async (input) => {
|
|
107
|
+
try {
|
|
108
|
+
const result = await atpTool.func(input);
|
|
109
|
+
return typeof result === 'string' ? result : JSON.stringify(result, null, 2);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return JSON.stringify({
|
|
113
|
+
success: false,
|
|
114
|
+
error: error.message,
|
|
115
|
+
}, null, 2);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
client,
|
|
122
|
+
tools,
|
|
123
|
+
isApprovalRequired: (error) => {
|
|
124
|
+
return error instanceof ApprovalRequiredException;
|
|
125
|
+
},
|
|
126
|
+
resumeWithApproval: async (executionId, approved, reason) => {
|
|
127
|
+
return await client.resumeWithApproval(executionId, approved, reason);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Helper to create a simple ATP tool for existing LangGraph agents
|
|
133
|
+
*
|
|
134
|
+
* This creates a single tool that can execute ATP code. For more control,
|
|
135
|
+
* use createATPTools() directly.
|
|
136
|
+
*/
|
|
137
|
+
export async function createSimpleATPTool(serverUrl, llm, headers) {
|
|
138
|
+
const result = await createATPTools({
|
|
139
|
+
serverUrl,
|
|
140
|
+
headers,
|
|
141
|
+
llm,
|
|
142
|
+
});
|
|
143
|
+
const tool = result.tools.find((t) => t.name === `atp_${ToolNames.EXECUTE_CODE}`);
|
|
144
|
+
if (!tool) {
|
|
145
|
+
throw new Error('Failed to create ATP execute_code tool');
|
|
146
|
+
}
|
|
147
|
+
return tool;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=langgraph-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph-tools.js","sourceRoot":"","sources":["../src/langgraph-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAe,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EACN,kBAAkB,EAElB,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,SAAS,GAET,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAwB,MAAM,+BAA+B,CAAC;AAgCtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IAClE,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAExE,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;QACrC,SAAS;QACT,GAAG,aAAa;KAChB,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,MAAM,QAAQ,GAAG,wBAAwB,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAExE,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE;QAC/C,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,YA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C,KAAU,EAAsC,EAAE;YACtE,OAAO,KAAK,YAAY,yBAAyB,CAAC;QACnD,CAAC;QACD,kBAAkB,EAAE,KAAK,EAAE,WAAmB,EAAE,QAAiB,EAAE,MAAe,EAAE,EAAE;YACrF,OAAO,MAAM,MAAM,CAAC,kBAAkB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACvE,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,SAAiB,EACjB,GAAQ,EACR,OAAgC;IAEhC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;QACnC,SAAS;QACT,OAAO;QACP,GAAG;KACH,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,SAAS,CAAC,YAAY,EAAE,CAAC,CAAC;IAClF,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AgentToolProtocolClient } from '@mondaydotcomorg/atp-client';
|
|
2
|
+
/**
|
|
3
|
+
* LangGraph-compatible node for ATP execution
|
|
4
|
+
*/
|
|
5
|
+
export declare class ATPExecutionNode {
|
|
6
|
+
private client;
|
|
7
|
+
constructor(client: AgentToolProtocolClient);
|
|
8
|
+
/**
|
|
9
|
+
* Execute code from the state and update the state with results
|
|
10
|
+
*/
|
|
11
|
+
execute(state: {
|
|
12
|
+
code?: string;
|
|
13
|
+
messages?: any[];
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a function suitable for LangGraph node
|
|
18
|
+
*/
|
|
19
|
+
asFunction(): (state: {
|
|
20
|
+
code?: string;
|
|
21
|
+
messages?: any[];
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}) => Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Helper to create a simple ATP execution node function
|
|
27
|
+
*/
|
|
28
|
+
export declare function createATPNode(client: AgentToolProtocolClient): (state: any) => Promise<any>;
|
|
29
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAGtE;;GAEG;AACH,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,EAAE,uBAAuB;IAI3C;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAgB3F;;OAEG;IACH,UAAU,YAnBW;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KAAG,OAAO,CAAC,GAAG,CAAC;CAsB3F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,uBAAuB,IAC9C,OAAO,GAAG,kBAexB"}
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* LangGraph-compatible node for ATP execution
|
|
4
|
+
*/
|
|
5
|
+
export class ATPExecutionNode {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Execute code from the state and update the state with results
|
|
12
|
+
*/
|
|
13
|
+
async execute(state) {
|
|
14
|
+
if (!state.code) {
|
|
15
|
+
throw new Error('No code provided in state');
|
|
16
|
+
}
|
|
17
|
+
const result = await this.client.execute(state.code);
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
executionResult: result,
|
|
21
|
+
lastExecutionStatus: result.status,
|
|
22
|
+
lastExecutionOutput: result.status === ExecutionStatus.COMPLETED ? result.result : result.error,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a function suitable for LangGraph node
|
|
27
|
+
*/
|
|
28
|
+
asFunction() {
|
|
29
|
+
return this.execute.bind(this);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helper to create a simple ATP execution node function
|
|
34
|
+
*/
|
|
35
|
+
export function createATPNode(client) {
|
|
36
|
+
return async (state) => {
|
|
37
|
+
if (!state.code) {
|
|
38
|
+
throw new Error('No code provided in state');
|
|
39
|
+
}
|
|
40
|
+
const result = await client.execute(state.code);
|
|
41
|
+
return {
|
|
42
|
+
...state,
|
|
43
|
+
executionResult: result,
|
|
44
|
+
lastExecutionStatus: result.status,
|
|
45
|
+
lastExecutionOutput: result.status === ExecutionStatus.COMPLETED ? result.result : result.error,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACpB,MAAM,CAA0B;IAExC,YAAY,MAA+B;QAC1C,IAAI,CAAC,MAAM,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 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain Integration for Agent Tool Protocol
|
|
3
|
+
*
|
|
4
|
+
* Converts ATP client tools into LangChain DynamicTool instances
|
|
5
|
+
*/
|
|
6
|
+
import { AgentToolProtocolClient, type Tool, type ClientHooks } from '@mondaydotcomorg/atp-client';
|
|
7
|
+
import { DynamicTool } from '@langchain/core/tools';
|
|
8
|
+
/**
|
|
9
|
+
* Creates ATP client and returns LangChain-compatible DynamicTool instances
|
|
10
|
+
* The client is automatically connected and ready to use.
|
|
11
|
+
*
|
|
12
|
+
* @param serverUrl - ATP server URL (e.g. 'http://localhost:3333')
|
|
13
|
+
* @param headers - Optional headers for authentication (e.g. { Authorization: 'Bearer token' })
|
|
14
|
+
* @param hooks - Optional hooks for intercepting and modifying client behavior
|
|
15
|
+
* @returns Promise of { client, tools } where tools is an array of LangChain DynamicTools
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { client, tools } = await createATPTools('http://localhost:3333', {
|
|
20
|
+
* Authorization: 'Bearer api-key'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Use tools with any LangChain agent
|
|
24
|
+
* const agent = await createReactAgent({ llm, tools, prompt });
|
|
25
|
+
* const executor = new AgentExecutor({ agent, tools });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createATPTools(serverUrl: string, headers?: Record<string, string>, hooks?: ClientHooks): Promise<{
|
|
29
|
+
client: AgentToolProtocolClient;
|
|
30
|
+
tools: DynamicTool<string>[];
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Converts generic ATP tools into LangChain DynamicTool instances
|
|
34
|
+
*
|
|
35
|
+
* @param tools - Array of ATP tools (with inputSchema and func)
|
|
36
|
+
* @returns Array of LangChain DynamicTools
|
|
37
|
+
*/
|
|
38
|
+
export declare function convertToLangChainTools(tools: Tool[]): DynamicTool[];
|
|
39
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,uBAAuB,EAEvB,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CACnC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,KAAK,CAAC,EAAE,WAAW;;;GAiBnB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,EAAE,CASpE"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain Integration for Agent Tool Protocol
|
|
3
|
+
*
|
|
4
|
+
* Converts ATP client tools into LangChain DynamicTool instances
|
|
5
|
+
*/
|
|
6
|
+
import { AgentToolProtocolClient, createToolsFromATPClient, } from '@mondaydotcomorg/atp-client';
|
|
7
|
+
import { DynamicTool } from '@langchain/core/tools';
|
|
8
|
+
/**
|
|
9
|
+
* Creates ATP client and returns LangChain-compatible DynamicTool instances
|
|
10
|
+
* The client is automatically connected and ready to use.
|
|
11
|
+
*
|
|
12
|
+
* @param serverUrl - ATP server URL (e.g. 'http://localhost:3333')
|
|
13
|
+
* @param headers - Optional headers for authentication (e.g. { Authorization: 'Bearer token' })
|
|
14
|
+
* @param hooks - Optional hooks for intercepting and modifying client behavior
|
|
15
|
+
* @returns Promise of { client, tools } where tools is an array of LangChain DynamicTools
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { client, tools } = await createATPTools('http://localhost:3333', {
|
|
20
|
+
* Authorization: 'Bearer api-key'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Use tools with any LangChain agent
|
|
24
|
+
* const agent = await createReactAgent({ llm, tools, prompt });
|
|
25
|
+
* const executor = new AgentExecutor({ agent, tools });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function createATPTools(serverUrl, headers, hooks) {
|
|
29
|
+
const client = new AgentToolProtocolClient({ baseUrl: serverUrl, headers, hooks });
|
|
30
|
+
await client.connect();
|
|
31
|
+
const atpTools = createToolsFromATPClient(client);
|
|
32
|
+
const tools = atpTools.map((tool) => new DynamicTool({
|
|
33
|
+
name: tool.name,
|
|
34
|
+
description: tool.description || '',
|
|
35
|
+
func: tool.func,
|
|
36
|
+
}));
|
|
37
|
+
return { client, tools };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts generic ATP tools into LangChain DynamicTool instances
|
|
41
|
+
*
|
|
42
|
+
* @param tools - Array of ATP tools (with inputSchema and func)
|
|
43
|
+
* @returns Array of LangChain DynamicTools
|
|
44
|
+
*/
|
|
45
|
+
export function convertToLangChainTools(tools) {
|
|
46
|
+
return tools.map((tool) => new DynamicTool({
|
|
47
|
+
name: tool.name,
|
|
48
|
+
description: tool.description || '',
|
|
49
|
+
func: tool.func,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=tools.js.map
|