@mongodb-js/agent-engine-sdk-langgraph 0.11.3
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 +39 -0
- package/LICENSE.md +201 -0
- package/README.md +149 -0
- package/dist/agent.d.ts +53 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +508 -0
- package/dist/agent.js.map +1 -0
- package/dist/backends/tool_sandbox.d.ts +15 -0
- package/dist/backends/tool_sandbox.d.ts.map +1 -0
- package/dist/backends/tool_sandbox.js +15 -0
- package/dist/backends/tool_sandbox.js.map +1 -0
- package/dist/backends/toolpod.d.ts +68 -0
- package/dist/backends/toolpod.d.ts.map +1 -0
- package/dist/backends/toolpod.js +451 -0
- package/dist/backends/toolpod.js.map +1 -0
- package/dist/call_interrupt.d.ts +20 -0
- package/dist/call_interrupt.d.ts.map +1 -0
- package/dist/call_interrupt.js +23 -0
- package/dist/call_interrupt.js.map +1 -0
- package/dist/checkpoint_branch.d.ts +58 -0
- package/dist/checkpoint_branch.d.ts.map +1 -0
- package/dist/checkpoint_branch.js +239 -0
- package/dist/checkpoint_branch.js.map +1 -0
- package/dist/checkpointer.d.ts +21 -0
- package/dist/checkpointer.d.ts.map +1 -0
- package/dist/checkpointer.js +31 -0
- package/dist/checkpointer.js.map +1 -0
- package/dist/deep_agent.d.ts +49 -0
- package/dist/deep_agent.d.ts.map +1 -0
- package/dist/deep_agent.js +110 -0
- package/dist/deep_agent.js.map +1 -0
- package/dist/deep_agent_checkpointer.d.ts +11 -0
- package/dist/deep_agent_checkpointer.d.ts.map +1 -0
- package/dist/deep_agent_checkpointer.js +19 -0
- package/dist/deep_agent_checkpointer.js.map +1 -0
- package/dist/deep_agent_task.d.ts +26 -0
- package/dist/deep_agent_task.d.ts.map +1 -0
- package/dist/deep_agent_task.js +49 -0
- package/dist/deep_agent_task.js.map +1 -0
- package/dist/durable_deep_agent.d.ts +23 -0
- package/dist/durable_deep_agent.d.ts.map +1 -0
- package/dist/durable_deep_agent.js +176 -0
- package/dist/durable_deep_agent.js.map +1 -0
- package/dist/durable_message_identity.d.ts +5 -0
- package/dist/durable_message_identity.d.ts.map +1 -0
- package/dist/durable_message_identity.js +106 -0
- package/dist/durable_message_identity.js.map +1 -0
- package/dist/durable_session.d.ts +30 -0
- package/dist/durable_session.d.ts.map +1 -0
- package/dist/durable_session.js +400 -0
- package/dist/durable_session.js.map +1 -0
- package/dist/durable_subgraphs.d.ts +13 -0
- package/dist/durable_subgraphs.d.ts.map +1 -0
- package/dist/durable_subgraphs.js +82 -0
- package/dist/durable_subgraphs.js.map +1 -0
- package/dist/durable_tools.d.ts +12 -0
- package/dist/durable_tools.d.ts.map +1 -0
- package/dist/durable_tools.js +41 -0
- package/dist/durable_tools.js.map +1 -0
- package/dist/execution_session.d.ts +63 -0
- package/dist/execution_session.d.ts.map +1 -0
- package/dist/execution_session.js +300 -0
- package/dist/execution_session.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/llm_adapter.d.ts +41 -0
- package/dist/llm_adapter.d.ts.map +1 -0
- package/dist/llm_adapter.js +177 -0
- package/dist/llm_adapter.js.map +1 -0
- package/dist/messages.d.ts +56 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +592 -0
- package/dist/messages.js.map +1 -0
- package/dist/node_logger_adapter.d.ts +51 -0
- package/dist/node_logger_adapter.d.ts.map +1 -0
- package/dist/node_logger_adapter.js +163 -0
- package/dist/node_logger_adapter.js.map +1 -0
- package/dist/platform_checkpointer.d.ts +70 -0
- package/dist/platform_checkpointer.d.ts.map +1 -0
- package/dist/platform_checkpointer.js +252 -0
- package/dist/platform_checkpointer.js.map +1 -0
- package/dist/query.d.ts +103 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +623 -0
- package/dist/query.js.map +1 -0
- package/dist/runtime.d.ts +336 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +881 -0
- package/dist/runtime.js.map +1 -0
- package/dist/secure_llm.d.ts +93 -0
- package/dist/secure_llm.d.ts.map +1 -0
- package/dist/secure_llm.js +423 -0
- package/dist/secure_llm.js.map +1 -0
- package/dist/session_factory.d.ts +6 -0
- package/dist/session_factory.d.ts.map +1 -0
- package/dist/session_factory.js +29 -0
- package/dist/session_factory.js.map +1 -0
- package/dist/session_fork.d.ts +76 -0
- package/dist/session_fork.d.ts.map +1 -0
- package/dist/session_fork.js +428 -0
- package/dist/session_fork.js.map +1 -0
- package/dist/subagents.d.ts +37 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +67 -0
- package/dist/subagents.js.map +1 -0
- package/dist/suspend.d.ts +27 -0
- package/dist/suspend.d.ts.map +1 -0
- package/dist/suspend.js +87 -0
- package/dist/suspend.js.map +1 -0
- package/dist/thread_id.d.ts +30 -0
- package/dist/thread_id.d.ts.map +1 -0
- package/dist/thread_id.js +69 -0
- package/dist/thread_id.js.map +1 -0
- package/dist/workflow_json.d.ts +11 -0
- package/dist/workflow_json.d.ts.map +1 -0
- package/dist/workflow_json.js +49 -0
- package/dist/workflow_json.js.map +1 -0
- package/dist/workflow_message.d.ts +11 -0
- package/dist/workflow_message.d.ts.map +1 -0
- package/dist/workflow_message.js +179 -0
- package/dist/workflow_message.js.map +1 -0
- package/dist/workflow_state.d.ts +7 -0
- package/dist/workflow_state.d.ts.map +1 -0
- package/dist/workflow_state.js +62 -0
- package/dist/workflow_state.js.map +1 -0
- package/package.json +66 -0
package/dist/agent.js
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangGraph BaseAgent adapter.
|
|
3
|
+
*
|
|
4
|
+
* Wraps a LangGraph compiled graph to implement the framework-neutral
|
|
5
|
+
* `BaseAgent` protocol from agent-engine-sdk. Execution-session setup lives in
|
|
6
|
+
* `execution_session.ts`; this adapter owns graph invocation and event/result
|
|
7
|
+
* translation.
|
|
8
|
+
*
|
|
9
|
+
* Port of `agent_engine_sdk_langgraph/agent.py`.
|
|
10
|
+
*/
|
|
11
|
+
import { AIMessage, AIMessageChunk, ToolMessage, } from "@langchain/core/messages";
|
|
12
|
+
import { Command } from "@langchain/langgraph";
|
|
13
|
+
import { isDeepStrictEqual } from "node:util";
|
|
14
|
+
import {} from "@mongodb-js/agent-engine-sdk";
|
|
15
|
+
import { getLogger } from "@mongodb-js/agent-engine-runner-shared";
|
|
16
|
+
import {} from "./execution_session.js";
|
|
17
|
+
import { installDurableMessageIdentity } from "./durable_message_identity.js";
|
|
18
|
+
import { DurableSubgraphResolver } from "./durable_subgraphs.js";
|
|
19
|
+
import { iterTaskCalls } from "./deep_agent_task.js";
|
|
20
|
+
import { lcMessagesToPlatform, unwrapMessageValues } from "./messages.js";
|
|
21
|
+
import { wrapSessionForkUpdateState } from "./session_fork.js";
|
|
22
|
+
import { executionSession } from "./session_factory.js";
|
|
23
|
+
const logger = getLogger("agent_engine_sdk_langgraph.agent");
|
|
24
|
+
// LangGraph namespace segment shape: ``"<node_name>:<task_id>"``.
|
|
25
|
+
const NS_TASK_SEP = ":";
|
|
26
|
+
// LangChain/LangGraph pregel node names; never identify a real subagent.
|
|
27
|
+
const NS_SENTINEL_NAMES = new Set(["agent", "model", "tools"]);
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Internal helpers
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/** Extract subagent attribution from a LangGraph subgraph namespace tuple. */
|
|
32
|
+
function sourceFromNamespace(namespace) {
|
|
33
|
+
for (let i = namespace.length - 1; i >= 0; i--) {
|
|
34
|
+
const segment = namespace[i];
|
|
35
|
+
const name = segment.split(NS_TASK_SEP, 1)[0] ?? "";
|
|
36
|
+
if (name !== "" && !NS_SENTINEL_NAMES.has(name))
|
|
37
|
+
return name;
|
|
38
|
+
}
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
function startEvent(task) {
|
|
42
|
+
return {
|
|
43
|
+
data: {
|
|
44
|
+
source: task.name,
|
|
45
|
+
subagent_name: task.name,
|
|
46
|
+
tool_call_id: task.tcId,
|
|
47
|
+
description: task.description,
|
|
48
|
+
},
|
|
49
|
+
event: "subagent_start",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function endEvent(task, summary = "") {
|
|
53
|
+
return {
|
|
54
|
+
data: {
|
|
55
|
+
source: task.name,
|
|
56
|
+
subagent_name: task.name,
|
|
57
|
+
tool_call_id: task.tcId,
|
|
58
|
+
summary,
|
|
59
|
+
},
|
|
60
|
+
event: "subagent_end",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function tcIdForSource(source, tasksById) {
|
|
64
|
+
if (source === "")
|
|
65
|
+
return "";
|
|
66
|
+
for (const task of tasksById.values()) {
|
|
67
|
+
if (task.name === source)
|
|
68
|
+
return task.tcId;
|
|
69
|
+
}
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
async function* onTaskCall(call, tasksById, pending) {
|
|
73
|
+
const placeholder = pending.get(call.subagentName);
|
|
74
|
+
if (placeholder !== undefined) {
|
|
75
|
+
pending.delete(call.subagentName);
|
|
76
|
+
placeholder.tcId = call.toolCallId;
|
|
77
|
+
if (call.description !== "" && placeholder.description === "") {
|
|
78
|
+
placeholder.description = call.description;
|
|
79
|
+
}
|
|
80
|
+
tasksById.set(call.toolCallId, placeholder);
|
|
81
|
+
yield startEvent(placeholder);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const existing = tasksById.get(call.toolCallId);
|
|
85
|
+
if (existing !== undefined) {
|
|
86
|
+
if (call.description !== "" && existing.description === "") {
|
|
87
|
+
existing.description = call.description;
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const task = {
|
|
92
|
+
name: call.subagentName,
|
|
93
|
+
tcId: call.toolCallId,
|
|
94
|
+
description: call.description,
|
|
95
|
+
};
|
|
96
|
+
tasksById.set(call.toolCallId, task);
|
|
97
|
+
yield startEvent(task);
|
|
98
|
+
}
|
|
99
|
+
function onSourcedToken(source, tasksById, pending) {
|
|
100
|
+
// First sourced token signal — insert a synthetic placeholder in `pending`
|
|
101
|
+
// if no entry exists. Strategy A: do NOT emit subagent_start here.
|
|
102
|
+
for (const task of tasksById.values()) {
|
|
103
|
+
if (task.name === source)
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (pending.has(source))
|
|
107
|
+
return;
|
|
108
|
+
pending.set(source, { name: source, tcId: "", description: "" });
|
|
109
|
+
}
|
|
110
|
+
async function* drainOpenTasks(tasksById, pending) {
|
|
111
|
+
for (const task of [...tasksById.values()]) {
|
|
112
|
+
yield endEvent(task);
|
|
113
|
+
}
|
|
114
|
+
for (const task of [...pending.values()]) {
|
|
115
|
+
yield startEvent(task);
|
|
116
|
+
yield endEvent(task);
|
|
117
|
+
}
|
|
118
|
+
tasksById.clear();
|
|
119
|
+
pending.clear();
|
|
120
|
+
}
|
|
121
|
+
function normalizeContent(content) {
|
|
122
|
+
if (typeof content === "string")
|
|
123
|
+
return content;
|
|
124
|
+
if (Array.isArray(content)) {
|
|
125
|
+
const parts = [];
|
|
126
|
+
for (const block of content) {
|
|
127
|
+
if (block !== null && typeof block === "object") {
|
|
128
|
+
const b = block;
|
|
129
|
+
if (b["type"] === "text" && typeof b["text"] === "string")
|
|
130
|
+
parts.push(b["text"]);
|
|
131
|
+
}
|
|
132
|
+
else if (typeof block === "string") {
|
|
133
|
+
parts.push(block);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return parts.join("");
|
|
137
|
+
}
|
|
138
|
+
if (content === null || content === undefined)
|
|
139
|
+
return "";
|
|
140
|
+
return String(content);
|
|
141
|
+
}
|
|
142
|
+
function findLastAiContent(messages) {
|
|
143
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
144
|
+
const msg = messages[i];
|
|
145
|
+
if (msg &&
|
|
146
|
+
(msg instanceof AIMessage ||
|
|
147
|
+
msg instanceof AIMessageChunk ||
|
|
148
|
+
msg.type === "ai")) {
|
|
149
|
+
const content = normalizeContent(msg.content);
|
|
150
|
+
if (content !== "")
|
|
151
|
+
return content;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Detect cancellation / abort errors. The TS equivalents of Python's
|
|
158
|
+
* `asyncio.CancelledError` / `GeneratorExit` are `AbortError` (DOMException)
|
|
159
|
+
* and any error whose name signals cancellation by upstream cancellation
|
|
160
|
+
* sources.
|
|
161
|
+
*/
|
|
162
|
+
function isCancellationError(exc) {
|
|
163
|
+
if (exc instanceof Error) {
|
|
164
|
+
return exc.name === "AbortError" || exc.name === "CancelledError";
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// ExecutionResult wrapper
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
/**
|
|
172
|
+
* Concrete `ExecutionResult` — dual-mode handle.
|
|
173
|
+
*
|
|
174
|
+
* Implements `PromiseLike<AgentOutput>` (so callers can `await`) and
|
|
175
|
+
* `AsyncIterable<StreamEvent>` (so callers can `for await`). Mirrors the
|
|
176
|
+
* Python dual-shape via `__await__` + `__aiter__`.
|
|
177
|
+
*/
|
|
178
|
+
class _ExecutionResult {
|
|
179
|
+
invokeFn;
|
|
180
|
+
streamFn;
|
|
181
|
+
constructor(invokeFn, streamFn) {
|
|
182
|
+
this.invokeFn = invokeFn;
|
|
183
|
+
this.streamFn = streamFn;
|
|
184
|
+
}
|
|
185
|
+
// PromiseLike — `await execResult` resolves to the final AgentOutput.
|
|
186
|
+
then(onfulfilled, onrejected) {
|
|
187
|
+
return this.invokeFn().then(onfulfilled, onrejected);
|
|
188
|
+
}
|
|
189
|
+
// AsyncIterable — `for await (const e of execResult)` streams StreamEvents.
|
|
190
|
+
[Symbol.asyncIterator]() {
|
|
191
|
+
return this.streamFn()[Symbol.asyncIterator]();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// LangGraphBaseAgent
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
/** LangGraph adapter implementing the BaseAgent protocol. */
|
|
198
|
+
export class LangGraphBaseAgent {
|
|
199
|
+
graph;
|
|
200
|
+
callbacks;
|
|
201
|
+
prepareInput;
|
|
202
|
+
resolveThreadIdFn;
|
|
203
|
+
durableSubgraphs;
|
|
204
|
+
constructor(graph, callbacks, prepareInput, resolveThreadId) {
|
|
205
|
+
this.graph = graph;
|
|
206
|
+
installDurableMessageIdentity(this.graph);
|
|
207
|
+
const durableSubgraphs = new DurableSubgraphResolver(this.graph);
|
|
208
|
+
this.durableSubgraphs = durableSubgraphs.hasCompiledChildren
|
|
209
|
+
? durableSubgraphs
|
|
210
|
+
: null;
|
|
211
|
+
this.callbacks = callbacks ?? [];
|
|
212
|
+
this.prepareInput = prepareInput ?? null;
|
|
213
|
+
this.resolveThreadIdFn = resolveThreadId ?? null;
|
|
214
|
+
// The platform maps live updateState to a new session+thread, not LangGraph
|
|
215
|
+
// same-thread time-travel. See docs/session-fork.md.
|
|
216
|
+
wrapSessionForkUpdateState(this.graph, {
|
|
217
|
+
resolveThreadId: this.resolveThreadIdFn,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/** The wrapped compiled graph (Python `compiled_graph` parity). */
|
|
221
|
+
get compiledGraph() {
|
|
222
|
+
return this.graph;
|
|
223
|
+
}
|
|
224
|
+
/** The tenant thread-id hook, or null (Python `_resolve_thread_id` parity). */
|
|
225
|
+
get resolveThreadId() {
|
|
226
|
+
return this.resolveThreadIdFn;
|
|
227
|
+
}
|
|
228
|
+
execute(ctx, input) {
|
|
229
|
+
return new _ExecutionResult(() => this.invoke(ctx, input), () => this.stream(ctx, input));
|
|
230
|
+
}
|
|
231
|
+
session(ctx, input) {
|
|
232
|
+
return executionSession(this.graph, ctx, input, {
|
|
233
|
+
callbacks: this.callbacks,
|
|
234
|
+
prepareInput: this.prepareInput,
|
|
235
|
+
resolveThreadId: this.resolveThreadIdFn,
|
|
236
|
+
durableSubgraphs: this.durableSubgraphs,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
async invoke(ctx, input) {
|
|
240
|
+
const session = this.session(ctx, input);
|
|
241
|
+
try {
|
|
242
|
+
return await session.runInGraphScope(() => this.invokeGraph(session));
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
await session.close();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async invokeGraph(session) {
|
|
249
|
+
const { graphInput, config } = await session.prepareRun();
|
|
250
|
+
let nextInput = graphInput;
|
|
251
|
+
const graphAny = this.graph;
|
|
252
|
+
while (true) {
|
|
253
|
+
const result = (await graphAny.invoke(nextInput, config));
|
|
254
|
+
const messages = Array.isArray(result["messages"])
|
|
255
|
+
? result["messages"]
|
|
256
|
+
: [];
|
|
257
|
+
const response = findLastAiContent(messages);
|
|
258
|
+
const interrupt = await session.invokeInterrupt(config, response, messages);
|
|
259
|
+
if (interrupt instanceof Command) {
|
|
260
|
+
nextInput = interrupt;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (interrupt !== null)
|
|
264
|
+
return interrupt;
|
|
265
|
+
const metadata = await session.complete();
|
|
266
|
+
return {
|
|
267
|
+
response: {
|
|
268
|
+
response,
|
|
269
|
+
execution_id: session.threadId,
|
|
270
|
+
status: "completed",
|
|
271
|
+
message_count: messages.length,
|
|
272
|
+
resumed: session.resumed,
|
|
273
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async resume(ctx, input, decision) {
|
|
279
|
+
// Resume state lives on the context, not the caller payload.
|
|
280
|
+
const resumeCtx = {
|
|
281
|
+
...ctx,
|
|
282
|
+
resume: true,
|
|
283
|
+
resumeData: decision,
|
|
284
|
+
};
|
|
285
|
+
return this.invoke(resumeCtx, input);
|
|
286
|
+
}
|
|
287
|
+
// ------------------------------------------------------------------------
|
|
288
|
+
// Streaming
|
|
289
|
+
// ------------------------------------------------------------------------
|
|
290
|
+
async *processMessagesChunk(chunk, source, tasksById, pending) {
|
|
291
|
+
if (!(chunk instanceof AIMessageChunk))
|
|
292
|
+
return;
|
|
293
|
+
if (source === "") {
|
|
294
|
+
for (const call of iterTaskCalls([chunk])) {
|
|
295
|
+
if (call.subagentName === "")
|
|
296
|
+
continue;
|
|
297
|
+
for await (const ev of onTaskCall(call, tasksById, pending))
|
|
298
|
+
yield ev;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
onSourcedToken(source, tasksById, pending);
|
|
303
|
+
}
|
|
304
|
+
const token = normalizeContent(chunk.content);
|
|
305
|
+
if (token !== "") {
|
|
306
|
+
yield {
|
|
307
|
+
data: {
|
|
308
|
+
content: token,
|
|
309
|
+
source,
|
|
310
|
+
tool_call_id: tcIdForSource(source, tasksById),
|
|
311
|
+
},
|
|
312
|
+
event: "token",
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async *processAddMessagesUpdate(msgs, tasksById, pending, allMessages) {
|
|
317
|
+
const extracted = unwrapMessageValues(msgs);
|
|
318
|
+
allMessages.push(...extracted);
|
|
319
|
+
for (const call of iterTaskCalls(extracted)) {
|
|
320
|
+
if (call.subagentName === "")
|
|
321
|
+
continue;
|
|
322
|
+
for await (const ev of onTaskCall(call, tasksById, pending))
|
|
323
|
+
yield ev;
|
|
324
|
+
}
|
|
325
|
+
for (const msg of extracted) {
|
|
326
|
+
if (!(msg instanceof ToolMessage))
|
|
327
|
+
continue;
|
|
328
|
+
const tcId = msg.tool_call_id;
|
|
329
|
+
if (typeof tcId !== "string" || tcId === "")
|
|
330
|
+
continue;
|
|
331
|
+
const task = tasksById.get(tcId);
|
|
332
|
+
if (task === undefined)
|
|
333
|
+
continue;
|
|
334
|
+
tasksById.delete(tcId);
|
|
335
|
+
const summary = normalizeContent(msg.content ?? "");
|
|
336
|
+
yield endEvent(task, summary);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async *processCommandUpdate(cmd, tasksById, allMessages) {
|
|
340
|
+
const cmdAny = cmd;
|
|
341
|
+
const cmdUpdate = cmdAny.update;
|
|
342
|
+
if (cmdUpdate === null ||
|
|
343
|
+
typeof cmdUpdate !== "object" ||
|
|
344
|
+
Array.isArray(cmdUpdate))
|
|
345
|
+
return;
|
|
346
|
+
const cmdDict = cmdUpdate;
|
|
347
|
+
if (!("messages" in cmdDict))
|
|
348
|
+
return;
|
|
349
|
+
const extracted = unwrapMessageValues(cmdDict["messages"]);
|
|
350
|
+
allMessages.push(...extracted);
|
|
351
|
+
for (const msg of extracted) {
|
|
352
|
+
const tcId = msg.tool_call_id;
|
|
353
|
+
if (typeof tcId !== "string" || tcId === "")
|
|
354
|
+
continue;
|
|
355
|
+
const task = tasksById.get(tcId);
|
|
356
|
+
if (task === undefined)
|
|
357
|
+
continue;
|
|
358
|
+
tasksById.delete(tcId);
|
|
359
|
+
const summary = normalizeContent(msg.content ?? "");
|
|
360
|
+
yield endEvent(task, summary);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async *stream(ctx, input) {
|
|
364
|
+
const session = this.session(ctx, input);
|
|
365
|
+
try {
|
|
366
|
+
yield* session.iterateInGraphScope(this.streamGraph(session));
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
await session.close();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async *streamGraph(session) {
|
|
373
|
+
const { graphInput, config } = await session.prepareRun();
|
|
374
|
+
let nextInput = graphInput;
|
|
375
|
+
const allMessages = [];
|
|
376
|
+
const tasksById = new Map();
|
|
377
|
+
const pending = new Map();
|
|
378
|
+
const graphAny = this.graph;
|
|
379
|
+
while (true) {
|
|
380
|
+
const capturedInterrupts = [];
|
|
381
|
+
const capturedInterruptValues = new Map();
|
|
382
|
+
let streamError;
|
|
383
|
+
try {
|
|
384
|
+
const streamOpts = {
|
|
385
|
+
...config,
|
|
386
|
+
streamMode: ["messages", "updates"],
|
|
387
|
+
subgraphs: true,
|
|
388
|
+
};
|
|
389
|
+
for await (const event of await graphAny.stream(nextInput, streamOpts)) {
|
|
390
|
+
// LangGraph.js emits `[namespace, streamMode, payload]` when subgraphs=true.
|
|
391
|
+
if (!Array.isArray(event) || event.length < 3)
|
|
392
|
+
continue;
|
|
393
|
+
const namespace = Array.isArray(event[0])
|
|
394
|
+
? event[0]
|
|
395
|
+
: [];
|
|
396
|
+
const streamMode = event[1];
|
|
397
|
+
const eventPayload = event[2];
|
|
398
|
+
if (streamMode === "messages") {
|
|
399
|
+
const tuple = Array.isArray(eventPayload)
|
|
400
|
+
? eventPayload
|
|
401
|
+
: [eventPayload];
|
|
402
|
+
const chunk = tuple[0];
|
|
403
|
+
const source = sourceFromNamespace(namespace);
|
|
404
|
+
for await (const ev of this.processMessagesChunk(chunk, source, tasksById, pending)) {
|
|
405
|
+
yield ev;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
else if (streamMode === "updates") {
|
|
409
|
+
if (eventPayload === null ||
|
|
410
|
+
typeof eventPayload !== "object" ||
|
|
411
|
+
Array.isArray(eventPayload)) {
|
|
412
|
+
logger.warn(`Unexpected non-dict updates payload: ${typeof eventPayload}`);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const updateDict = eventPayload;
|
|
416
|
+
const interrupts = updateDict["__interrupt__"];
|
|
417
|
+
if (Array.isArray(interrupts)) {
|
|
418
|
+
// A nested subgraph's interrupt projects onto its parent, so the
|
|
419
|
+
// same native id legitimately streams twice (child + root) with
|
|
420
|
+
// an identical value. Keep one copy. A repeated id with a
|
|
421
|
+
// different value stays in the list for interruptSnapshot to
|
|
422
|
+
// reject as conflicting framework state.
|
|
423
|
+
for (const interrupt of interrupts) {
|
|
424
|
+
const id = interrupt.id;
|
|
425
|
+
if (typeof id === "string") {
|
|
426
|
+
const previous = capturedInterruptValues.get(id);
|
|
427
|
+
const value = interrupt.value;
|
|
428
|
+
if (previous !== undefined &&
|
|
429
|
+
isDeepStrictEqual(previous, value)) {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
capturedInterruptValues.set(id, value);
|
|
433
|
+
}
|
|
434
|
+
capturedInterrupts.push(interrupt);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
for (const nodeOutput of Object.values(updateDict)) {
|
|
438
|
+
// `Command` IS an object, so it must be checked BEFORE the generic
|
|
439
|
+
// object branch below — otherwise Command instances fall into the
|
|
440
|
+
// `'messages' in node` check (which is false for Command, whose
|
|
441
|
+
// payload lives under `.update`) and their messages are silently
|
|
442
|
+
// dropped. See tests/agent.test.ts (Command.update coverage).
|
|
443
|
+
if (nodeOutput instanceof Command) {
|
|
444
|
+
for await (const ev of this.processCommandUpdate(nodeOutput, tasksById, allMessages)) {
|
|
445
|
+
yield ev;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (nodeOutput !== null &&
|
|
449
|
+
typeof nodeOutput === "object" &&
|
|
450
|
+
!Array.isArray(nodeOutput)) {
|
|
451
|
+
const node = nodeOutput;
|
|
452
|
+
if ("messages" in node) {
|
|
453
|
+
for await (const ev of this.processAddMessagesUpdate(node["messages"], tasksById, pending, allMessages)) {
|
|
454
|
+
yield ev;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
catch (exc) {
|
|
463
|
+
streamError = exc;
|
|
464
|
+
}
|
|
465
|
+
if (streamError !== undefined) {
|
|
466
|
+
// Mirror Python's `except (GeneratorExit, asyncio.CancelledError): raise`:
|
|
467
|
+
// skip the drain on cancellation so we don't try to yield while the
|
|
468
|
+
// surrounding task is being torn down.
|
|
469
|
+
if (!isCancellationError(streamError)) {
|
|
470
|
+
for await (const ev of drainOpenTasks(tasksById, pending))
|
|
471
|
+
yield ev;
|
|
472
|
+
}
|
|
473
|
+
throw streamError;
|
|
474
|
+
}
|
|
475
|
+
const interrupt = await session.streamInterrupt(config, capturedInterrupts, allMessages);
|
|
476
|
+
if (interrupt instanceof Command) {
|
|
477
|
+
nextInput = interrupt;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (interrupt !== null) {
|
|
481
|
+
yield interrupt;
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
for await (const ev of drainOpenTasks(tasksById, pending))
|
|
487
|
+
yield ev;
|
|
488
|
+
if (allMessages.length === 0) {
|
|
489
|
+
throw new Error("Graph completed without producing messages");
|
|
490
|
+
}
|
|
491
|
+
const response = findLastAiContent(allMessages);
|
|
492
|
+
const metadata = await session.complete();
|
|
493
|
+
yield {
|
|
494
|
+
data: {
|
|
495
|
+
response,
|
|
496
|
+
// Convert to platform Messages ({role, content, ...}) so the runner-shared
|
|
497
|
+
// AER path receives the expected shape — matches Python's
|
|
498
|
+
// `lc_messages_to_platform(...)` before emitting the result (agent.py).
|
|
499
|
+
messages: lcMessagesToPlatform(allMessages),
|
|
500
|
+
message_count: allMessages.length,
|
|
501
|
+
resumed: session.resumed,
|
|
502
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
503
|
+
},
|
|
504
|
+
event: "result",
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,SAAS,EACT,cAAc,EACd,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,OAAO,EAAkB,MAAM,sBAAsB,CAAC;AAE/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CAAC;QAE1C,MAAM;YACJ,IAAI,EAAE;gBACJ,QAAQ;gBACR,2EAA2E;gBAC3E,0DAA0D;gBAC1D,wEAAwE;gBACxE,QAAQ,EAAE,oBAAoB,CAAC,WAAW,CAAU;gBACpD,aAAa,EAAE,WAAW,CAAC,MAAM;gBACjC,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;aAChD;YACD,KAAK,EAAE,QAAQ;SAChB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentEngineToolSandboxBackend — canonical name for AgentEngineToolPodBackend.
|
|
3
|
+
*
|
|
4
|
+
* This module exists so agent authors can use the stable sandbox terminology
|
|
5
|
+
* without depending on the legacy AER/ToolPod names. The implementation is
|
|
6
|
+
* identical; both names refer to the same class.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // The package `exports` map only exposes the root, so import from there.
|
|
11
|
+
* import { AgentEngineToolSandboxBackend } from "@mongodb-js/agent-engine-sdk-langgraph";
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { AgentEngineToolPodBackend as AgentEngineToolSandboxBackend } from "./toolpod.js";
|
|
15
|
+
//# sourceMappingURL=tool_sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_sandbox.d.ts","sourceRoot":"","sources":["../../src/backends/tool_sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,yBAAyB,IAAI,6BAA6B,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentEngineToolSandboxBackend — canonical name for AgentEngineToolPodBackend.
|
|
3
|
+
*
|
|
4
|
+
* This module exists so agent authors can use the stable sandbox terminology
|
|
5
|
+
* without depending on the legacy AER/ToolPod names. The implementation is
|
|
6
|
+
* identical; both names refer to the same class.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // The package `exports` map only exposes the root, so import from there.
|
|
11
|
+
* import { AgentEngineToolSandboxBackend } from "@mongodb-js/agent-engine-sdk-langgraph";
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { AgentEngineToolPodBackend as AgentEngineToolSandboxBackend } from "./toolpod.js";
|
|
15
|
+
//# sourceMappingURL=tool_sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_sandbox.js","sourceRoot":"","sources":["../../src/backends/tool_sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,yBAAyB,IAAI,6BAA6B,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentEngineToolPodBackend — routes deep-agent filesystem/shell ops through the
|
|
3
|
+
* secure path (SecureToolWrapper → Orchestration Engine → Tool Pod handlers).
|
|
4
|
+
*
|
|
5
|
+
* Port of Python `agent_engine_sdk_langgraph/backends/toolpod.py`, targeting
|
|
6
|
+
* deepagents' current V2 backend protocol (`SandboxBackendProtocolV2`): every
|
|
7
|
+
* method returns a structured Result object with an optional `error`, so a
|
|
8
|
+
* failure is surfaced through the same channel as success — never thrown into
|
|
9
|
+
* the graph and never leaking internal topology.
|
|
10
|
+
*
|
|
11
|
+
* The active `SecureToolWrapper` is read from the async-context store on every
|
|
12
|
+
* call (not captured at construction): LangGraph builds the backend on one task
|
|
13
|
+
* and invokes it on another, so a captured reference would be stale.
|
|
14
|
+
*
|
|
15
|
+
* Batch downloads (`downloadFiles`) fan out concurrently in native mode, with
|
|
16
|
+
* one `filesystem_download` call per file so OE policy and audit stay
|
|
17
|
+
* independent. Under a durable `AttemptContext` they stay sequential: unkeyed
|
|
18
|
+
* activities are exclusive on the attempt gate, and overlapping them raises
|
|
19
|
+
* CONFLICT.
|
|
20
|
+
*/
|
|
21
|
+
import type { EditResult, ExecuteResponse, FileDownloadResponse, FileUploadResponse, GlobResult, GrepResult, LsResult, ReadRawResult, ReadResult, SandboxBackendProtocolV2, WriteResult } from "deepagents";
|
|
22
|
+
/**
|
|
23
|
+
* Backend that routes every operation through Atlas Agent Engine's secure path. Each
|
|
24
|
+
* method delegates to `SecureToolWrapper.executeTool`, which sends the request
|
|
25
|
+
* to the OE for policy approval and audit logging before it runs in the Tool
|
|
26
|
+
* Pod.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AgentEngineToolPodBackend implements SandboxBackendProtocolV2 {
|
|
29
|
+
readonly id = "agent-engine-toolpod";
|
|
30
|
+
/**
|
|
31
|
+
* Execute a Tool Pod handler through the secure wrapper. Returns the wire
|
|
32
|
+
* result on success, or a classified `[RETRYABLE]`/`[NON-RETRYABLE]` error
|
|
33
|
+
* string on failure (exceptions are logged and translated, never rethrown).
|
|
34
|
+
*/
|
|
35
|
+
private call;
|
|
36
|
+
ls(path: string): Promise<LsResult>;
|
|
37
|
+
read(filePath: string, offset?: number, limit?: number): Promise<ReadResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Raw read is not backed by a dedicated wire handler; the Tool Pod exposes
|
|
40
|
+
* only line-oriented `filesystem_read`. We wrap its text content in a v2
|
|
41
|
+
* FileData so binary-unaware callers still work. Genuine binary reads should
|
|
42
|
+
* use `downloadFiles`, which carries raw bytes base64-encoded.
|
|
43
|
+
*/
|
|
44
|
+
readRaw(filePath: string): Promise<ReadRawResult>;
|
|
45
|
+
grep(pattern: string, path?: string | null, glob?: string | null): Promise<GrepResult>;
|
|
46
|
+
glob(pattern: string, path?: string): Promise<GlobResult>;
|
|
47
|
+
write(filePath: string, content: string): Promise<WriteResult>;
|
|
48
|
+
edit(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
49
|
+
execute(command: string): Promise<ExecuteResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Download a single path. Never throws: failures become error responses.
|
|
52
|
+
*/
|
|
53
|
+
private downloadOne;
|
|
54
|
+
/**
|
|
55
|
+
* Download files via the audited `filesystem_download` handler — one call per
|
|
56
|
+
* path so each is policy-checked and logged independently — then base64-decode
|
|
57
|
+
* the `content_base64` field into raw bytes. Responses preserve input order;
|
|
58
|
+
* on failure `content` is null and `error` carries a classified message.
|
|
59
|
+
*
|
|
60
|
+
* Native-mode batches fan out on a bounded worker pool so skills loading
|
|
61
|
+
* pays one round-trip of latency instead of a sum. Durable attempts stay
|
|
62
|
+
* sequential: unkeyed activities are exclusive under the attempt gate, and
|
|
63
|
+
* overlapping them raises CONFLICT.
|
|
64
|
+
*/
|
|
65
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
66
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=toolpod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolpod.d.ts","sourceRoot":"","sources":["../../src/backends/toolpod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAEf,oBAAoB,EAEpB,kBAAkB,EAClB,UAAU,EAEV,UAAU,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,WAAW,EACZ,MAAM,YAAY,CAAC;AA8HpB;;;;;GAKG;AACH,qBAAa,yBAA0B,YAAW,wBAAwB;IACxE,QAAQ,CAAC,EAAE,0BAA0B;IAErC;;;;OAIG;YACW,IAAI;IAyBZ,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgBnC,IAAI,CAAC,QAAQ,EAAE,MAAM,E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