@slopus/happy-agent-base 0.0.0 → 0.0.2
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 +21 -0
- package/README.md +640 -15
- package/dist/Agent.d.ts +86 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +326 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentBase.d.ts +340 -0
- package/dist/AgentBase.d.ts.map +1 -0
- package/dist/AgentBase.js +2295 -0
- package/dist/AgentBase.js.map +1 -0
- package/dist/AgentBaseHooks.d.ts +156 -0
- package/dist/AgentBaseHooks.d.ts.map +1 -0
- package/dist/AgentBaseHooks.js +2 -0
- package/dist/AgentBaseHooks.js.map +1 -0
- package/dist/AgentBasePending.d.ts +49 -0
- package/dist/AgentBasePending.d.ts.map +1 -0
- package/dist/AgentBasePending.js +73 -0
- package/dist/AgentBasePending.js.map +1 -0
- package/dist/AgentBaseState.d.ts +13 -0
- package/dist/AgentBaseState.d.ts.map +1 -0
- package/dist/AgentBaseState.js +2 -0
- package/dist/AgentBaseState.js.map +1 -0
- package/dist/AgentBaseStoreLock.d.ts +16 -0
- package/dist/AgentBaseStoreLock.d.ts.map +1 -0
- package/dist/AgentBaseStoreLock.js +37 -0
- package/dist/AgentBaseStoreLock.js.map +1 -0
- package/dist/AgentConfig.d.ts +67 -0
- package/dist/AgentConfig.d.ts.map +1 -0
- package/dist/AgentConfig.js +81 -0
- package/dist/AgentConfig.js.map +1 -0
- package/dist/AgentContexts.d.ts +40 -0
- package/dist/AgentContexts.d.ts.map +1 -0
- package/dist/AgentContexts.js +70 -0
- package/dist/AgentContexts.js.map +1 -0
- package/dist/AgentFeature.d.ts +119 -0
- package/dist/AgentFeature.d.ts.map +1 -0
- package/dist/AgentFeature.js +2 -0
- package/dist/AgentFeature.js.map +1 -0
- package/dist/AgentFeatureAction.d.ts +16 -0
- package/dist/AgentFeatureAction.d.ts.map +1 -0
- package/dist/AgentFeatureAction.js +2 -0
- package/dist/AgentFeatureAction.js.map +1 -0
- package/dist/AgentKV.d.ts +63 -0
- package/dist/AgentKV.d.ts.map +1 -0
- package/dist/AgentKV.js +122 -0
- package/dist/AgentKV.js.map +1 -0
- package/dist/AgentModel.d.ts +17 -0
- package/dist/AgentModel.d.ts.map +1 -0
- package/dist/AgentModel.js +2 -0
- package/dist/AgentModel.js.map +1 -0
- package/dist/AgentPersistence.d.ts +95 -0
- package/dist/AgentPersistence.d.ts.map +1 -0
- package/dist/AgentPersistence.js +2 -0
- package/dist/AgentPersistence.js.map +1 -0
- package/dist/AgentProviders.d.ts +22 -0
- package/dist/AgentProviders.d.ts.map +1 -0
- package/dist/AgentProviders.js +35 -0
- package/dist/AgentProviders.js.map +1 -0
- package/dist/AgentRef.d.ts +41 -0
- package/dist/AgentRef.d.ts.map +1 -0
- package/dist/AgentRef.js +60 -0
- package/dist/AgentRef.js.map +1 -0
- package/dist/AgentStorage.d.ts +19 -0
- package/dist/AgentStorage.d.ts.map +1 -0
- package/dist/AgentStorage.js +16 -0
- package/dist/AgentStorage.js.map +1 -0
- package/dist/AgentSystem.d.ts +50 -0
- package/dist/AgentSystem.d.ts.map +1 -0
- package/dist/AgentSystem.js +2 -0
- package/dist/AgentSystem.js.map +1 -0
- package/dist/AgentSystemContext.d.ts +15 -0
- package/dist/AgentSystemContext.d.ts.map +1 -0
- package/dist/AgentSystemContext.js +20 -0
- package/dist/AgentSystemContext.js.map +1 -0
- package/dist/AgentSystemLocal.d.ts +103 -0
- package/dist/AgentSystemLocal.d.ts.map +1 -0
- package/dist/AgentSystemLocal.js +282 -0
- package/dist/AgentSystemLocal.js.map +1 -0
- package/dist/AgentSystemRef.d.ts +56 -0
- package/dist/AgentSystemRef.d.ts.map +1 -0
- package/dist/AgentSystemRef.js +75 -0
- package/dist/AgentSystemRef.js.map +1 -0
- package/dist/AgentTaskContext.d.ts +17 -0
- package/dist/AgentTaskContext.d.ts.map +1 -0
- package/dist/AgentTaskContext.js +26 -0
- package/dist/AgentTaskContext.js.map +1 -0
- package/dist/AgentTool.d.ts +87 -0
- package/dist/AgentTool.d.ts.map +1 -0
- package/dist/AgentTool.js +5 -0
- package/dist/AgentTool.js.map +1 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +62 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +185 -0
- package/dist/models.js.map +1 -0
- package/package.json +44 -37
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import type { SessionReasoningEffort, SessionServiceTier, SessionUserMessage } from "@slopus/happy-providers";
|
|
2
|
+
import { type Context } from "@steve.kite/stdlib";
|
|
3
|
+
import type { AgentBaseHooks } from "./AgentBaseHooks.js";
|
|
4
|
+
import type { AgentPersistence } from "./AgentPersistence.js";
|
|
5
|
+
import type { AgentBaseState } from "./AgentBaseState.js";
|
|
6
|
+
import { AgentProviders } from "./AgentProviders.js";
|
|
7
|
+
/** How a message queue drains: one message per model response, or every queued message at once. */
|
|
8
|
+
export type AgentBaseQueueMode = "one-at-a-time" | "all";
|
|
9
|
+
/**
|
|
10
|
+
* Inference settings carried by a queued message. An omitted field keeps the previously
|
|
11
|
+
* effective value; the first message without a value falls back to the constructor default,
|
|
12
|
+
* though relying on that default is discouraged — prefer sending settings with the message.
|
|
13
|
+
*/
|
|
14
|
+
export interface AgentBaseMessageOptions {
|
|
15
|
+
/** The registry ID of the provider to switch to. */
|
|
16
|
+
readonly provider?: string;
|
|
17
|
+
/** The model to switch to; an incompatible one resets the conversation. */
|
|
18
|
+
readonly model?: string;
|
|
19
|
+
/** How hard the model should think about the request. */
|
|
20
|
+
readonly effort?: SessionReasoningEffort;
|
|
21
|
+
/** Which of the provider's service tiers to bill and schedule the request on. */
|
|
22
|
+
readonly serviceTier?: SessionServiceTier;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether an operation resolves once the agent has taken the request on, or once the agent has
|
|
26
|
+
* carried it out. Every operation that asks something of an agent accepts this, and every one of
|
|
27
|
+
* them defaults to the first: asking is the operation, and waiting is opt-in.
|
|
28
|
+
*
|
|
29
|
+
* The reason is re-entrancy. An agent does its work in one run loop, and while a hook or a tool
|
|
30
|
+
* runs, that loop is waiting for it — so code in that position that waits for its own agent waits
|
|
31
|
+
* for itself. Rather than offer some operations in a waiting form and others not, every operation
|
|
32
|
+
* returns as soon as the request is registered, and `await: true` asks for the rest. That flag is
|
|
33
|
+
* refused, loudly, when the caller's context says it is running inside the loop of the very agent
|
|
34
|
+
* it is asking, which is the only case where the wait could never end.
|
|
35
|
+
*/
|
|
36
|
+
export interface AgentBaseAwaitOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Wait for the operation to finish rather than for it to be accepted. Refused from inside the
|
|
39
|
+
* agent's own run loop.
|
|
40
|
+
*/
|
|
41
|
+
readonly await?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Everything an agent session is constructed with; only the identity and store are required. */
|
|
44
|
+
export interface AgentBaseOptions {
|
|
45
|
+
/** Stable session identity supplied by the caller. */
|
|
46
|
+
readonly id: string;
|
|
47
|
+
/** The registry providers are resolved from, at session creation time. */
|
|
48
|
+
readonly providers: AgentProviders;
|
|
49
|
+
/** The registry ID of the provider to use; serializable alongside model and effort. */
|
|
50
|
+
readonly provider: string;
|
|
51
|
+
/** The append-only store the conversation, the queues, and the settings live in. */
|
|
52
|
+
readonly persistence: AgentPersistence;
|
|
53
|
+
/** Observers and correctness hooks the run is assembled from; `Agent` merges features here. */
|
|
54
|
+
readonly hooks?: AgentBaseHooks;
|
|
55
|
+
/** Copied into the agent's own mutable `state`. */
|
|
56
|
+
readonly initialState?: Partial<AgentBaseState>;
|
|
57
|
+
/** The initial model, superseded by the first message that carries one. */
|
|
58
|
+
readonly model?: string;
|
|
59
|
+
/** The initial reasoning effort, superseded by the first message that carries one. */
|
|
60
|
+
readonly effort?: SessionReasoningEffort;
|
|
61
|
+
/** The initial service tier, superseded by the first message that carries one. */
|
|
62
|
+
readonly serviceTier?: SessionServiceTier;
|
|
63
|
+
/** How the steering queue drains; one message per response by default. */
|
|
64
|
+
readonly steeringMode?: AgentBaseQueueMode;
|
|
65
|
+
/** How the send queue drains; one message per response by default. */
|
|
66
|
+
readonly sendMode?: AgentBaseQueueMode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A single agent session over one provider. Messages arrive through two FIFO queues: steering
|
|
70
|
+
* messages inject as soon as the current assistant response and its tool batch finish, while
|
|
71
|
+
* sent messages wait until the agent would otherwise stop — no tool calls or steering remain.
|
|
72
|
+
* Each queue drains per its configured mode, and the conversation is durable through
|
|
73
|
+
* append-only persistence reloaded at the start of every turn.
|
|
74
|
+
*
|
|
75
|
+
* The rest of this comment is the list of promises the implementation has to keep. They are
|
|
76
|
+
* written down because most of them are invisible in ordinary use and only show themselves when
|
|
77
|
+
* a process dies, two owners share a store, or a caller races the loop — every one of them was
|
|
78
|
+
* bought with a bug found by `tests/chaos/`, and each has a focused test that fails without it.
|
|
79
|
+
*
|
|
80
|
+
* ## Serialization
|
|
81
|
+
*
|
|
82
|
+
* One lock serializes every persistence operation together with its in-memory effect, so storage
|
|
83
|
+
* order always matches history order and a load never overlaps an append. Anything that decides
|
|
84
|
+
* from durable state resolves that state inside the lock rather than capturing it beforehand; a
|
|
85
|
+
* reference taken before a wait can belong to a history that has since been replaced.
|
|
86
|
+
*
|
|
87
|
+
* ## Accepting a message
|
|
88
|
+
*
|
|
89
|
+
* A message is accepted exactly once, or not at all. Its durable write and the writes of every
|
|
90
|
+
* other message in the same batch commit in one transaction under one hold of the lock. So:
|
|
91
|
+
*
|
|
92
|
+
* - `steer` and `send` with `await: true` resolve only once the message is durable; a failed
|
|
93
|
+
* write keeps it out of the conversation entirely. Without the flag they return early, but the
|
|
94
|
+
* acceptance is the same one, and a close still waits for it.
|
|
95
|
+
* - Messages a hook returns from one decision are accepted as one batch. A caller arriving while
|
|
96
|
+
* that batch is being written lands after all of it, never between two halves of one thought.
|
|
97
|
+
* - Queue keys order by what the store already holds and end in a segment identifying their
|
|
98
|
+
* writer, so two owners accepting in the same millisecond may order arbitrarily but can never
|
|
99
|
+
* overwrite one another.
|
|
100
|
+
* - An agent holding a durable message never describes itself as settled.
|
|
101
|
+
*
|
|
102
|
+
* ## Consuming a message
|
|
103
|
+
*
|
|
104
|
+
* A consumption claims each entry with an atomic delete inside its own transaction, so one
|
|
105
|
+
* durable message is answered exactly once however many live owners hold it in memory. A batch
|
|
106
|
+
* that claims nothing rolls back having changed nothing. A message is never durable in both the
|
|
107
|
+
* queue and the context, or in neither, and memory changes only after the commit.
|
|
108
|
+
*
|
|
109
|
+
* ## Turns
|
|
110
|
+
*
|
|
111
|
+
* A turn answers the durable conversation, not the one this instance remembers: it reloads
|
|
112
|
+
* before it decides anything, so an appended message or a model switch from another owner is in
|
|
113
|
+
* force by the next turn. A turn that consumes the last queued work clears the request it just
|
|
114
|
+
* answered, rather than buying an extra turn with an empty queue and a full set of hooks.
|
|
115
|
+
*
|
|
116
|
+
* ## Tool calls
|
|
117
|
+
*
|
|
118
|
+
* A batch runs its calls at the same time, each in its own persistence scope, and commits their
|
|
119
|
+
* results in batch order. Results are matched back by call ID, so a response that used one ID
|
|
120
|
+
* twice has no answer the model could tell apart: that ID is kept once and refused before
|
|
121
|
+
* anything runs, since a refusal after the fact would not undo the side effect.
|
|
122
|
+
*
|
|
123
|
+
* The conversation never keeps a tool call the model will not get an answer for:
|
|
124
|
+
*
|
|
125
|
+
* - A batch is committed before any call in it runs, so a batch found uncommitted after a crash
|
|
126
|
+
* has certainly not run and is dispatched as the fresh batch it never became.
|
|
127
|
+
* - A response that emits a call but does not end in one, and a turn that fails while owing
|
|
128
|
+
* results, settle their own calls with error results before appending anything behind them.
|
|
129
|
+
* - A conversation loaded with a call stranded under later messages is repaired atomically at
|
|
130
|
+
* load, since the answer belongs beside its call rather than at the end.
|
|
131
|
+
* - A non-durable tool never runs twice; a durable one may.
|
|
132
|
+
*
|
|
133
|
+
* ## Compaction
|
|
134
|
+
*
|
|
135
|
+
* A compaction runs before a turn's first inference, so the model always receives a settled
|
|
136
|
+
* conversation. It replaces the history whole or not at all, and the suffix it preserves is
|
|
137
|
+
* rebuilt from the store inside the commit — from a record count taken at the snapshot, so work
|
|
138
|
+
* another owner committed while the provider was summarizing survives. A compaction nobody will
|
|
139
|
+
* carry out is rejected rather than left waiting.
|
|
140
|
+
*
|
|
141
|
+
* ## Model changes
|
|
142
|
+
*
|
|
143
|
+
* An incompatible provider or model change resets the conversation; a compatible one keeps it.
|
|
144
|
+
* Either way the change lands on one side or the other, never the old history under the new
|
|
145
|
+
* model. `modelChanged` runs inside the lock and is lent a store bound to that hold — a
|
|
146
|
+
* capability released when the hook returns, so it cannot be retained to bypass the lock later.
|
|
147
|
+
* A failing handoff rejects an incompatible switch outright rather than costing the history.
|
|
148
|
+
*
|
|
149
|
+
* ## Recovery
|
|
150
|
+
*
|
|
151
|
+
* Whether a restart owes a response is decided by the last durable record: a consumed message, a
|
|
152
|
+
* tool result, or a failure note is owed an answer, while a replacement written by a compaction
|
|
153
|
+
* is not a question and gets none.
|
|
154
|
+
*
|
|
155
|
+
* ## Abort
|
|
156
|
+
*
|
|
157
|
+
* An abort owns the whole turn. Its scope opens before any of the turn's work — its hooks and its
|
|
158
|
+
* loading as much as its inference — so a turn cancelled while it is still starting up never
|
|
159
|
+
* reaches the model at all, rather than being cancelled only once it was already talking.
|
|
160
|
+
*
|
|
161
|
+
* What a cancelled turn leaves behind is fixed:
|
|
162
|
+
*
|
|
163
|
+
* - Assistant blocks that finished stay in the history; a block still being streamed is dropped,
|
|
164
|
+
* because half a block is not something the model said.
|
|
165
|
+
* - Tool calls still running are settled in the conversation as aborted error results, so the
|
|
166
|
+
* history owes nothing, and the turn ends without waiting for the tools themselves. A tool that
|
|
167
|
+
* never notices cancellation therefore cannot hold the cancellation open — but it is still
|
|
168
|
+
* running, so the *next* provider request waits for it before reusing the stateful session.
|
|
169
|
+
* - Messages already queued stay durable and join the next requested turn. An abort cancels the
|
|
170
|
+
* turn, not the work waiting for one.
|
|
171
|
+
* - A compaction requested during the turn is rejected rather than left pending, because dropping
|
|
172
|
+
* the turn request drops the only thing that would have carried it out.
|
|
173
|
+
* - Exactly one terminal event is reported. A cancellation seen after a response already reported
|
|
174
|
+
* its own outcome adds nothing, since that response is over.
|
|
175
|
+
*
|
|
176
|
+
* `abort` signals and returns, because the cancellation is complete once it is signalled.
|
|
177
|
+
* `abort(ctx, { await: true })` additionally waits for the loop to stop, which is what an owner
|
|
178
|
+
* outside the agent usually wants and what code inside it must not ask for — see below.
|
|
179
|
+
*
|
|
180
|
+
* ## Close
|
|
181
|
+
*
|
|
182
|
+
* Close is a barrier, published before any of the shutdown runs. Nothing new is admitted from
|
|
183
|
+
* the moment it is called; everything already admitted is written and answered, and only then is
|
|
184
|
+
* the provider session destroyed. Every caller shares that one shutdown, including one
|
|
185
|
+
* reentering from inside session destruction, so a session is never destroyed twice.
|
|
186
|
+
*
|
|
187
|
+
* ## Hooks
|
|
188
|
+
*
|
|
189
|
+
* Hooks observe the run and never fail it. Neither a throwing hook nor a failing hook-driven
|
|
190
|
+
* action ends a turn.
|
|
191
|
+
*
|
|
192
|
+
* ## Re-entrancy
|
|
193
|
+
*
|
|
194
|
+
* A hook or a tool runs while the loop is waiting for it, so anything it asks of its own agent
|
|
195
|
+
* that only the loop can deliver would wait for itself. Rather than leave that to be remembered
|
|
196
|
+
* per operation, asking and waiting are separated everywhere:
|
|
197
|
+
*
|
|
198
|
+
* - `steer`, `send`, `abort` and `compact` are safe from anywhere in their asking form, which is
|
|
199
|
+
* the default. Each registers what it registers and returns; the loop acts on it afterwards.
|
|
200
|
+
* - `await: true` asks for the part only the loop can give. Contexts handed to hooks and tools
|
|
201
|
+
* record which agents' loops the execution is inside, so the flag is refused with an error that
|
|
202
|
+
* names the problem instead of hanging. The check is per agent: work inside one agent's loop
|
|
203
|
+
* may still wait on another's, which is what makes a subagent's report to its parent safe.
|
|
204
|
+
* - The refusal is uniform even where a particular wait would have happened to work. A tool that
|
|
205
|
+
* waits for its own abort, for instance, does unwind — the batch races each execution against
|
|
206
|
+
* cancellation — but that is a property of tool batches rather than of abort, and a rule that
|
|
207
|
+
* holds only in one position is worse than no rule.
|
|
208
|
+
* - A hook that wants a compaction has a better option than requesting one: the
|
|
209
|
+
* `{ type: "compact" }` action it returns lands exactly where the loop can act on it, in order
|
|
210
|
+
* with the rest of that decision.
|
|
211
|
+
* - `close` and `waitForIdle` take no context, so they cannot be checked and will simply hang.
|
|
212
|
+
* Both are nothing but a wait for the run to finish. Close the agent from the caller that owns
|
|
213
|
+
* its lifetime.
|
|
214
|
+
*
|
|
215
|
+
* `AgentRef` and `AgentSystemRef` drop the two unguarded waits, and are what code running inside
|
|
216
|
+
* an agent should be handed.
|
|
217
|
+
*/
|
|
218
|
+
export declare class AgentBase {
|
|
219
|
+
#private;
|
|
220
|
+
/** The caller-supplied session identity: the name of this agent's store and of its loop. */
|
|
221
|
+
readonly id: string;
|
|
222
|
+
/**
|
|
223
|
+
* The agent's own copy of the initial state, mutable directly; every inference reads the
|
|
224
|
+
* current values.
|
|
225
|
+
*/
|
|
226
|
+
readonly state: AgentBaseState;
|
|
227
|
+
/**
|
|
228
|
+
* A new agent, wired to its options and touching no storage at all. Use this for an identity
|
|
229
|
+
* with no durable state yet; whatever the agent needs from the store is read by its first
|
|
230
|
+
* turn.
|
|
231
|
+
*/
|
|
232
|
+
static create(ctx: Context, options: AgentBaseOptions): Promise<AgentBase>;
|
|
233
|
+
/**
|
|
234
|
+
* An agent for an identity that may already have durable state, with the one externally
|
|
235
|
+
* meaningful fact about that state — whether it has work left — read before it is handed
|
|
236
|
+
* back, so `active` is answerable straight away.
|
|
237
|
+
*
|
|
238
|
+
* Only the flag is read. The conversation, the queues and the settings are deliberately not:
|
|
239
|
+
* they are needed by the first turn and by nothing before it, so an owner resuming a hundred
|
|
240
|
+
* identities at startup pays for a hundred small reads rather than a hundred transcripts.
|
|
241
|
+
* The rest loads on the way into the turn that actually needs it.
|
|
242
|
+
*/
|
|
243
|
+
static load(ctx: Context, options: AgentBaseOptions): Promise<AgentBase>;
|
|
244
|
+
/**
|
|
245
|
+
* Load the agent and set it going again if it has work left, or answer with nothing when it
|
|
246
|
+
* has none. This is how an owner coming up carries on whatever an earlier process was in the
|
|
247
|
+
* middle of: the whole question is one key, and an agent told to go picks its own work back
|
|
248
|
+
* up, so the caller has only to bring it into existence.
|
|
249
|
+
*
|
|
250
|
+
* An agent owing nothing is not handed back, because there is nothing to do with it that
|
|
251
|
+
* resolving it when something is actually wanted of it would not do better.
|
|
252
|
+
*/
|
|
253
|
+
static loadActive(ctx: Context, options: AgentBaseOptions): Promise<AgentBase | undefined>;
|
|
254
|
+
/**
|
|
255
|
+
* Build the agent from its options, without touching the store. Nothing is loaded here: the
|
|
256
|
+
* durable state is read by the first turn, so constructing one stays cheap even for a session
|
|
257
|
+
* nobody goes on to run. Private, because an agent is made by `create` or by `load`, and
|
|
258
|
+
* which of the two the caller means is worth saying.
|
|
259
|
+
*/
|
|
260
|
+
private constructor();
|
|
261
|
+
/**
|
|
262
|
+
* Whether the agent has anything left to do. This is the only thing about an agent's state
|
|
263
|
+
* anyone outside it may read: the queues and the stage behind this answer are the run's own
|
|
264
|
+
* business, and can be cleared but never inspected. Even this is rarely wanted — it is here
|
|
265
|
+
* for the owner deciding which agents a restarted process has to resume.
|
|
266
|
+
*/
|
|
267
|
+
get active(): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Queue a user message that injects as soon as the current assistant response and its tool
|
|
270
|
+
* batch finish; steering always takes precedence over sent messages. Returns once the message
|
|
271
|
+
* has been handed to the agent, which never waits for the turn that answers it; with
|
|
272
|
+
* `await: true` it returns once the durable write has landed instead, and a failed write both
|
|
273
|
+
* rejects and keeps the message out of the conversation entirely.
|
|
274
|
+
*/
|
|
275
|
+
steer(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Queue a user message that waits until the agent would otherwise stop — no tool calls or
|
|
278
|
+
* steering remain — before injecting. Returns once the message has been handed to the agent,
|
|
279
|
+
* which never waits for the turn that answers it; with `await: true` it returns once the
|
|
280
|
+
* durable write has landed instead, and a failed write both rejects and keeps the message out
|
|
281
|
+
* of the conversation entirely.
|
|
282
|
+
*/
|
|
283
|
+
send(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Start the loop without a new message: load the durable state and, if a turn was cut off —
|
|
286
|
+
* queued messages, a dispatched tool batch without results, or an unanswered user or tool
|
|
287
|
+
* message — continue it to completion. On an idle history this loads and does nothing more.
|
|
288
|
+
*/
|
|
289
|
+
start(): void;
|
|
290
|
+
/**
|
|
291
|
+
* Wait until the agent has nothing left to do. That includes work it has taken on but not yet
|
|
292
|
+
* started: an operation whose caller did not wait for it is registered from the moment it is
|
|
293
|
+
* called, so a message asked for and abandoned is still something this waits for, rather than
|
|
294
|
+
* a race between the caller's next line and the agent's own lock.
|
|
295
|
+
*/
|
|
296
|
+
waitForIdle(): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Compact the conversation. The compaction waits for the active turn to end — or runs right
|
|
299
|
+
* away when idle — and replaces the compacted history with the provider's replacement context
|
|
300
|
+
* while keeping every message that joined the history after the snapshot.
|
|
301
|
+
*
|
|
302
|
+
* Returns once the compaction has been asked for; with `await: true` it returns once the
|
|
303
|
+
* compaction has run, rejecting when the provider reports failure or when nothing will carry
|
|
304
|
+
* it out. Callers that wait while a compaction is pending or running all wait for that same
|
|
305
|
+
* compaction rather than queueing another.
|
|
306
|
+
*/
|
|
307
|
+
compact(ctx: Context, options?: AgentBaseAwaitOptions): Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Cancel the active turn: stop consuming the inference stream, settle still-running tool calls
|
|
310
|
+
* as aborted error results, and drop the queued turn request. Blocks that already finished
|
|
311
|
+
* stay in the history; an unfinished block is dropped. Messages still waiting in the steering
|
|
312
|
+
* and send queues stay durable and join the next requested turn. A no-op when the agent is
|
|
313
|
+
* idle.
|
|
314
|
+
*
|
|
315
|
+
* Returns once the cancellation has been signalled, which is the point from which nothing
|
|
316
|
+
* more of that turn happens; with `await: true` it returns once the loop has actually
|
|
317
|
+
* unwound. The cancellation is identical either way — waiting only buys the answer about
|
|
318
|
+
* when it finished.
|
|
319
|
+
*/
|
|
320
|
+
abort(ctx: Context, options?: AgentBaseAwaitOptions): Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Stop the agent, without abandoning anything it had already taken on. Nothing new is
|
|
323
|
+
* admitted from the moment close is called, but a message accepted just before it is still
|
|
324
|
+
* written, still answered, and only then is the provider session destroyed — so a caller
|
|
325
|
+
* whose send resolved never has to wonder whether the close raced it. Closing twice awaits
|
|
326
|
+
* the same shutdown.
|
|
327
|
+
*
|
|
328
|
+
* A close is nothing but a wait, so it is refused from inside the agent's own run loop, where
|
|
329
|
+
* the wait could never end. It is the one operation with no context to check, so it asks the
|
|
330
|
+
* runtime instead.
|
|
331
|
+
*
|
|
332
|
+
* Running tool calls are the exception to finishing what was accepted. From the moment close
|
|
333
|
+
* begins, the batch stops waiting for them and settles them in the conversation as error
|
|
334
|
+
* results. A tool can perfectly well be blocked on this very close — that is how two agents
|
|
335
|
+
* closing each other through their tools would otherwise wedge — and no tool is worth
|
|
336
|
+
* letting the shutdown never finish.
|
|
337
|
+
*/
|
|
338
|
+
close(): Promise<void>;
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=AgentBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentBase.d.ts","sourceRoot":"","sources":["../sources/AgentBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMR,sBAAsB,EACtB,kBAAkB,EAKlB,kBAAkB,EACrB,MAAM,yBAAyB,CAAC;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