@superdurable/dex-agents 0.1.0 → 0.3.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/README.md +1608 -64
- package/dist/src/agent-built-in-tools.d.ts +81 -0
- package/dist/src/agent-built-in-tools.js +246 -0
- package/dist/src/agent-built-in-tools.js.map +1 -0
- package/dist/src/agent-context-compaction.d.ts +254 -0
- package/dist/src/agent-context-compaction.js +287 -0
- package/dist/src/agent-context-compaction.js.map +1 -0
- package/dist/src/agent-framework-runner.d.ts +456 -16
- package/dist/src/agent-framework-runner.js +4 -3
- package/dist/src/agent-framework-runner.js.map +1 -1
- package/dist/src/agent-plans.d.ts +48 -0
- package/dist/src/agent-plans.js +86 -0
- package/dist/src/agent-plans.js.map +1 -0
- package/dist/src/agent-session-cancellation-steps.d.ts +28 -0
- package/dist/src/agent-session-cancellation-steps.js +154 -0
- package/dist/src/agent-session-cancellation-steps.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +65 -4
- package/dist/src/agent-session-codecs.js +343 -8
- package/dist/src/agent-session-codecs.js.map +1 -1
- package/dist/src/agent-session-failure.d.ts +58 -0
- package/dist/src/agent-session-failure.js +126 -0
- package/dist/src/agent-session-failure.js.map +1 -0
- package/dist/src/agent-session-flow-graph-cli.d.ts +2 -0
- package/dist/src/agent-session-flow-graph-cli.js +47 -0
- package/dist/src/agent-session-flow-graph-cli.js.map +1 -0
- package/dist/src/agent-session-flow-graph.d.ts +38 -0
- package/dist/src/agent-session-flow-graph.js +54 -0
- package/dist/src/agent-session-flow-graph.js.map +1 -0
- package/dist/src/agent-session-flow-graph.json +2187 -0
- package/dist/src/agent-session-flow.d.ts +317 -28
- package/dist/src/agent-session-flow.js +373 -21
- package/dist/src/agent-session-flow.js.map +1 -1
- package/dist/src/agent-session-persistence.d.ts +81 -4
- package/dist/src/agent-session-persistence.js +33 -2
- package/dist/src/agent-session-persistence.js.map +1 -1
- package/dist/src/agent-session-settings.d.ts +58 -0
- package/dist/src/agent-session-settings.js +81 -0
- package/dist/src/agent-session-settings.js.map +1 -0
- package/dist/src/agent-session-spend-limit.d.ts +156 -0
- package/dist/src/agent-session-spend-limit.js +42 -0
- package/dist/src/agent-session-spend-limit.js.map +1 -0
- package/dist/src/agent-session-start.d.ts +49 -0
- package/dist/src/agent-session-start.js +67 -0
- package/dist/src/agent-session-start.js.map +1 -0
- package/dist/src/agent-session-step-options.d.ts +78 -0
- package/dist/src/agent-session-step-options.js +71 -0
- package/dist/src/agent-session-step-options.js.map +1 -0
- package/dist/src/agent-session-step-types.d.ts +20 -0
- package/dist/src/agent-session-step-types.js +28 -0
- package/dist/src/agent-session-step-types.js.map +1 -0
- package/dist/src/agent-session-steps.d.ts +103 -8
- package/dist/src/agent-session-steps.js +997 -197
- package/dist/src/agent-session-steps.js.map +1 -1
- package/dist/src/agent-session-tracer.d.ts +61 -0
- package/dist/src/agent-session-tracer.js +608 -0
- package/dist/src/agent-session-tracer.js.map +1 -0
- package/dist/src/agent-session-transitions.d.ts +200 -26
- package/dist/src/agent-session-transitions.js +732 -32
- package/dist/src/agent-session-transitions.js.map +1 -1
- package/dist/src/agent-session-values.d.ts +696 -30
- package/dist/src/agent-session-values.js +39 -4
- package/dist/src/agent-session-values.js.map +1 -1
- package/dist/src/agent-session-wait-steps.d.ts +53 -0
- package/dist/src/agent-session-wait-steps.js +389 -0
- package/dist/src/agent-session-wait-steps.js.map +1 -0
- package/dist/src/agent-tracing-options.d.ts +107 -0
- package/dist/src/agent-tracing-options.js +20 -0
- package/dist/src/agent-tracing-options.js.map +1 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +40 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js +235 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -0
- package/dist/src/ai-sdk/index.d.ts +1 -0
- package/dist/src/ai-sdk/index.js +9 -0
- package/dist/src/ai-sdk/index.js.map +1 -0
- package/dist/src/index.d.ts +14 -3
- package/dist/src/index.js +12 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/index.d.ts +3 -0
- package/dist/src/mcp/index.js +10 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.d.ts +29 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js +185 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js.map +1 -0
- package/dist/src/mcp/mcp-server-config.d.ts +86 -0
- package/dist/src/mcp/mcp-server-config.js +38 -0
- package/dist/src/mcp/mcp-server-config.js.map +1 -0
- package/dist/src/mcp/mcp-tool-source.d.ts +470 -0
- package/dist/src/mcp/mcp-tool-source.js +1204 -0
- package/dist/src/mcp/mcp-tool-source.js.map +1 -0
- package/dist/src/stepwise/agent-definition.d.ts +166 -0
- package/dist/src/stepwise/agent-definition.js +9 -0
- package/dist/src/stepwise/agent-definition.js.map +1 -0
- package/dist/src/stepwise/function-tool.d.ts +130 -0
- package/dist/src/stepwise/function-tool.js +75 -0
- package/dist/src/stepwise/function-tool.js.map +1 -0
- package/dist/src/stepwise/index.d.ts +8 -0
- package/dist/src/stepwise/index.js +13 -0
- package/dist/src/stepwise/index.js.map +1 -0
- package/dist/src/stepwise/json-schema-validation.d.ts +9 -0
- package/dist/src/stepwise/json-schema-validation.js +141 -0
- package/dist/src/stepwise/json-schema-validation.js.map +1 -0
- package/dist/src/stepwise/model-client.d.ts +194 -0
- package/dist/src/stepwise/model-client.js +9 -0
- package/dist/src/stepwise/model-client.js.map +1 -0
- package/dist/src/stepwise/scripted-model-client.d.ts +99 -0
- package/dist/src/stepwise/scripted-model-client.js +156 -0
- package/dist/src/stepwise/scripted-model-client.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-runner.d.ts +171 -0
- package/dist/src/stepwise/stepwise-agent-runner.js +777 -0
- package/dist/src/stepwise/stepwise-agent-runner.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +35 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js +57 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js.map +1 -0
- package/dist/src/stepwise/stepwise-input-items.d.ts +12 -0
- package/dist/src/stepwise/stepwise-input-items.js +172 -0
- package/dist/src/stepwise/stepwise-input-items.js.map +1 -0
- package/dist/src/stepwise/tool-source.d.ts +103 -0
- package/dist/src/stepwise/tool-source.js +9 -0
- package/dist/src/stepwise/tool-source.js.map +1 -0
- package/dist/src/testing/agent-session-test-client.d.ts +65 -8
- package/dist/src/testing/agent-session-test-client.js +92 -22
- package/dist/src/testing/agent-session-test-client.js.map +1 -1
- package/dist/src/testing/context-window.d.ts +194 -0
- package/dist/src/testing/context-window.js +360 -0
- package/dist/src/testing/context-window.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +2 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/private-dex-engine.d.ts +9 -0
- package/dist/src/testing/private-dex-engine.js +9 -1
- package/dist/src/testing/private-dex-engine.js.map +1 -1
- package/dist/src/testing/scripted-model-client.d.ts +1 -0
- package/dist/src/testing/scripted-model-client.js +10 -0
- package/dist/src/testing/scripted-model-client.js.map +1 -0
- package/dist/src/ui-stream/agent-event-json.d.ts +30 -0
- package/dist/src/ui-stream/agent-event-json.js +64 -0
- package/dist/src/ui-stream/agent-event-json.js.map +1 -0
- package/dist/src/ui-stream/agent-event-sse.d.ts +155 -0
- package/dist/src/ui-stream/agent-event-sse.js +167 -0
- package/dist/src/ui-stream/agent-event-sse.js.map +1 -0
- package/dist/src/ui-stream/agent-event-stream-positions.d.ts +42 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js +153 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js.map +1 -0
- package/dist/src/ui-stream/agent-session-record-reader.d.ts +74 -0
- package/dist/src/ui-stream/agent-session-record-reader.js +246 -0
- package/dist/src/ui-stream/agent-session-record-reader.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.d.ts +219 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js +441 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream.d.ts +138 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js +695 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-types.d.ts +238 -0
- package/dist/src/ui-stream/agent-ui-message-types.js +57 -0
- package/dist/src/ui-stream/agent-ui-message-types.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-messages.d.ts +68 -0
- package/dist/src/ui-stream/agent-ui-messages.js +222 -0
- package/dist/src/ui-stream/agent-ui-messages.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.d.ts +64 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js +186 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js.map +1 -0
- package/dist/src/ui-stream/index.d.ts +14 -0
- package/dist/src/ui-stream/index.js +22 -0
- package/dist/src/ui-stream/index.js.map +1 -0
- package/dist/src/ui-stream/server-sent-event-responses.d.ts +6 -0
- package/dist/src/ui-stream/server-sent-event-responses.js +34 -0
- package/dist/src/ui-stream/server-sent-event-responses.js.map +1 -0
- package/package.json +44 -5
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type ContextSummaryRequest, type ContextSummaryResult } from "../agent-context-compaction.js";
|
|
2
|
+
export { buildContextSummaryNote, buildContextSummaryOmissionNote, contextSummaryInstructions, contextSummaryNoteHeader, contextSummaryRequest, } from "../agent-context-compaction.js";
|
|
3
|
+
import { type AgentFrameworkRunner, type AgentTurnContext, type AgentTurnOutcome, type DeferredToolExecution, type DeferredToolOutcome, type ToolTaskCancellation, type ToolTaskPoll, type ToolTaskPollOutcome } from "../agent-framework-runner.js";
|
|
4
|
+
import { type FrameworkMessage } from "../agent-session-values.js";
|
|
5
|
+
import type { AgentDefinition } from "./agent-definition.js";
|
|
6
|
+
/** Default {@link AgentDefinition.toolSourceListingTimeoutMs}: 10 seconds. */
|
|
7
|
+
export declare const defaultToolSourceListingTimeoutMs = 10000;
|
|
8
|
+
export declare const defaultMaxModelCallsPerTurn = 100;
|
|
9
|
+
/** Result of a tool call the model made after the turn's model call limit; the same text as the Python core. */
|
|
10
|
+
export declare function buildToolCallLimitReachedResult(maxModelCallsPerTurn: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* The {@link AgentFrameworkRunner} of the built-in Stepwise loop.
|
|
13
|
+
*
|
|
14
|
+
* {@link createStepwiseAgentSessionFlow} creates one; construct it directly only to pass it to
|
|
15
|
+
* `createAgentSessionFlow` with options of your own. Each `RunModel` makes at most one model call
|
|
16
|
+
* through {@link AgentDefinition.model}, from committed state only: the stored messages, the results
|
|
17
|
+
* of the previous model response from the turn's final records, and the instructions. The runner
|
|
18
|
+
* stores the turn's transcript as it goes through {@link ToolCallsRequested.newMessages}, so a long turn
|
|
19
|
+
* never rewrites a growing run state. It supports plan mode: a `planning` turn offers only `write_todos`, and
|
|
20
|
+
* every model call shows the plan with {@link buildPlanNote} before the turn's messages. It implements the
|
|
21
|
+
* compaction methods, so a session with a compaction policy starts the model input with the summary. Its
|
|
22
|
+
* {@link pollToolTask} passes a tool task to the {@link ToolSource} that started it; function tools start no
|
|
23
|
+
* tasks. Its {@link cancelToolTask} passes a task that `cancel_turn` abandoned to that source's optional
|
|
24
|
+
* `cancelToolTask`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const runner = new StepwiseAgentRunner(definition);
|
|
29
|
+
* const flow = createAgentSessionFlow(runner, "SupportAgent", { builtInTools: ["ask_user"] });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class StepwiseAgentRunner implements AgentFrameworkRunner<DeferredToolOutcome> {
|
|
33
|
+
/** The agent definition, frozen at construction. */
|
|
34
|
+
readonly definition: AgentDefinition;
|
|
35
|
+
/** The runner honors {@link AgentTurnContext.interactionMode}, so plan mode can be enabled. */
|
|
36
|
+
readonly supportsPlanMode = true;
|
|
37
|
+
private readonly functionToolsByName;
|
|
38
|
+
private readonly toolSources;
|
|
39
|
+
private readonly toolSourcesByName;
|
|
40
|
+
private readonly maxModelCallsPerTurn;
|
|
41
|
+
private readonly toolSourceListingTimeoutMs;
|
|
42
|
+
/** The last listing of each source, so estimates count its tools without listing again. */
|
|
43
|
+
private readonly lastListings;
|
|
44
|
+
/**
|
|
45
|
+
* Creates the runner and checks the definition.
|
|
46
|
+
* @param definition - The agent definition.
|
|
47
|
+
* @throws {TypeError} When the name, instructions, model, or tools are invalid, two tools share a
|
|
48
|
+
* name, a function tool uses the name of an enabled built-in tool, `planModeEnabled` is set without
|
|
49
|
+
* `write_todos`, `planningToolChoice` is neither `auto` nor `required`, or a tool source lacks a
|
|
50
|
+
* {@link ToolSource} method.
|
|
51
|
+
* @throws {RangeError} When `maxModelCallsPerTurn` is not a positive integer.
|
|
52
|
+
*/
|
|
53
|
+
constructor(definition: AgentDefinition);
|
|
54
|
+
/**
|
|
55
|
+
* Converts user text into a stored `user_text` item.
|
|
56
|
+
* @param text - User message text.
|
|
57
|
+
* @returns The message with role `user`.
|
|
58
|
+
*/
|
|
59
|
+
buildUserMessage(text: string): FrameworkMessage;
|
|
60
|
+
/**
|
|
61
|
+
* Makes the turn's next model call.
|
|
62
|
+
* @param turn - The turn context.
|
|
63
|
+
* @returns {@link TurnCompleted} with the results and final answer not stored yet, or
|
|
64
|
+
* {@link ToolCallsRequested} with the previous results, this response, and its tool calls.
|
|
65
|
+
* @throws {TypeError} When a function tool uses the name of an enabled built-in tool, or a tool source lists a
|
|
66
|
+
* name that repeats a function tool, an enabled built-in tool, or another source's tool. No model request is
|
|
67
|
+
* made.
|
|
68
|
+
* @throws Any error of the model call or of a tool source's `listTools`, which retries the `RunModel` attempt.
|
|
69
|
+
*/
|
|
70
|
+
runModelStep(turn: AgentTurnContext): Promise<AgentTurnOutcome>;
|
|
71
|
+
/**
|
|
72
|
+
* Runs one function tool call after checking its arguments against the tool's schema, or passes a call that a
|
|
73
|
+
* tool source built in `runModelStep` to that source, with the source's own `toolSourceReference` and without a
|
|
74
|
+
* listing. Any other name is an unknown tool and never reaches a source.
|
|
75
|
+
* @param call - The deferred call.
|
|
76
|
+
* @returns The output: a `string` result unchanged, any other result as JSON; the tool's
|
|
77
|
+
* {@link ToolInputRequested}; or a source's outcome, such as {@link ToolTaskStarted}.
|
|
78
|
+
* @throws {ToolExecutionError} For an unknown tool, arguments that are not a JSON object or break the
|
|
79
|
+
* schema, or a `ToolExecutionError` from the tool or its source.
|
|
80
|
+
* @throws {RangeError} When a source built the call but the definition no longer has it, so the effect decides
|
|
81
|
+
* the outcome.
|
|
82
|
+
* @throws Any other error of the tool source.
|
|
83
|
+
*/
|
|
84
|
+
executeDeferredToolCall(call: DeferredToolExecution): Promise<DeferredToolOutcome>;
|
|
85
|
+
/**
|
|
86
|
+
* Polls a tool source's task once, through the source that built the call.
|
|
87
|
+
* @param poll - The call's record from `PollToolTask`.
|
|
88
|
+
* @returns The source's `pollToolTask` outcome.
|
|
89
|
+
* @throws {RangeError} When no tool source built the call. The task may still run, so `PollToolTask` retries
|
|
90
|
+
* and then records the call by its effect.
|
|
91
|
+
* @throws Any error of the source.
|
|
92
|
+
*/
|
|
93
|
+
pollToolTask(poll: ToolTaskPoll): Promise<ToolTaskPollOutcome>;
|
|
94
|
+
/**
|
|
95
|
+
* Cancels a tool source's task through the source that built the call; a source without `cancelToolTask` leaves
|
|
96
|
+
* its task running.
|
|
97
|
+
* @param cancellation - The abandoned call's record from `CancelToolTask`.
|
|
98
|
+
* @returns A Promise that resolves once the source took the cancellation.
|
|
99
|
+
* @throws {RangeError} When no tool source built the call; `CancelToolTask` retries and then records the call
|
|
100
|
+
* `outcome_unknown`.
|
|
101
|
+
* @throws Any error of the source.
|
|
102
|
+
*/
|
|
103
|
+
cancelToolTask(cancellation: ToolTaskCancellation): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the results of the turn's tool calls that are not stored yet.
|
|
106
|
+
* @param turn - The ended turn, with every record final.
|
|
107
|
+
* @returns One `tool_result` message per unstored result, in deferral order.
|
|
108
|
+
*/
|
|
109
|
+
buildUnfinishedTurnMessages(turn: AgentTurnContext): readonly FrameworkMessage[];
|
|
110
|
+
/**
|
|
111
|
+
* Estimates the model input of the next `runModelStep` with the model client.
|
|
112
|
+
* @param turn - The context of the next model call.
|
|
113
|
+
* @returns `ModelClient.estimateInputTokens` of the request `runModelStep` would send: instructions,
|
|
114
|
+
* summary, messages, unstored tool results, and tools. Tool source tools come from each source's `cachedTools`
|
|
115
|
+
* when it has one, else from the runner's last listing, as in the Python core.
|
|
116
|
+
*/
|
|
117
|
+
estimateInputTokens(turn: AgentTurnContext): Promise<number>;
|
|
118
|
+
/**
|
|
119
|
+
* Chooses the last message to summarize, at a boundary between model responses.
|
|
120
|
+
*
|
|
121
|
+
* The runner cuts only before a user message or before the first output item of a model response whose
|
|
122
|
+
* earlier tool calls all have stored results, so no tool call is separated from its result and no
|
|
123
|
+
* response is split. It keeps the newest messages that fit the budget, and never summarizes the newest
|
|
124
|
+
* stored message.
|
|
125
|
+
*
|
|
126
|
+
* @param turn - The context of the model call that crossed the threshold.
|
|
127
|
+
* @param retainedTokenBudget - Tokens that the kept messages may use.
|
|
128
|
+
* @returns The sequence of the last message to summarize: the earliest cut whose kept messages fit the
|
|
129
|
+
* budget, else the latest cut; `null` when every message already fits or no cut is possible.
|
|
130
|
+
*/
|
|
131
|
+
selectCompactionCutoff(turn: AgentTurnContext, retainedTokenBudget: number): number | null;
|
|
132
|
+
/**
|
|
133
|
+
* Folds the previous summary and the messages of the range into new text, with one model call.
|
|
134
|
+
*
|
|
135
|
+
* The call uses {@link contextSummaryInstructions}, no tools, the previous summary as a note, the
|
|
136
|
+
* range's items, and {@link contextSummaryRequest} as the last user text. Its text streams nowhere,
|
|
137
|
+
* because it is not the assistant's answer. When the request would exceed `request.inputTokenBudget`,
|
|
138
|
+
* such as after a smaller context window or when compaction starts on a long session, the runner leaves
|
|
139
|
+
* out the oldest items of the range and says so with {@link buildContextSummaryOmissionNote}, so the
|
|
140
|
+
* call and its `maxOutputTokens`, when set, still fit. It leaves them out up to a boundary between model responses, as
|
|
141
|
+
* {@link selectCompactionCutoff} cuts, so it never splits a response or separates a tool call from its
|
|
142
|
+
* result.
|
|
143
|
+
*
|
|
144
|
+
* @param request - The previous summary and the messages to summarize.
|
|
145
|
+
* @returns The response text and the usage of the call.
|
|
146
|
+
* @throws {Error} When the model returned no text, or any error of the model call.
|
|
147
|
+
*/
|
|
148
|
+
summarizeContext(request: ContextSummaryRequest): Promise<ContextSummaryResult>;
|
|
149
|
+
private buildSummaryRequest;
|
|
150
|
+
private buildModelRequest;
|
|
151
|
+
private estimateItems;
|
|
152
|
+
/** A built-in enabled only in the session options must not share a function tool's name. */
|
|
153
|
+
private requireNoBuiltInToolNameClash;
|
|
154
|
+
private listSourceTools;
|
|
155
|
+
private listOneSource;
|
|
156
|
+
private readCachedSourceTools;
|
|
157
|
+
private routeToToolSource;
|
|
158
|
+
private listOfferedTools;
|
|
159
|
+
/** A session policy wins; otherwise a function tool's own effect and approval apply, as in the Python core. */
|
|
160
|
+
private resolveModelToolPolicy;
|
|
161
|
+
private resolveModel;
|
|
162
|
+
private resolveInstructions;
|
|
163
|
+
}
|
|
164
|
+
/** Error of a call to a tool that no function tool or source listing offers; the same text as the Python core. */
|
|
165
|
+
export declare function buildUnknownToolError(toolName: string): string;
|
|
166
|
+
/** The runner's `toolSourceReference`: the source's name and its own reference, as JSON text. */
|
|
167
|
+
export declare function writeToolSourceEnvelope(sourceName: string, reference: string | undefined): string;
|
|
168
|
+
export declare function readToolSourceEnvelope(toolSourceReference: string | undefined): {
|
|
169
|
+
readonly sourceName: string;
|
|
170
|
+
readonly reference: string | undefined;
|
|
171
|
+
} | undefined;
|