@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,202 @@
|
|
|
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 { StepRef, goTo, stringCodec, } from "@superdurable/dex";
|
|
9
|
+
import { StreamAgentEventWriter } from "./agent-event-writer.js";
|
|
10
|
+
import { resolveToolPolicy, } from "./agent-framework-runner.js";
|
|
11
|
+
import { messageSequenceKey } from "./agent-session-persistence.js";
|
|
12
|
+
import { addAgentUsage, emptyAgentUsage, } from "./agent-session-values.js";
|
|
13
|
+
export const agentSessionStepTypes = {
|
|
14
|
+
startAgentSession: "StartAgentSession",
|
|
15
|
+
awaitUserMessage: "AwaitUserMessage",
|
|
16
|
+
runModel: "RunModel",
|
|
17
|
+
awaitToolApproval: "AwaitToolApproval",
|
|
18
|
+
callTool: "CallTool",
|
|
19
|
+
callSingleAttemptTool: "CallSingleAttemptTool",
|
|
20
|
+
recordToolFailure: "RecordToolFailure",
|
|
21
|
+
recordToolOutcomeUnknown: "RecordToolOutcomeUnknown",
|
|
22
|
+
resumeTurn: "ResumeTurn",
|
|
23
|
+
recordTurnFailure: "RecordTurnFailure",
|
|
24
|
+
};
|
|
25
|
+
// Keeps liveness well inside the shortest heartbeat timeout, one minute.
|
|
26
|
+
const heartbeatIntervalMs = 20_000;
|
|
27
|
+
/** Shared state reads, writes, and routing used by every session Step. */
|
|
28
|
+
export class AgentSessionTransitions {
|
|
29
|
+
persistence;
|
|
30
|
+
runner;
|
|
31
|
+
config;
|
|
32
|
+
constructor(persistence, runner, config) {
|
|
33
|
+
this.persistence = persistence;
|
|
34
|
+
this.runner = runner;
|
|
35
|
+
this.config = config;
|
|
36
|
+
}
|
|
37
|
+
readOptionalAgentState(context) {
|
|
38
|
+
return this.persistence.agentState.get(context) ?? null;
|
|
39
|
+
}
|
|
40
|
+
readAgentState(context) {
|
|
41
|
+
const state = this.readOptionalAgentState(context);
|
|
42
|
+
if (state === null) {
|
|
43
|
+
throw new Error(`the agent session ${context.flowId} is not initialized`);
|
|
44
|
+
}
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
writeAgentState(context, state) {
|
|
48
|
+
this.persistence.agentState.set(context, state);
|
|
49
|
+
}
|
|
50
|
+
readPendingInterrupts(context) {
|
|
51
|
+
return this.persistence.pendingInterrupts.get(context) ?? [];
|
|
52
|
+
}
|
|
53
|
+
readAgentUsage(context) {
|
|
54
|
+
return this.persistence.agentUsage.get(context) ?? emptyAgentUsage();
|
|
55
|
+
}
|
|
56
|
+
readFrameworkRunState(context) {
|
|
57
|
+
const runState = this.persistence.frameworkRunState.get(context);
|
|
58
|
+
return runState === undefined || runState === "" ? null : runState;
|
|
59
|
+
}
|
|
60
|
+
/** Returns messages with sequences in [start, end); requires the AgentMessages load. */
|
|
61
|
+
readMessages(context, start, end) {
|
|
62
|
+
const messages = [];
|
|
63
|
+
for (let sequence = Math.max(1, start); sequence < end; sequence += 1) {
|
|
64
|
+
messages.push(this.persistence.agentMessages.get(context, messageSequenceKey(sequence)));
|
|
65
|
+
}
|
|
66
|
+
return messages;
|
|
67
|
+
}
|
|
68
|
+
/** Returns the turn's tool call records in deferral order; requires the AgentToolCalls load. */
|
|
69
|
+
readTurnToolCalls(context, turnId) {
|
|
70
|
+
if (turnId === null) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const toolCalls = this.persistence.agentToolCalls;
|
|
74
|
+
return toolCalls
|
|
75
|
+
.getAllInstanceKeys(context)
|
|
76
|
+
.map((key) => toolCalls.get(context, key))
|
|
77
|
+
.filter((toolCall) => toolCall.turnId === turnId)
|
|
78
|
+
.sort((left, right) => left.deferralOrder - right.deferralOrder);
|
|
79
|
+
}
|
|
80
|
+
/** Returns one tool call record; requires the AgentToolCalls load. */
|
|
81
|
+
readToolCall(context, toolCallId) {
|
|
82
|
+
const toolCall = this.persistence.agentToolCalls.get(context, toolCallId);
|
|
83
|
+
if (toolCall === undefined) {
|
|
84
|
+
throw new Error(`tool call ${toolCallId} has no record in session ${context.flowId}`);
|
|
85
|
+
}
|
|
86
|
+
return toolCall;
|
|
87
|
+
}
|
|
88
|
+
/** Tells `ResumeTurn` that one tool call of the batch has a final record. */
|
|
89
|
+
publishToolCallResult(context, toolCallId) {
|
|
90
|
+
this.persistence.toolCallResults.publish(context, { toolCallId });
|
|
91
|
+
}
|
|
92
|
+
writeToolCall(context, toolCall) {
|
|
93
|
+
this.persistence.agentToolCalls.set(context, toolCall.toolCallId, toolCall);
|
|
94
|
+
}
|
|
95
|
+
/** Appends messages, writes the advanced AgentState, and returns it. */
|
|
96
|
+
appendMessages(context, state, turnId, frameworkMessages) {
|
|
97
|
+
let nextMessageSequence = state.nextMessageSequence;
|
|
98
|
+
const createdAt = new Date().toISOString();
|
|
99
|
+
for (const frameworkMessage of frameworkMessages) {
|
|
100
|
+
const message = {
|
|
101
|
+
sequence: nextMessageSequence,
|
|
102
|
+
turnId,
|
|
103
|
+
role: frameworkMessage.role,
|
|
104
|
+
text: frameworkMessage.text,
|
|
105
|
+
toolCallId: frameworkMessage.toolCallId,
|
|
106
|
+
toolName: frameworkMessage.toolName,
|
|
107
|
+
toolArguments: frameworkMessage.toolArguments,
|
|
108
|
+
toolOutput: frameworkMessage.toolOutput,
|
|
109
|
+
frameworkItem: frameworkMessage.frameworkItem,
|
|
110
|
+
createdAt,
|
|
111
|
+
};
|
|
112
|
+
this.persistence.agentMessages.set(context, messageSequenceKey(nextMessageSequence), message);
|
|
113
|
+
nextMessageSequence += 1;
|
|
114
|
+
}
|
|
115
|
+
const advancedState = { ...state, nextMessageSequence };
|
|
116
|
+
this.writeAgentState(context, advancedState);
|
|
117
|
+
return advancedState;
|
|
118
|
+
}
|
|
119
|
+
/** Appends the user message, opens the next turn, and moves to RunModel. */
|
|
120
|
+
beginTurn(context, state, text) {
|
|
121
|
+
const turnId = `turn-${state.turnCount + 1}`;
|
|
122
|
+
const userMessage = this.runner.buildUserMessage(text);
|
|
123
|
+
if (userMessage.role !== "user") {
|
|
124
|
+
throw new TypeError("buildUserMessage must return a message with role user");
|
|
125
|
+
}
|
|
126
|
+
const sequence = state.nextMessageSequence;
|
|
127
|
+
const stateWithMessage = this.appendMessages(context, state, turnId, [userMessage]);
|
|
128
|
+
this.writeAgentState(context, { ...stateWithMessage, status: "running_model", activeTurnId: turnId });
|
|
129
|
+
this.writeEvents(context, turnId, (events) => events.writeEvent("turn_started", { sequence }));
|
|
130
|
+
return goTo(new StepRef(agentSessionStepTypes.runModel), undefined);
|
|
131
|
+
}
|
|
132
|
+
goToAwaitUserMessage() {
|
|
133
|
+
return goTo(new StepRef(agentSessionStepTypes.awaitUserMessage), undefined);
|
|
134
|
+
}
|
|
135
|
+
resolveToolPolicy(toolName, frameworkEffect) {
|
|
136
|
+
return resolveToolPolicy(toolName, this.config.toolPolicies, this.config.defaultToolEffect, frameworkEffect);
|
|
137
|
+
}
|
|
138
|
+
recordUsage(context, usage, events) {
|
|
139
|
+
const sessionUsage = addAgentUsage(this.readAgentUsage(context), usage);
|
|
140
|
+
this.persistence.agentUsage.set(context, sessionUsage);
|
|
141
|
+
events.writeEvent("usage_recorded", {
|
|
142
|
+
recorded: usagePayload(usage),
|
|
143
|
+
session: usagePayload(sessionUsage),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
createEventWriter(context, turnId) {
|
|
147
|
+
return new StreamAgentEventWriter(context, this.persistence.agentEvents, turnId);
|
|
148
|
+
}
|
|
149
|
+
writeEvents(context, turnId, write) {
|
|
150
|
+
const events = this.createEventWriter(context, turnId);
|
|
151
|
+
try {
|
|
152
|
+
write(events);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
events.close();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** Runs an operation while recording a heartbeat every 20 seconds. */
|
|
159
|
+
async runWithHeartbeats(context, operation) {
|
|
160
|
+
const heartbeatTimer = setInterval(() => {
|
|
161
|
+
// A rejected heartbeat means the attempt already ended; the operation result decides the outcome.
|
|
162
|
+
this.recordHeartbeat(context).catch(() => undefined);
|
|
163
|
+
}, heartbeatIntervalMs);
|
|
164
|
+
try {
|
|
165
|
+
return await operation();
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
clearInterval(heartbeatTimer);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
recordHeartbeat(context) {
|
|
172
|
+
return context.recordHeartbeat(context.stepExecutionId, stringCodec);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export function toolStepTypeForEffect(effect) {
|
|
176
|
+
switch (effect) {
|
|
177
|
+
case "read":
|
|
178
|
+
case "idempotent_write":
|
|
179
|
+
return agentSessionStepTypes.callTool;
|
|
180
|
+
case "non_idempotent_write":
|
|
181
|
+
case "unclassified":
|
|
182
|
+
return agentSessionStepTypes.callSingleAttemptTool;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/** Returns the text of the failure that selected a recovery Step. */
|
|
186
|
+
export function readRecoveryDetail(context) {
|
|
187
|
+
const recoveryError = context.recoveryError;
|
|
188
|
+
if (recoveryError === undefined) {
|
|
189
|
+
return "unknown failure";
|
|
190
|
+
}
|
|
191
|
+
return recoveryError.detail !== "" ? recoveryError.detail : recoveryError.errorType;
|
|
192
|
+
}
|
|
193
|
+
function usagePayload(usage) {
|
|
194
|
+
return {
|
|
195
|
+
model_calls: usage.modelCalls,
|
|
196
|
+
input_tokens: usage.inputTokens,
|
|
197
|
+
output_tokens: usage.outputTokens,
|
|
198
|
+
cached_input_tokens: usage.cachedInputTokens,
|
|
199
|
+
reasoning_tokens: usage.reasoningTokens,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=agent-session-transitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-transitions.js","sourceRoot":"","sources":["../../src/agent-session-transitions.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,OAAO,EACP,IAAI,EACJ,WAAW,GAIZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EACL,iBAAiB,GAIlB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAgC,MAAM,gCAAgC,CAAC;AAClG,OAAO,EACL,aAAa,EACb,eAAe,GAQhB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,QAAQ,EAAE,UAAU;IACpB,iBAAiB,EAAE,mBAAmB;IACtC,QAAQ,EAAE,UAAU;IACpB,qBAAqB,EAAE,uBAAuB;IAC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KAAK,CAAC,eAAe;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status of an agent session, stored in the `status` field of {@link AgentState}.
|
|
3
|
+
*
|
|
4
|
+
* - `waiting_for_user_message`: the session is idle in `AwaitUserMessage`.
|
|
5
|
+
* - `running_model`: `RunModel` makes the turn's next model call.
|
|
6
|
+
* - `running_tools`: the requested tool calls run in parallel Steps, some possibly waiting for
|
|
7
|
+
* approval, and `ResumeTurn` waits for their results.
|
|
8
|
+
*/
|
|
9
|
+
export type AgentSessionStatus = "waiting_for_user_message" | "running_model" | "running_tools";
|
|
10
|
+
/**
|
|
11
|
+
* Input of the `StartAgentSession` Step, passed to `Client.startFlow`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* await client.startFlow(flow, "session-42", { initialMessage: "Summarize my inbox" });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface AgentSessionStartInput {
|
|
19
|
+
/**
|
|
20
|
+
* First user message, or `null` to start idle in `AwaitUserMessage`.
|
|
21
|
+
* Blank text is treated as `null`. Wire field: `initial_message`.
|
|
22
|
+
*/
|
|
23
|
+
readonly initialMessage: string | null;
|
|
24
|
+
}
|
|
25
|
+
/** Small durable summary of an agent session, stored in the `AgentState` Attribute. */
|
|
26
|
+
export interface AgentState {
|
|
27
|
+
/** Current session status. Wire field: `status`. */
|
|
28
|
+
readonly status: AgentSessionStatus;
|
|
29
|
+
/** Number of completed or failed turns. Wire field: `turn_count`. */
|
|
30
|
+
readonly turnCount: number;
|
|
31
|
+
/** ID of the running turn, `turn-<n>`, or `null` when idle. Wire field: `active_turn_id`. */
|
|
32
|
+
readonly activeTurnId: string | null;
|
|
33
|
+
/** Sequence assigned to the next stored message; starts at 1. Wire field: `next_message_sequence`. */
|
|
34
|
+
readonly nextMessageSequence: number;
|
|
35
|
+
/** Error text of the most recent failed turn, or `null`. Wire field: `last_turn_error`. */
|
|
36
|
+
readonly lastTurnError: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** Author of one stored agent message. */
|
|
39
|
+
export type AgentMessageRole = "user" | "assistant" | "tool";
|
|
40
|
+
/**
|
|
41
|
+
* Framework-neutral projection of one framework message, produced by an {@link AgentFrameworkRunner}.
|
|
42
|
+
*
|
|
43
|
+
* The session stores it as an {@link AgentMessage} after adding a sequence, turn ID, and time.
|
|
44
|
+
* Only `frameworkItem` is replayed to the framework; the other fields are display projections.
|
|
45
|
+
*/
|
|
46
|
+
export interface FrameworkMessage {
|
|
47
|
+
/** Author of the message. */
|
|
48
|
+
readonly role: AgentMessageRole;
|
|
49
|
+
/** Display text, or `null` for a message without text, such as a bare tool call. */
|
|
50
|
+
readonly text: string | null;
|
|
51
|
+
/** Tool call ID for a tool call or tool result message, otherwise `null`. */
|
|
52
|
+
readonly toolCallId: string | null;
|
|
53
|
+
/** Tool name for a tool call or tool result message, otherwise `null`. */
|
|
54
|
+
readonly toolName: string | null;
|
|
55
|
+
/** Tool call arguments as JSON text, otherwise `null`. */
|
|
56
|
+
readonly toolArguments: string | null;
|
|
57
|
+
/** Tool result text, otherwise `null`. */
|
|
58
|
+
readonly toolOutput: string | null;
|
|
59
|
+
/** Framework-native JSON for this message; the session replays it to the framework unchanged. */
|
|
60
|
+
readonly frameworkItem: string;
|
|
61
|
+
}
|
|
62
|
+
/** One message stored in the `AgentMessages` AttributeMap under its zero-padded sequence. */
|
|
63
|
+
export interface AgentMessage extends FrameworkMessage {
|
|
64
|
+
/** Monotonic session-wide sequence, starting at 1. Wire field: `sequence`. */
|
|
65
|
+
readonly sequence: number;
|
|
66
|
+
/** Turn that produced the message. Wire field: `turn_id`. */
|
|
67
|
+
readonly turnId: string;
|
|
68
|
+
/** RFC 3339 time at which the session stored the message. Wire field: `created_at`. */
|
|
69
|
+
readonly createdAt: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Side-effect class of a tool, which decides where and how often the session runs it.
|
|
73
|
+
*
|
|
74
|
+
* - `read`: runs in `CallTool`, up to 3 attempts; no approval by default.
|
|
75
|
+
* - `idempotent_write`: runs in `CallTool`, up to 3 attempts with one idempotency key; when they run
|
|
76
|
+
* out, the session records `outcome_unknown`.
|
|
77
|
+
* - `non_idempotent_write`: runs once in `CallSingleAttemptTool`; a crash records `outcome_unknown`.
|
|
78
|
+
* - `unclassified`: treated like `non_idempotent_write`; the default for tools without a policy.
|
|
79
|
+
*/
|
|
80
|
+
export type ToolEffect = "read" | "idempotent_write" | "non_idempotent_write" | "unclassified";
|
|
81
|
+
/**
|
|
82
|
+
* Status of one deferred tool call record.
|
|
83
|
+
*
|
|
84
|
+
* `awaiting_approval` and `approved` are open. The other statuses are final: the session
|
|
85
|
+
* never runs a call whose record is final, and the runner reports the result to the model.
|
|
86
|
+
* `failed` means the tool threw {@link ToolExecutionError}, or a `read` call ended without a result after
|
|
87
|
+
* its attempts ran out. `outcome_unknown` means a write's tool Step ended without a result, through a
|
|
88
|
+
* Worker crash, a timeout, or another error after its attempts ran out.
|
|
89
|
+
*/
|
|
90
|
+
export type AgentToolCallStatus = "awaiting_approval" | "approved" | "rejected" | "succeeded" | "failed" | "outcome_unknown";
|
|
91
|
+
/** Durable record of one deferred tool call, stored in `AgentToolCalls` under its tool call ID. */
|
|
92
|
+
export interface AgentToolCall {
|
|
93
|
+
/** Framework tool call ID; non-empty and slash-free. Wire field: `tool_call_id`. */
|
|
94
|
+
readonly toolCallId: string;
|
|
95
|
+
/** Turn that deferred the call. Wire field: `turn_id`. */
|
|
96
|
+
readonly turnId: string;
|
|
97
|
+
/** Tool name. Wire field: `tool_name`. */
|
|
98
|
+
readonly toolName: string;
|
|
99
|
+
/** Tool arguments as JSON text. Wire field: `arguments`. */
|
|
100
|
+
readonly arguments: string;
|
|
101
|
+
/** Effect that selected the tool Step. Wire field: `effect`. */
|
|
102
|
+
readonly effect: ToolEffect;
|
|
103
|
+
/** Whether the call waited for `resolve_interrupt`. Wire field: `requires_approval`. */
|
|
104
|
+
readonly requiresApproval: boolean;
|
|
105
|
+
/** Current status. Wire field: `status`. */
|
|
106
|
+
readonly status: AgentToolCallStatus;
|
|
107
|
+
/** Tool output text after `succeeded`, otherwise `null`. Wire field: `output`. */
|
|
108
|
+
readonly output: string | null;
|
|
109
|
+
/**
|
|
110
|
+
* The `ToolExecutionError` message, or the failed Step's recovery detail, after `failed` or
|
|
111
|
+
* `outcome_unknown`; otherwise `null`. Wire field: `error`.
|
|
112
|
+
*/
|
|
113
|
+
readonly error: string | null;
|
|
114
|
+
/** Rejection text after `rejected`, otherwise `null`. Wire field: `rejection_message`. */
|
|
115
|
+
readonly rejectionMessage: string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Zero-based order in which the turn deferred the call; approved calls run in this order.
|
|
118
|
+
* It extends the planned contract, as in the Python core. Wire field: `deferral_order`.
|
|
119
|
+
*/
|
|
120
|
+
readonly deferralOrder: number;
|
|
121
|
+
}
|
|
122
|
+
/** One pending approval request, stored in the `PendingInterrupts` Attribute. */
|
|
123
|
+
export interface AgentInterrupt {
|
|
124
|
+
/** Interrupt ID; equals the tool call ID for tool approvals. Wire field: `interrupt_id`. */
|
|
125
|
+
readonly interruptId: string;
|
|
126
|
+
/** Interrupt kind. Wire field: `kind`. */
|
|
127
|
+
readonly kind: "tool_approval";
|
|
128
|
+
/** Tool call awaiting approval. Wire field: `tool_call_id`. */
|
|
129
|
+
readonly toolCallId: string;
|
|
130
|
+
/** Tool name. Wire field: `tool_name`. */
|
|
131
|
+
readonly toolName: string;
|
|
132
|
+
/** Tool arguments as JSON text. Wire field: `arguments`. */
|
|
133
|
+
readonly arguments: string;
|
|
134
|
+
/** RFC 3339 time at which the interrupt was raised. Wire field: `created_at`. */
|
|
135
|
+
readonly createdAt: string;
|
|
136
|
+
/** RFC 3339 approval deadline, or `null` for no deadline. Wire field: `deadline`. */
|
|
137
|
+
readonly deadline: string | null;
|
|
138
|
+
}
|
|
139
|
+
/** Resolution of one interrupt, published to the `InterruptResolutions` ChannelMap. */
|
|
140
|
+
export interface AgentInterruptResolution {
|
|
141
|
+
/** Whether the tool call may run. Wire field: `approved`. */
|
|
142
|
+
readonly approved: boolean;
|
|
143
|
+
/** Text shown to the model when rejected, or `null`. Wire field: `rejection_message`. */
|
|
144
|
+
readonly rejectionMessage: string | null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Model usage counters, stored cumulatively in the `AgentUsage` Attribute.
|
|
148
|
+
*
|
|
149
|
+
* Runners report the usage of one model call in an {@link AgentTurnOutcome}; the session adds it.
|
|
150
|
+
* Use {@link emptyAgentUsage} and {@link addAgentUsage} to accumulate per-model-call usage.
|
|
151
|
+
*/
|
|
152
|
+
export interface AgentUsage {
|
|
153
|
+
/** Number of model calls. Wire field: `model_calls`. */
|
|
154
|
+
readonly modelCalls: number;
|
|
155
|
+
/** Input tokens, including cached input tokens. Wire field: `input_tokens`. */
|
|
156
|
+
readonly inputTokens: number;
|
|
157
|
+
/** Output tokens, including reasoning tokens when the provider counts them so. Wire field: `output_tokens`. */
|
|
158
|
+
readonly outputTokens: number;
|
|
159
|
+
/** Input tokens served from a provider cache. Wire field: `cached_input_tokens`. */
|
|
160
|
+
readonly cachedInputTokens: number;
|
|
161
|
+
/** Reasoning tokens reported by the provider. Wire field: `reasoning_tokens`. */
|
|
162
|
+
readonly reasoningTokens: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Notice that one tool call of the current batch reached a final record, published to the internal
|
|
166
|
+
* `ToolCallResults` Channel. `ResumeTurn` waits for one per requested tool call; the result itself is
|
|
167
|
+
* in the call's `AgentToolCalls` record.
|
|
168
|
+
*/
|
|
169
|
+
export interface ToolCallCompleted {
|
|
170
|
+
/** Tool call whose record is final. Wire field: `tool_call_id`. */
|
|
171
|
+
readonly toolCallId: string;
|
|
172
|
+
}
|
|
173
|
+
/** One user message, the input of the `send_user_message` RPC and the `QueuedUserMessages` Channel value. */
|
|
174
|
+
export interface AgentUserMessage {
|
|
175
|
+
/** Message text. Blank text is rejected. Wire field: `text`. */
|
|
176
|
+
readonly text: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Standard type of one {@link AgentEvent}. Adapters may write other types with an adapter prefix.
|
|
180
|
+
*
|
|
181
|
+
* Payloads are JSON objects with snake_case keys, serialized with sorted keys:
|
|
182
|
+
* - `turn_started`: `{"sequence"}`, the sequence of the user message that started the turn.
|
|
183
|
+
* - `turn_completed`: `{"message_count"}`, the number of messages the turn appended.
|
|
184
|
+
* - `turn_failed`: `{"error"}`.
|
|
185
|
+
* - `text_delta` and `reasoning_delta`: `{"text"}`.
|
|
186
|
+
* - `tool_call_started`: `{"tool_call_id","tool_name"}`.
|
|
187
|
+
* - `tool_call_finished`: `{"tool_call_id","tool_name","status"}`, when a record becomes final,
|
|
188
|
+
* including a rejection.
|
|
189
|
+
* - `tool_call_deferred`: `{"tool_call_id","tool_name","effect","requires_approval"}`, when the model
|
|
190
|
+
* asks for a call, which then runs in its own Step.
|
|
191
|
+
* - `interrupt_raised`: `{"interrupt_id","tool_call_id","tool_name","deadline"}`.
|
|
192
|
+
* - `interrupt_resolved`: `{"interrupt_id","approved","rejection_message"}`.
|
|
193
|
+
* - `usage_recorded`: `{"recorded","session"}`: one model call's and the cumulative usage, each with
|
|
194
|
+
* {@link AgentUsage} wire fields.
|
|
195
|
+
*/
|
|
196
|
+
export type AgentEventType = "turn_started" | "turn_completed" | "turn_failed" | "text_delta" | "reasoning_delta" | "tool_call_started" | "tool_call_finished" | "tool_call_deferred" | "interrupt_raised" | "interrupt_resolved" | "usage_recorded";
|
|
197
|
+
/** One best-effort live event, written to the `AgentEvents` Stream. */
|
|
198
|
+
export interface AgentEvent {
|
|
199
|
+
/** An {@link AgentEventType} or an adapter-specific type such as `"vercel_ai.step"`. Wire field: `type`. */
|
|
200
|
+
readonly type: string;
|
|
201
|
+
/** Turn the event belongs to, or `null`. Wire field: `turn_id`. */
|
|
202
|
+
readonly turnId: string | null;
|
|
203
|
+
/** One-based attempt of the Step that wrote the event. Wire field: `attempt`. */
|
|
204
|
+
readonly attempt: number;
|
|
205
|
+
/**
|
|
206
|
+
* Dex Step execution ID of the Step that wrote the event; all attempts of one Step execution share
|
|
207
|
+
* it. Events written before this field existed decode with `""`. Wire field: `step_execution_id`.
|
|
208
|
+
*
|
|
209
|
+
* Group live text by `(turnId, stepExecutionId, attempt)`. Within one `stepExecutionId`, keep only the
|
|
210
|
+
* events of the highest `attempt` seen and drop the partial text of lower attempts. Different
|
|
211
|
+
* `stepExecutionId` values of one turn are its model calls and tool Steps, and each keeps its
|
|
212
|
+
* own events. After `turn_completed` or `turn_failed`, replace the turn's live text with the stored
|
|
213
|
+
* messages.
|
|
214
|
+
*/
|
|
215
|
+
readonly stepExecutionId: string;
|
|
216
|
+
/** Event payload as JSON text. Wire field: `payload`. */
|
|
217
|
+
readonly payload: string;
|
|
218
|
+
}
|
|
219
|
+
/** Input of the `resolve_interrupt` RPC. */
|
|
220
|
+
export interface ResolveInterruptInput {
|
|
221
|
+
/** Pending interrupt to resolve. Wire field: `interrupt_id`. */
|
|
222
|
+
readonly interruptId: string;
|
|
223
|
+
/** Whether the tool call may run. Wire field: `approved`. */
|
|
224
|
+
readonly approved: boolean;
|
|
225
|
+
/** Text shown to the model when rejected, or `null`. Wire field: `rejection_message`. */
|
|
226
|
+
readonly rejectionMessage: string | null;
|
|
227
|
+
}
|
|
228
|
+
/** Output of the `get_agent_snapshot` RPC, enough for a UI to rebuild its view. */
|
|
229
|
+
export interface AgentSnapshot {
|
|
230
|
+
/** Current session state, or `null` before `StartAgentSession` committed. Wire field: `state`. */
|
|
231
|
+
readonly state: AgentState | null;
|
|
232
|
+
/** Up to the last 200 messages in ascending sequence order. Wire field: `messages`. */
|
|
233
|
+
readonly messages: readonly AgentMessage[];
|
|
234
|
+
/** Interrupts that `resolve_interrupt` still accepts. Wire field: `pending_interrupts`. */
|
|
235
|
+
readonly pendingInterrupts: readonly AgentInterrupt[];
|
|
236
|
+
/** Deferred tool call records of the active turn, in deferral order. Wire field: `tool_calls`. */
|
|
237
|
+
readonly toolCalls: readonly AgentToolCall[];
|
|
238
|
+
/** Cumulative usage. Wire field: `usage`. */
|
|
239
|
+
readonly usage: AgentUsage;
|
|
240
|
+
/** User messages queued and not yet consumed. Wire field: `queued_message_count`. */
|
|
241
|
+
readonly queuedMessageCount: number;
|
|
242
|
+
}
|
|
243
|
+
/** Input of the `list_agent_messages` RPC. */
|
|
244
|
+
export interface ListAgentMessagesInput {
|
|
245
|
+
/** Return messages with a smaller sequence, or `null` for the newest. Wire field: `before_sequence`. */
|
|
246
|
+
readonly beforeSequence: number | null;
|
|
247
|
+
/** Page size; the session clamps it to 1..200. A missing wire value means 50. Wire field: `limit`. */
|
|
248
|
+
readonly limit: number;
|
|
249
|
+
}
|
|
250
|
+
/** Output of the `list_agent_messages` RPC. */
|
|
251
|
+
export interface AgentMessagesPage {
|
|
252
|
+
/** Messages in ascending sequence order. Wire field: `messages`. */
|
|
253
|
+
readonly messages: readonly AgentMessage[];
|
|
254
|
+
/**
|
|
255
|
+
* Value to pass as `beforeSequence` for the next older page, or `null` when no older message exists.
|
|
256
|
+
* Wire field: `next_before_sequence`.
|
|
257
|
+
*/
|
|
258
|
+
readonly nextBeforeSequence: number | null;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Returns usage with every counter at zero.
|
|
262
|
+
*
|
|
263
|
+
* @returns A new {@link AgentUsage} whose counters are all `0`.
|
|
264
|
+
*/
|
|
265
|
+
export declare function emptyAgentUsage(): AgentUsage;
|
|
266
|
+
/**
|
|
267
|
+
* Adds two usage values counter by counter.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* let usage = emptyAgentUsage();
|
|
272
|
+
* usage = addAgentUsage(usage, { ...emptyAgentUsage(), modelCalls: 1, inputTokens: 120, outputTokens: 30 });
|
|
273
|
+
* ```
|
|
274
|
+
* @param left - First usage value.
|
|
275
|
+
* @param right - Second usage value.
|
|
276
|
+
* @returns A new {@link AgentUsage} holding the sums; neither input is changed.
|
|
277
|
+
*/
|
|
278
|
+
export declare function addAgentUsage(left: AgentUsage, right: AgentUsage): AgentUsage;
|
|
279
|
+
/**
|
|
280
|
+
* Reports whether a tool call status is final.
|
|
281
|
+
*
|
|
282
|
+
* @param status - Status to classify.
|
|
283
|
+
* @returns `true` for `rejected`, `succeeded`, `failed`, and `outcome_unknown`; `false` for
|
|
284
|
+
* `awaiting_approval` and `approved`.
|
|
285
|
+
*/
|
|
286
|
+
export declare function isFinalToolCallStatus(status: AgentToolCallStatus): boolean;
|
|
287
|
+
/** Tool result text the model sees for an `outcome_unknown` call; the same text as the Python core. */
|
|
288
|
+
export declare const outcomeUnknownToolResult: string;
|
|
289
|
+
/** First line of the note `RecordTurnFailure` stores after a failed turn ran tools. */
|
|
290
|
+
export declare const turnFailureNoteHeader = "[Dex] The previous turn failed after these tool calls ran:";
|
|
291
|
+
/** Last line of that note. */
|
|
292
|
+
export declare const turnFailureNoteFooter = "Do not repeat these tool calls unless the user asks again.";
|
|
293
|
+
/** Tool result text the model sees for a rejection without a message; the same text as the Python core. */
|
|
294
|
+
export declare const defaultRejectionToolResult = "The user rejected this tool call.";
|
|
295
|
+
/** Rejection message recorded when an approval deadline passes. */
|
|
296
|
+
export declare const approvalDeadlinePassed = "approval deadline passed";
|
|
297
|
+
/**
|
|
298
|
+
* Returns the note text that tells the model what a failed turn already did.
|
|
299
|
+
*
|
|
300
|
+
* `RecordTurnFailure` stores this note through {@link AgentFrameworkRunner.buildUserMessage} when a
|
|
301
|
+
* failed turn has final tool call records, as the failed turn's last message, so the next turn's model
|
|
302
|
+
* does not repeat a write. The text matches the Python core's `build_turn_failure_note`:
|
|
303
|
+
*
|
|
304
|
+
* ```text
|
|
305
|
+
* [Dex] The previous turn failed after these tool calls ran:
|
|
306
|
+
* - charge {"amount": 5} -> succeeded: charged 5
|
|
307
|
+
* Do not repeat these tool calls unless the user asks again.
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @param toolCalls - Final records of the failed turn; they are listed in `deferralOrder`.
|
|
311
|
+
* @returns {@link turnFailureNoteHeader}, one `- <toolName> <arguments> -> <status>: <outcome>` line
|
|
312
|
+
* per record, with the outcome from {@link describeToolCallOutcome}, and {@link turnFailureNoteFooter},
|
|
313
|
+
* joined with newlines.
|
|
314
|
+
* @throws {TypeError} When a record is not final.
|
|
315
|
+
*/
|
|
316
|
+
export declare function buildTurnFailureNote(toolCalls: readonly AgentToolCall[]): string;
|
|
317
|
+
/**
|
|
318
|
+
* Returns the tool result text a runner shows the model for a final tool call record.
|
|
319
|
+
*
|
|
320
|
+
* Use it when resuming a framework whose tool result must be text. A runner whose framework has a
|
|
321
|
+
* native rejection, such as a rejection message argument, may pass `rejectionMessage` there instead.
|
|
322
|
+
* The texts match the Python core's `describe_tool_call_outcome`.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* const record = turn.recordedToolCall(pendingCallId);
|
|
327
|
+
* if (record !== undefined && isFinalToolCallStatus(record.status)) {
|
|
328
|
+
* frameworkToolResult = describeToolCallOutcome(record);
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
331
|
+
* @param toolCall - Record whose status is final.
|
|
332
|
+
* @returns The output for `succeeded`; `The tool call failed: <error>` for `failed`; the rejection
|
|
333
|
+
* message, or {@link defaultRejectionToolResult}, for `rejected`; {@link outcomeUnknownToolResult}
|
|
334
|
+
* for `outcome_unknown`.
|
|
335
|
+
* @throws {TypeError} When the record status is `awaiting_approval` or `approved`.
|
|
336
|
+
*/
|
|
337
|
+
export declare function describeToolCallOutcome(toolCall: AgentToolCall): string;
|