@superdurable/dex-agents 0.0.0-stage → 0.1.0
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/LICENSE +105 -0
- package/README.md +475 -2
- package/dist/src/agent-event-writer.d.ts +26 -0
- package/dist/src/agent-event-writer.js +110 -0
- package/dist/src/agent-event-writer.js.map +1 -0
- package/dist/src/agent-framework-runner.d.ts +368 -0
- package/dist/src/agent-framework-runner.js +81 -0
- package/dist/src/agent-framework-runner.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +44 -0
- package/dist/src/agent-session-codecs.js +355 -0
- package/dist/src/agent-session-codecs.js.map +1 -0
- package/dist/src/agent-session-flow.d.ts +148 -0
- package/dist/src/agent-session-flow.js +276 -0
- package/dist/src/agent-session-flow.js.map +1 -0
- package/dist/src/agent-session-persistence.d.ts +56 -0
- package/dist/src/agent-session-persistence.js +43 -0
- package/dist/src/agent-session-persistence.js.map +1 -0
- package/dist/src/agent-session-steps.d.ts +86 -0
- package/dist/src/agent-session-steps.js +533 -0
- package/dist/src/agent-session-steps.js.map +1 -0
- package/dist/src/agent-session-transitions.d.ts +61 -0
- package/dist/src/agent-session-transitions.js +202 -0
- package/dist/src/agent-session-transitions.js.map +1 -0
- package/dist/src/agent-session-values.d.ts +337 -0
- package/dist/src/agent-session-values.js +127 -0
- package/dist/src/agent-session-values.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/testing/agent-session-test-client.d.ts +148 -0
- package/dist/src/testing/agent-session-test-client.js +217 -0
- package/dist/src/testing/agent-session-test-client.js.map +1 -0
- package/dist/src/testing/agent-test-environment.d.ts +52 -0
- package/dist/src/testing/agent-test-environment.js +86 -0
- package/dist/src/testing/agent-test-environment.js.map +1 -0
- package/dist/src/testing/agent-worker-process.d.ts +91 -0
- package/dist/src/testing/agent-worker-process.js +150 -0
- package/dist/src/testing/agent-worker-process.js.map +1 -0
- package/dist/src/testing/child-process-group.d.ts +33 -0
- package/dist/src/testing/child-process-group.js +164 -0
- package/dist/src/testing/child-process-group.js.map +1 -0
- package/dist/src/testing/coordination.d.ts +99 -0
- package/dist/src/testing/coordination.js +155 -0
- package/dist/src/testing/coordination.js.map +1 -0
- package/dist/src/testing/index.d.ts +7 -0
- package/dist/src/testing/index.js +15 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/polling.d.ts +31 -0
- package/dist/src/testing/polling.js +51 -0
- package/dist/src/testing/polling.js.map +1 -0
- package/dist/src/testing/private-dex-engine.d.ts +92 -0
- package/dist/src/testing/private-dex-engine.js +215 -0
- package/dist/src/testing/private-dex-engine.js.map +1 -0
- package/dist/src/testing/step-history.d.ts +40 -0
- package/dist/src/testing/step-history.js +59 -0
- package/dist/src/testing/step-history.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
import { ExecuteFailure, StepMovement, int64Codec, StepRef, Timer, Wait, deadEnd, goTo, goToMany, stringCodec, voidCodec, } from "@superdurable/dex";
|
|
9
|
+
import { ToolExecutionError, } from "./agent-framework-runner.js";
|
|
10
|
+
import { agentSessionStartInputCodec } from "./agent-session-codecs.js";
|
|
11
|
+
import { agentSessionStepTypes, readRecoveryDetail, toolStepTypeForEffect, } from "./agent-session-transitions.js";
|
|
12
|
+
import { approvalDeadlinePassed, buildTurnFailureNote, emptyAgentUsage, isFinalToolCallStatus, } from "./agent-session-values.js";
|
|
13
|
+
const minuteMs = 60_000;
|
|
14
|
+
// Recovery Steps must eventually run; cap their backoff so a returning Worker picks them up quickly.
|
|
15
|
+
const recoveryRetry = { maximumIntervalMs: 5_000 };
|
|
16
|
+
// An ASYNC FlowConfig could replay a committed result after a Server failover, re-running a write.
|
|
17
|
+
const syncDurability = { waitForDurability: "sync", executeDurability: "sync" };
|
|
18
|
+
// An int64 Value, as the Python core's Step[int] encodes it.
|
|
19
|
+
const expectedResultCountCodec = {
|
|
20
|
+
typeName: "ExpectedResultCount",
|
|
21
|
+
wireKind: "int64",
|
|
22
|
+
encode: (value) => int64Codec.encode(BigInt(requirePositiveResultCount(value))),
|
|
23
|
+
decode: (value) => requirePositiveResultCount(Number(int64Codec.decode(value))),
|
|
24
|
+
};
|
|
25
|
+
export class StartAgentSessionStep {
|
|
26
|
+
transitions;
|
|
27
|
+
inputCodec = agentSessionStartInputCodec;
|
|
28
|
+
constructor(transitions) {
|
|
29
|
+
this.transitions = transitions;
|
|
30
|
+
}
|
|
31
|
+
getStepType() {
|
|
32
|
+
return agentSessionStepTypes.startAgentSession;
|
|
33
|
+
}
|
|
34
|
+
getStepOptions() {
|
|
35
|
+
return syncDurability;
|
|
36
|
+
}
|
|
37
|
+
execute(context, input) {
|
|
38
|
+
const persistence = this.transitions.persistence;
|
|
39
|
+
const state = {
|
|
40
|
+
status: "waiting_for_user_message",
|
|
41
|
+
turnCount: 0,
|
|
42
|
+
activeTurnId: null,
|
|
43
|
+
nextMessageSequence: 1,
|
|
44
|
+
lastTurnError: null,
|
|
45
|
+
};
|
|
46
|
+
this.transitions.writeAgentState(context, state);
|
|
47
|
+
persistence.agentUsage.set(context, emptyAgentUsage());
|
|
48
|
+
persistence.pendingInterrupts.set(context, []);
|
|
49
|
+
const initialMessage = input.initialMessage;
|
|
50
|
+
if (initialMessage === null || initialMessage.trim() === "") {
|
|
51
|
+
return this.transitions.goToAwaitUserMessage();
|
|
52
|
+
}
|
|
53
|
+
return this.transitions.beginTurn(context, state, initialMessage);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class AwaitUserMessageStep {
|
|
57
|
+
transitions;
|
|
58
|
+
inputCodec = voidCodec;
|
|
59
|
+
constructor(transitions) {
|
|
60
|
+
this.transitions = transitions;
|
|
61
|
+
}
|
|
62
|
+
getStepType() {
|
|
63
|
+
return agentSessionStepTypes.awaitUserMessage;
|
|
64
|
+
}
|
|
65
|
+
getStepOptions() {
|
|
66
|
+
return syncDurability;
|
|
67
|
+
}
|
|
68
|
+
waitFor() {
|
|
69
|
+
return Wait.until(this.transitions.persistence.queuedUserMessages.forOne());
|
|
70
|
+
}
|
|
71
|
+
execute(context) {
|
|
72
|
+
const [message] = context.channelResults(this.transitions.persistence.queuedUserMessages);
|
|
73
|
+
if (message === undefined || message.text.trim() === "") {
|
|
74
|
+
return this.transitions.goToAwaitUserMessage();
|
|
75
|
+
}
|
|
76
|
+
return this.transitions.beginTurn(context, this.transitions.readAgentState(context), message.text);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Makes the turn's next model call and fans the requested tool calls out to parallel Steps. */
|
|
80
|
+
export class RunModelStep {
|
|
81
|
+
transitions;
|
|
82
|
+
inputCodec = voidCodec;
|
|
83
|
+
constructor(transitions) {
|
|
84
|
+
this.transitions = transitions;
|
|
85
|
+
}
|
|
86
|
+
getStepType() {
|
|
87
|
+
return agentSessionStepTypes.runModel;
|
|
88
|
+
}
|
|
89
|
+
getStepOptions() {
|
|
90
|
+
const persistence = this.transitions.persistence;
|
|
91
|
+
return {
|
|
92
|
+
...syncDurability,
|
|
93
|
+
executeMethodTimeoutMs: 15 * minuteMs,
|
|
94
|
+
heartbeatTimeoutMs: 2 * minuteMs,
|
|
95
|
+
executeRetry: { maximumAttempts: 3, totalDurationMs: 30 * minuteMs },
|
|
96
|
+
executeFailure: ExecuteFailure.proceedTo(new StepRef(agentSessionStepTypes.recordTurnFailure)),
|
|
97
|
+
executeLoadAttributeMaps: [persistence.agentMessages, persistence.agentToolCalls],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async execute(context) {
|
|
101
|
+
const transitions = this.transitions;
|
|
102
|
+
const state = transitions.readAgentState(context);
|
|
103
|
+
const turnId = state.activeTurnId;
|
|
104
|
+
if (turnId === null) {
|
|
105
|
+
throw new Error(`the agent session ${context.flowId} has no active turn`);
|
|
106
|
+
}
|
|
107
|
+
const toolCalls = transitions.readTurnToolCalls(context, turnId);
|
|
108
|
+
const openToolCall = toolCalls.find((toolCall) => !isFinalToolCallStatus(toolCall.status));
|
|
109
|
+
if (openToolCall !== undefined) {
|
|
110
|
+
throw new Error(`RunModel for ${turnId} started before tool call ${openToolCall.toolCallId} finished`);
|
|
111
|
+
}
|
|
112
|
+
const toolCallsById = new Map(toolCalls.map((toolCall) => [toolCall.toolCallId, toolCall]));
|
|
113
|
+
const frameworkRunState = transitions.readFrameworkRunState(context);
|
|
114
|
+
const events = transitions.createEventWriter(context, turnId);
|
|
115
|
+
try {
|
|
116
|
+
const turnContext = {
|
|
117
|
+
flowId: context.flowId,
|
|
118
|
+
turnId,
|
|
119
|
+
attempt: context.attempt,
|
|
120
|
+
messages: transitions.readMessages(context, 1, state.nextMessageSequence),
|
|
121
|
+
frameworkRunState,
|
|
122
|
+
isResuming: frameworkRunState !== null,
|
|
123
|
+
toolCalls,
|
|
124
|
+
events,
|
|
125
|
+
cancellationSignal: context.cancellationSignal,
|
|
126
|
+
deadline: context.deadline,
|
|
127
|
+
resolveToolPolicy: (toolName, frameworkEffect) => transitions.resolveToolPolicy(toolName, frameworkEffect),
|
|
128
|
+
recordedToolCall: (toolCallId) => toolCallsById.get(toolCallId),
|
|
129
|
+
heartbeat: () => transitions.recordHeartbeat(context),
|
|
130
|
+
};
|
|
131
|
+
const outcome = await transitions.runWithHeartbeats(context, () => transitions.runner.runModelStep(turnContext));
|
|
132
|
+
switch (outcome?.kind) {
|
|
133
|
+
case "completed":
|
|
134
|
+
return this.completeTurn(context, state, turnId, toolCalls, outcome, events);
|
|
135
|
+
case "tool_calls_requested":
|
|
136
|
+
return this.requestToolCalls(context, state, turnId, toolCalls, outcome, events);
|
|
137
|
+
default:
|
|
138
|
+
throw new TypeError("runModelStep must return a TurnCompleted or ToolCallsRequested outcome");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
events.close();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
completeTurn(context, state, turnId, toolCalls, outcome, events) {
|
|
146
|
+
const transitions = this.transitions;
|
|
147
|
+
const persistence = transitions.persistence;
|
|
148
|
+
const stateWithMessages = transitions.appendMessages(context, state, turnId, outcome.newMessages);
|
|
149
|
+
for (const toolCall of toolCalls) {
|
|
150
|
+
persistence.agentToolCalls.delete(context, toolCall.toolCallId);
|
|
151
|
+
}
|
|
152
|
+
persistence.frameworkRunState.delete(context);
|
|
153
|
+
transitions.recordUsage(context, outcome.usage, events);
|
|
154
|
+
transitions.writeAgentState(context, {
|
|
155
|
+
...stateWithMessages,
|
|
156
|
+
status: "waiting_for_user_message",
|
|
157
|
+
turnCount: state.turnCount + 1,
|
|
158
|
+
activeTurnId: null,
|
|
159
|
+
lastTurnError: null,
|
|
160
|
+
});
|
|
161
|
+
events.writeEvent("turn_completed", { message_count: outcome.newMessages.length });
|
|
162
|
+
return transitions.goToAwaitUserMessage();
|
|
163
|
+
}
|
|
164
|
+
requestToolCalls(context, state, turnId, toolCalls, outcome, events) {
|
|
165
|
+
validateToolCallsRequested(turnId, toolCalls, outcome);
|
|
166
|
+
const transitions = this.transitions;
|
|
167
|
+
transitions.persistence.frameworkRunState.set(context, outcome.frameworkRunState);
|
|
168
|
+
const createdAt = new Date();
|
|
169
|
+
const deadline = transitions.config.interruptDeadlineMs === undefined
|
|
170
|
+
? null
|
|
171
|
+
: new Date(createdAt.getTime() + transitions.config.interruptDeadlineMs).toISOString();
|
|
172
|
+
const interrupts = [];
|
|
173
|
+
// goToMany takes movements of mixed input types, which the SDK types as StepMovement<any>.
|
|
174
|
+
const movements = [];
|
|
175
|
+
for (const [index, requestedToolCall] of outcome.toolCalls.entries()) {
|
|
176
|
+
const requiresApproval = requestedToolCall.policy.requiresApproval;
|
|
177
|
+
const effect = requestedToolCall.policy.effect;
|
|
178
|
+
transitions.writeToolCall(context, {
|
|
179
|
+
toolCallId: requestedToolCall.toolCallId,
|
|
180
|
+
turnId,
|
|
181
|
+
toolName: requestedToolCall.toolName,
|
|
182
|
+
arguments: requestedToolCall.arguments,
|
|
183
|
+
effect,
|
|
184
|
+
requiresApproval,
|
|
185
|
+
status: requiresApproval ? "awaiting_approval" : "approved",
|
|
186
|
+
output: null,
|
|
187
|
+
error: null,
|
|
188
|
+
rejectionMessage: null,
|
|
189
|
+
deferralOrder: toolCalls.length + index,
|
|
190
|
+
});
|
|
191
|
+
events.writeEvent("tool_call_deferred", {
|
|
192
|
+
tool_call_id: requestedToolCall.toolCallId,
|
|
193
|
+
tool_name: requestedToolCall.toolName,
|
|
194
|
+
effect,
|
|
195
|
+
requires_approval: requiresApproval,
|
|
196
|
+
});
|
|
197
|
+
const nextStepType = requiresApproval
|
|
198
|
+
? agentSessionStepTypes.awaitToolApproval
|
|
199
|
+
: toolStepTypeForEffect(effect);
|
|
200
|
+
movements.push(toolStepMovement(transitions.persistence, nextStepType, requestedToolCall.toolCallId));
|
|
201
|
+
if (!requiresApproval) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const interrupt = {
|
|
205
|
+
interruptId: requestedToolCall.toolCallId,
|
|
206
|
+
kind: "tool_approval",
|
|
207
|
+
toolCallId: requestedToolCall.toolCallId,
|
|
208
|
+
toolName: requestedToolCall.toolName,
|
|
209
|
+
arguments: requestedToolCall.arguments,
|
|
210
|
+
createdAt: createdAt.toISOString(),
|
|
211
|
+
deadline,
|
|
212
|
+
};
|
|
213
|
+
interrupts.push(interrupt);
|
|
214
|
+
events.writeEvent("interrupt_raised", {
|
|
215
|
+
interrupt_id: interrupt.interruptId,
|
|
216
|
+
tool_call_id: interrupt.toolCallId,
|
|
217
|
+
tool_name: interrupt.toolName,
|
|
218
|
+
deadline: interrupt.deadline,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
transitions.persistence.pendingInterrupts.set(context, interrupts);
|
|
222
|
+
transitions.recordUsage(context, outcome.usage, events);
|
|
223
|
+
transitions.writeAgentState(context, { ...state, status: "running_tools" });
|
|
224
|
+
movements.push(StepMovement.of(new StepRef(agentSessionStepTypes.resumeTurn), outcome.toolCalls.length));
|
|
225
|
+
return goToMany(...movements);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Waits for one tool call's approval or its deadline, then runs or rejects the call. */
|
|
229
|
+
export class AwaitToolApprovalStep {
|
|
230
|
+
transitions;
|
|
231
|
+
inputCodec = stringCodec;
|
|
232
|
+
constructor(transitions) {
|
|
233
|
+
this.transitions = transitions;
|
|
234
|
+
}
|
|
235
|
+
getStepType() {
|
|
236
|
+
return agentSessionStepTypes.awaitToolApproval;
|
|
237
|
+
}
|
|
238
|
+
getStepOptions() {
|
|
239
|
+
return toolStepOptions(this.transitions.persistence, agentSessionStepTypes.awaitToolApproval);
|
|
240
|
+
}
|
|
241
|
+
waitFor(context, toolCallId) {
|
|
242
|
+
const transitions = this.transitions;
|
|
243
|
+
const conditions = [transitions.persistence.interruptResolutions.forOne(toolCallId)];
|
|
244
|
+
// A resolved interrupt left PendingInterrupts, so its deadline no longer applies.
|
|
245
|
+
const interrupt = transitions
|
|
246
|
+
.readPendingInterrupts(context)
|
|
247
|
+
.find((pendingInterrupt) => pendingInterrupt.interruptId === toolCallId);
|
|
248
|
+
if (interrupt?.deadline != null) {
|
|
249
|
+
// Dex Timers take whole seconds; rounding up can only fire late, never early.
|
|
250
|
+
const remainingMs = Math.max(0, Date.parse(interrupt.deadline) - Date.now());
|
|
251
|
+
conditions.push(Timer.byDuration(Math.ceil(remainingMs / 1_000) * 1_000));
|
|
252
|
+
}
|
|
253
|
+
return Wait.anyOf(...conditions);
|
|
254
|
+
}
|
|
255
|
+
execute(context, toolCallId) {
|
|
256
|
+
const transitions = this.transitions;
|
|
257
|
+
const persistence = transitions.persistence;
|
|
258
|
+
const toolCall = transitions.readToolCall(context, toolCallId);
|
|
259
|
+
if (toolCall.status !== "awaiting_approval") {
|
|
260
|
+
return deadEnd();
|
|
261
|
+
}
|
|
262
|
+
const [resolution] = context.channelResults(persistence.interruptResolutions, toolCallId);
|
|
263
|
+
if (resolution === undefined) {
|
|
264
|
+
if (!context.hasTimerFired()) {
|
|
265
|
+
throw new Error(`the approval wait for ${toolCallId} completed without an answer`);
|
|
266
|
+
}
|
|
267
|
+
const pendingInterrupts = transitions.readPendingInterrupts(context);
|
|
268
|
+
const interrupt = pendingInterrupts.find((pending) => pending.interruptId === toolCallId);
|
|
269
|
+
// resolve_interrupt answered first, or the Timer fired early; wait again.
|
|
270
|
+
if (interrupt?.deadline == null || Date.parse(interrupt.deadline) > Date.now()) {
|
|
271
|
+
return goToMany(toolStepMovement(persistence, agentSessionStepTypes.awaitToolApproval, toolCallId));
|
|
272
|
+
}
|
|
273
|
+
persistence.pendingInterrupts.set(context, pendingInterrupts.filter((interrupt) => interrupt.interruptId !== toolCallId));
|
|
274
|
+
return this.rejectToolCall(context, toolCall, approvalDeadlinePassed);
|
|
275
|
+
}
|
|
276
|
+
if (!resolution.approved) {
|
|
277
|
+
return this.rejectToolCall(context, toolCall, resolution.rejectionMessage);
|
|
278
|
+
}
|
|
279
|
+
transitions.writeToolCall(context, { ...toolCall, status: "approved" });
|
|
280
|
+
this.writeInterruptResolved(context, toolCall, true, null);
|
|
281
|
+
return goToMany(toolStepMovement(persistence, toolStepTypeForEffect(toolCall.effect), toolCallId));
|
|
282
|
+
}
|
|
283
|
+
rejectToolCall(context, toolCall, rejectionMessage) {
|
|
284
|
+
this.transitions.writeToolCall(context, { ...toolCall, status: "rejected", rejectionMessage });
|
|
285
|
+
this.writeInterruptResolved(context, toolCall, false, rejectionMessage);
|
|
286
|
+
this.transitions.writeEvents(context, toolCall.turnId, (events) => events.writeToolCallFinished(toolCall.toolCallId, toolCall.toolName, "rejected"));
|
|
287
|
+
this.transitions.publishToolCallResult(context, toolCall.toolCallId);
|
|
288
|
+
return deadEnd();
|
|
289
|
+
}
|
|
290
|
+
writeInterruptResolved(context, toolCall, isApproved, rejectionMessage) {
|
|
291
|
+
this.transitions.writeEvents(context, toolCall.turnId, (events) => events.writeEvent("interrupt_resolved", {
|
|
292
|
+
interrupt_id: toolCall.toolCallId,
|
|
293
|
+
approved: isApproved,
|
|
294
|
+
rejection_message: rejectionMessage,
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/** Runs one tool call; one class serves `CallTool` and `CallSingleAttemptTool`. */
|
|
299
|
+
export class ToolCallStep {
|
|
300
|
+
transitions;
|
|
301
|
+
stepType;
|
|
302
|
+
inputCodec = stringCodec;
|
|
303
|
+
constructor(transitions, stepType) {
|
|
304
|
+
this.transitions = transitions;
|
|
305
|
+
this.stepType = stepType;
|
|
306
|
+
}
|
|
307
|
+
getStepType() {
|
|
308
|
+
return this.stepType;
|
|
309
|
+
}
|
|
310
|
+
getStepOptions() {
|
|
311
|
+
return toolStepOptions(this.transitions.persistence, this.stepType);
|
|
312
|
+
}
|
|
313
|
+
async execute(context, toolCallId) {
|
|
314
|
+
const transitions = this.transitions;
|
|
315
|
+
const toolCall = transitions.readToolCall(context, toolCallId);
|
|
316
|
+
if (isFinalToolCallStatus(toolCall.status)) {
|
|
317
|
+
return deadEnd();
|
|
318
|
+
}
|
|
319
|
+
if (toolCall.status !== "approved" || toolStepTypeForEffect(toolCall.effect) !== this.stepType) {
|
|
320
|
+
throw new Error(`tool call ${toolCallId} cannot run in ${this.stepType}`);
|
|
321
|
+
}
|
|
322
|
+
const events = transitions.createEventWriter(context, toolCall.turnId);
|
|
323
|
+
try {
|
|
324
|
+
events.writeToolCallStarted(toolCall.toolCallId, toolCall.toolName);
|
|
325
|
+
// Dex re-delivers an attempt whose Worker vanished before any output, so emit output first.
|
|
326
|
+
await transitions.recordHeartbeat(context);
|
|
327
|
+
const execution = {
|
|
328
|
+
flowId: context.flowId,
|
|
329
|
+
toolCall,
|
|
330
|
+
idempotencyKey: `${context.flowId}/${toolCall.turnId}/${toolCall.toolCallId}`,
|
|
331
|
+
attempt: context.attempt,
|
|
332
|
+
events,
|
|
333
|
+
cancellationSignal: context.cancellationSignal,
|
|
334
|
+
deadline: context.deadline,
|
|
335
|
+
heartbeat: () => transitions.recordHeartbeat(context),
|
|
336
|
+
};
|
|
337
|
+
let finishedToolCall;
|
|
338
|
+
try {
|
|
339
|
+
const result = await transitions.runWithHeartbeats(context, () => transitions.runner.executeDeferredToolCall(execution));
|
|
340
|
+
if (typeof result?.output !== "string") {
|
|
341
|
+
throw new TypeError(`executeDeferredToolCall returned no output for ${toolCallId}`);
|
|
342
|
+
}
|
|
343
|
+
finishedToolCall = { ...toolCall, status: "succeeded", output: result.output };
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
if (!(error instanceof ToolExecutionError)) {
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
finishedToolCall = { ...toolCall, status: "failed", error: error.message };
|
|
350
|
+
}
|
|
351
|
+
transitions.writeToolCall(context, finishedToolCall);
|
|
352
|
+
events.writeToolCallFinished(toolCall.toolCallId, toolCall.toolName, finishedToolCall.status);
|
|
353
|
+
transitions.publishToolCallResult(context, toolCallId);
|
|
354
|
+
return deadEnd();
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
events.close();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Failure route of a tool Step; it receives the failed Step's input, the tool call ID.
|
|
363
|
+
* `RecordToolFailure` records `failed` for a `read` call and `outcome_unknown` for a write;
|
|
364
|
+
* `RecordToolOutcomeUnknown` always records `outcome_unknown`.
|
|
365
|
+
*/
|
|
366
|
+
export class ToolCallFailureRecordingStep {
|
|
367
|
+
transitions;
|
|
368
|
+
stepType;
|
|
369
|
+
isReadFailureRecorded;
|
|
370
|
+
inputCodec = stringCodec;
|
|
371
|
+
constructor(transitions, stepType, isReadFailureRecorded) {
|
|
372
|
+
this.transitions = transitions;
|
|
373
|
+
this.stepType = stepType;
|
|
374
|
+
this.isReadFailureRecorded = isReadFailureRecorded;
|
|
375
|
+
}
|
|
376
|
+
getStepType() {
|
|
377
|
+
return this.stepType;
|
|
378
|
+
}
|
|
379
|
+
getStepOptions() {
|
|
380
|
+
return toolStepOptions(this.transitions.persistence, this.stepType);
|
|
381
|
+
}
|
|
382
|
+
execute(context, toolCallId) {
|
|
383
|
+
const transitions = this.transitions;
|
|
384
|
+
const toolCall = transitions.readToolCall(context, toolCallId);
|
|
385
|
+
if (isFinalToolCallStatus(toolCall.status)) {
|
|
386
|
+
return deadEnd();
|
|
387
|
+
}
|
|
388
|
+
const status = this.isReadFailureRecorded && toolCall.effect === "read" ? "failed" : "outcome_unknown";
|
|
389
|
+
transitions.writeToolCall(context, { ...toolCall, status, error: readRecoveryDetail(context) });
|
|
390
|
+
transitions.writeEvents(context, toolCall.turnId, (events) => events.writeToolCallFinished(toolCall.toolCallId, toolCall.toolName, status));
|
|
391
|
+
transitions.publishToolCallResult(context, toolCallId);
|
|
392
|
+
return deadEnd();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/** Waits until every tool call of the batch has a final record, then makes the next model call. */
|
|
396
|
+
export class ResumeTurnStep {
|
|
397
|
+
transitions;
|
|
398
|
+
inputCodec = expectedResultCountCodec;
|
|
399
|
+
constructor(transitions) {
|
|
400
|
+
this.transitions = transitions;
|
|
401
|
+
}
|
|
402
|
+
getStepType() {
|
|
403
|
+
return agentSessionStepTypes.resumeTurn;
|
|
404
|
+
}
|
|
405
|
+
getStepOptions() {
|
|
406
|
+
return { ...syncDurability, executeLoadAttributeMaps: [this.transitions.persistence.agentToolCalls] };
|
|
407
|
+
}
|
|
408
|
+
waitFor(_context, expectedResultCount) {
|
|
409
|
+
return Wait.until(this.transitions.persistence.toolCallResults.forN(expectedResultCount));
|
|
410
|
+
}
|
|
411
|
+
execute(context) {
|
|
412
|
+
const transitions = this.transitions;
|
|
413
|
+
const state = transitions.readAgentState(context);
|
|
414
|
+
const unfinishedCount = transitions
|
|
415
|
+
.readTurnToolCalls(context, state.activeTurnId)
|
|
416
|
+
.filter((toolCall) => !isFinalToolCallStatus(toolCall.status)).length;
|
|
417
|
+
if (unfinishedCount > 0) {
|
|
418
|
+
// A consumed result from an earlier turn must not resume this one early.
|
|
419
|
+
return goTo(new StepRef(agentSessionStepTypes.resumeTurn), unfinishedCount);
|
|
420
|
+
}
|
|
421
|
+
transitions.writeAgentState(context, { ...state, status: "running_model" });
|
|
422
|
+
return goTo(new StepRef(agentSessionStepTypes.runModel), undefined);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
export class RecordTurnFailureStep {
|
|
426
|
+
transitions;
|
|
427
|
+
inputCodec = voidCodec;
|
|
428
|
+
constructor(transitions) {
|
|
429
|
+
this.transitions = transitions;
|
|
430
|
+
}
|
|
431
|
+
getStepType() {
|
|
432
|
+
return agentSessionStepTypes.recordTurnFailure;
|
|
433
|
+
}
|
|
434
|
+
getStepOptions() {
|
|
435
|
+
return {
|
|
436
|
+
...syncDurability,
|
|
437
|
+
executeRetry: recoveryRetry,
|
|
438
|
+
executeLoadAttributeMaps: [this.transitions.persistence.agentToolCalls],
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
execute(context) {
|
|
442
|
+
const transitions = this.transitions;
|
|
443
|
+
const persistence = transitions.persistence;
|
|
444
|
+
let state = transitions.readAgentState(context);
|
|
445
|
+
const turnError = readRecoveryDetail(context);
|
|
446
|
+
const toolCalls = transitions.readTurnToolCalls(context, state.activeTurnId);
|
|
447
|
+
const finalToolCalls = toolCalls.filter((toolCall) => isFinalToolCallStatus(toolCall.status));
|
|
448
|
+
// The records are deleted below; the note keeps the next model from repeating writes.
|
|
449
|
+
if (state.activeTurnId !== null && finalToolCalls.length > 0) {
|
|
450
|
+
const note = transitions.runner.buildUserMessage(buildTurnFailureNote(finalToolCalls));
|
|
451
|
+
if (note.role !== "user") {
|
|
452
|
+
throw new TypeError("buildUserMessage must return a message with role user");
|
|
453
|
+
}
|
|
454
|
+
state = transitions.appendMessages(context, state, state.activeTurnId, [note]);
|
|
455
|
+
}
|
|
456
|
+
for (const toolCall of toolCalls) {
|
|
457
|
+
persistence.agentToolCalls.delete(context, toolCall.toolCallId);
|
|
458
|
+
}
|
|
459
|
+
persistence.frameworkRunState.delete(context);
|
|
460
|
+
persistence.pendingInterrupts.set(context, []);
|
|
461
|
+
transitions.writeAgentState(context, {
|
|
462
|
+
...state,
|
|
463
|
+
status: "waiting_for_user_message",
|
|
464
|
+
turnCount: state.turnCount + 1,
|
|
465
|
+
activeTurnId: null,
|
|
466
|
+
lastTurnError: turnError,
|
|
467
|
+
});
|
|
468
|
+
transitions.writeEvents(context, state.activeTurnId, (events) => events.writeEvent("turn_failed", { error: turnError }));
|
|
469
|
+
return transitions.goToAwaitUserMessage();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function validateToolCallsRequested(turnId, existingToolCalls, outcome) {
|
|
473
|
+
if (typeof outcome.frameworkRunState !== "string" || outcome.frameworkRunState === "") {
|
|
474
|
+
throw new TypeError(`ToolCallsRequested for ${turnId} needs a non-empty frameworkRunState`);
|
|
475
|
+
}
|
|
476
|
+
if (outcome.toolCalls.length === 0) {
|
|
477
|
+
throw new TypeError(`ToolCallsRequested for ${turnId} needs at least one tool call`);
|
|
478
|
+
}
|
|
479
|
+
const seenIds = new Set(existingToolCalls.map((toolCall) => toolCall.toolCallId));
|
|
480
|
+
for (const requestedToolCall of outcome.toolCalls) {
|
|
481
|
+
const toolCallId = requestedToolCall.toolCallId;
|
|
482
|
+
if (toolCallId.trim() === "" || toolCallId.includes("/")) {
|
|
483
|
+
throw new TypeError(`tool call ID ${JSON.stringify(toolCallId)} is empty or contains '/'`);
|
|
484
|
+
}
|
|
485
|
+
if (seenIds.has(toolCallId)) {
|
|
486
|
+
throw new TypeError(`tool call ${toolCallId} was already requested in ${turnId}`);
|
|
487
|
+
}
|
|
488
|
+
seenIds.add(toolCallId);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Returns the full options of a tool Step type. With a tool call ID, the Step loads only that call's
|
|
493
|
+
* record; a movement's options replace the Step's static options, so every option is repeated here.
|
|
494
|
+
*/
|
|
495
|
+
function toolStepOptions(persistence, stepType, toolCallId) {
|
|
496
|
+
const loads = toolCallId === undefined
|
|
497
|
+
? { executeLoadAttributeMaps: [persistence.agentToolCalls] }
|
|
498
|
+
: { executeLoadAttributeMapInstances: [persistence.agentToolCalls.load(toolCallId)] };
|
|
499
|
+
switch (stepType) {
|
|
500
|
+
case agentSessionStepTypes.awaitToolApproval:
|
|
501
|
+
// The deadline path rewrites PendingInterrupts, which resolve_interrupt and sibling Steps also write.
|
|
502
|
+
return { ...syncDurability, ...loads, executeLockAttributes: [persistence.pendingInterrupts.lock()] };
|
|
503
|
+
case agentSessionStepTypes.callTool:
|
|
504
|
+
return {
|
|
505
|
+
...syncDurability,
|
|
506
|
+
...loads,
|
|
507
|
+
executeRetry: { maximumAttempts: 3 },
|
|
508
|
+
executeFailure: ExecuteFailure.proceedTo(new StepRef(agentSessionStepTypes.recordToolFailure), toolStepOptions(persistence, agentSessionStepTypes.recordToolFailure, toolCallId)),
|
|
509
|
+
};
|
|
510
|
+
case agentSessionStepTypes.callSingleAttemptTool:
|
|
511
|
+
return {
|
|
512
|
+
...syncDurability,
|
|
513
|
+
...loads,
|
|
514
|
+
executeRetry: { maximumAttempts: 1 },
|
|
515
|
+
executeFailure: ExecuteFailure.proceedTo(new StepRef(agentSessionStepTypes.recordToolOutcomeUnknown), toolStepOptions(persistence, agentSessionStepTypes.recordToolOutcomeUnknown, toolCallId)),
|
|
516
|
+
};
|
|
517
|
+
case agentSessionStepTypes.recordToolFailure:
|
|
518
|
+
case agentSessionStepTypes.recordToolOutcomeUnknown:
|
|
519
|
+
return { ...syncDurability, ...loads, executeRetry: recoveryRetry };
|
|
520
|
+
default:
|
|
521
|
+
throw new TypeError(`${stepType} is not a tool Step type`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function toolStepMovement(persistence, stepType, toolCallId) {
|
|
525
|
+
return StepMovement.of(new StepRef(stepType), toolCallId, toolStepOptions(persistence, stepType, toolCallId));
|
|
526
|
+
}
|
|
527
|
+
function requirePositiveResultCount(value) {
|
|
528
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
529
|
+
throw new TypeError(`ResumeTurn input must be a positive integer: ${value}`);
|
|
530
|
+
}
|
|
531
|
+
return value;
|
|
532
|
+
}
|
|
533
|
+
//# sourceMappingURL=agent-session-steps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-steps.js","sourceRoot":"","sources":["../../src/agent-session-steps.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,OAAO,EACP,KAAK,EACL,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,SAAS,GASV,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,kBAAkB,GAKnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,GAEtB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,GAKtB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,qGAAqG;AACrG,MAAM,aAAa,GAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;AAChE,mGAAmG;AACnG,M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AAK;gBACR,YAAY,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE;gBACpC,cAAc,EAAE,cAAc,CAAC,SAAS,CACtC,IAAI,OAAO,CAAC,qBAAqB,CAAC,wBAAwB,CAAC,EAC3D,eAAe,CAAC,WAAW,EAAE,qBAAqB,CAAC,wBAAwB,EAAE,UAAU,CAAC,CACzF;aACF,CAAC;QACJ,KAAK,qBAAqB,CAAC,iBAAiB,CAAC;QAC7C,KAAK,qBAAqB,CAAC,wBAAwB;YACjD,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;QACtE;YACE,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,0BAA0B,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CACvB,WAAoC,EACpC,QAAgB,EAChB,UAAkB;IAElB,OAAO,YAAY,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;AAChH,CAAC;AAED,SAAS,0BAA0B,CAAC,KAAa;IAC/C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,SAAS,CAAC,gDAAgD,KAAK,EAAE,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type AsyncContext, type Context, type StepDecision } from "@superdurable/dex";
|
|
2
|
+
import { StreamAgentEventWriter } from "./agent-event-writer.js";
|
|
3
|
+
import { type AgentFrameworkRunner, type ResolvedToolPolicy, type ToolPolicy } from "./agent-framework-runner.js";
|
|
4
|
+
import { type AgentSessionPersistence } from "./agent-session-persistence.js";
|
|
5
|
+
import { type AgentInterrupt, type AgentMessage, type AgentState, type AgentToolCall, type AgentUsage, type FrameworkMessage, type ToolEffect } from "./agent-session-values.js";
|
|
6
|
+
export declare const agentSessionStepTypes: {
|
|
7
|
+
readonly startAgentSession: "StartAgentSession";
|
|
8
|
+
readonly awaitUserMessage: "AwaitUserMessage";
|
|
9
|
+
readonly runModel: "RunModel";
|
|
10
|
+
readonly awaitToolApproval: "AwaitToolApproval";
|
|
11
|
+
readonly callTool: "CallTool";
|
|
12
|
+
readonly callSingleAttemptTool: "CallSingleAttemptTool";
|
|
13
|
+
readonly recordToolFailure: "RecordToolFailure";
|
|
14
|
+
readonly recordToolOutcomeUnknown: "RecordToolOutcomeUnknown";
|
|
15
|
+
readonly resumeTurn: "ResumeTurn";
|
|
16
|
+
readonly recordTurnFailure: "RecordTurnFailure";
|
|
17
|
+
};
|
|
18
|
+
export interface AgentSessionConfig {
|
|
19
|
+
readonly flowType: string;
|
|
20
|
+
readonly toolPolicies: Readonly<Record<string, ToolPolicy>>;
|
|
21
|
+
readonly defaultToolEffect: ToolEffect;
|
|
22
|
+
readonly eventStreamCapacityBytes: number;
|
|
23
|
+
readonly interruptDeadlineMs: number | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Shared state reads, writes, and routing used by every session Step. */
|
|
26
|
+
export declare class AgentSessionTransitions {
|
|
27
|
+
readonly persistence: AgentSessionPersistence;
|
|
28
|
+
readonly runner: AgentFrameworkRunner;
|
|
29
|
+
readonly config: AgentSessionConfig;
|
|
30
|
+
constructor(persistence: AgentSessionPersistence, runner: AgentFrameworkRunner, config: AgentSessionConfig);
|
|
31
|
+
readOptionalAgentState(context: Context): AgentState | null;
|
|
32
|
+
readAgentState(context: Context): AgentState;
|
|
33
|
+
writeAgentState(context: Context, state: AgentState): void;
|
|
34
|
+
readPendingInterrupts(context: Context): readonly AgentInterrupt[];
|
|
35
|
+
readAgentUsage(context: Context): AgentUsage;
|
|
36
|
+
readFrameworkRunState(context: Context): string | null;
|
|
37
|
+
/** Returns messages with sequences in [start, end); requires the AgentMessages load. */
|
|
38
|
+
readMessages(context: Context, start: number, end: number): AgentMessage[];
|
|
39
|
+
/** Returns the turn's tool call records in deferral order; requires the AgentToolCalls load. */
|
|
40
|
+
readTurnToolCalls(context: Context, turnId: string | null): AgentToolCall[];
|
|
41
|
+
/** Returns one tool call record; requires the AgentToolCalls load. */
|
|
42
|
+
readToolCall(context: Context, toolCallId: string): AgentToolCall;
|
|
43
|
+
/** Tells `ResumeTurn` that one tool call of the batch has a final record. */
|
|
44
|
+
publishToolCallResult(context: Context, toolCallId: string): void;
|
|
45
|
+
writeToolCall(context: Context, toolCall: AgentToolCall): void;
|
|
46
|
+
/** Appends messages, writes the advanced AgentState, and returns it. */
|
|
47
|
+
appendMessages(context: Context, state: AgentState, turnId: string, frameworkMessages: readonly FrameworkMessage[]): AgentState;
|
|
48
|
+
/** Appends the user message, opens the next turn, and moves to RunModel. */
|
|
49
|
+
beginTurn(context: Context, state: AgentState, text: string): StepDecision;
|
|
50
|
+
goToAwaitUserMessage(): StepDecision;
|
|
51
|
+
resolveToolPolicy(toolName: string, frameworkEffect?: ToolEffect): ResolvedToolPolicy;
|
|
52
|
+
recordUsage(context: Context, usage: AgentUsage, events: StreamAgentEventWriter): void;
|
|
53
|
+
createEventWriter(context: Context, turnId: string | null): StreamAgentEventWriter;
|
|
54
|
+
writeEvents(context: Context, turnId: string | null, write: (events: StreamAgentEventWriter) => void): void;
|
|
55
|
+
/** Runs an operation while recording a heartbeat every 20 seconds. */
|
|
56
|
+
runWithHeartbeats<Result>(context: AsyncContext, operation: () => Promise<Result>): Promise<Result>;
|
|
57
|
+
recordHeartbeat(context: AsyncContext): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export declare function toolStepTypeForEffect(effect: ToolEffect): string;
|
|
60
|
+
/** Returns the text of the failure that selected a recovery Step. */
|
|
61
|
+
export declare function readRecoveryDetail(context: Context): string;
|