agentfootprint 9.1.0 → 9.2.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.
Files changed (61) hide show
  1. package/README.md +15 -0
  2. package/dist/core/Agent.js +344 -18
  3. package/dist/core/Agent.js.map +1 -1
  4. package/dist/core/LLMCall.js +17 -0
  5. package/dist/core/LLMCall.js.map +1 -1
  6. package/dist/core/RunnerBase.js +22 -6
  7. package/dist/core/RunnerBase.js.map +1 -1
  8. package/dist/core/agent/AgentBuilder.js +20 -0
  9. package/dist/core/agent/AgentBuilder.js.map +1 -1
  10. package/dist/core/conversation.js +139 -0
  11. package/dist/core/conversation.js.map +1 -0
  12. package/dist/core/runCheckpoint.js +60 -2
  13. package/dist/core/runCheckpoint.js.map +1 -1
  14. package/dist/esm/core/Agent.d.ts +218 -3
  15. package/dist/esm/core/Agent.js +345 -19
  16. package/dist/esm/core/Agent.js.map +1 -1
  17. package/dist/esm/core/LLMCall.d.ts +9 -0
  18. package/dist/esm/core/LLMCall.js +17 -0
  19. package/dist/esm/core/LLMCall.js.map +1 -1
  20. package/dist/esm/core/RunnerBase.d.ts +22 -6
  21. package/dist/esm/core/RunnerBase.js +22 -6
  22. package/dist/esm/core/RunnerBase.js.map +1 -1
  23. package/dist/esm/core/agent/AgentBuilder.d.ts +5 -0
  24. package/dist/esm/core/agent/AgentBuilder.js +20 -0
  25. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  26. package/dist/esm/core/agent/types.d.ts +45 -3
  27. package/dist/esm/core/conversation.d.ts +96 -0
  28. package/dist/esm/core/conversation.js +133 -0
  29. package/dist/esm/core/conversation.js.map +1 -0
  30. package/dist/esm/core/runCheckpoint.d.ts +85 -1
  31. package/dist/esm/core/runCheckpoint.js +57 -1
  32. package/dist/esm/core/runCheckpoint.js.map +1 -1
  33. package/dist/esm/hosting/standingAgent.d.ts +6 -2
  34. package/dist/esm/hosting/standingAgent.js +36 -27
  35. package/dist/esm/hosting/standingAgent.js.map +1 -1
  36. package/dist/esm/index.d.ts +2 -1
  37. package/dist/esm/index.js +5 -1
  38. package/dist/esm/index.js.map +1 -1
  39. package/dist/hosting/standingAgent.js +36 -27
  40. package/dist/hosting/standingAgent.js.map +1 -1
  41. package/dist/index.js +9 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/types/core/Agent.d.ts +218 -3
  44. package/dist/types/core/Agent.d.ts.map +1 -1
  45. package/dist/types/core/LLMCall.d.ts +9 -0
  46. package/dist/types/core/LLMCall.d.ts.map +1 -1
  47. package/dist/types/core/RunnerBase.d.ts +22 -6
  48. package/dist/types/core/RunnerBase.d.ts.map +1 -1
  49. package/dist/types/core/agent/AgentBuilder.d.ts +5 -0
  50. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  51. package/dist/types/core/agent/types.d.ts +45 -3
  52. package/dist/types/core/agent/types.d.ts.map +1 -1
  53. package/dist/types/core/conversation.d.ts +97 -0
  54. package/dist/types/core/conversation.d.ts.map +1 -0
  55. package/dist/types/core/runCheckpoint.d.ts +85 -1
  56. package/dist/types/core/runCheckpoint.d.ts.map +1 -1
  57. package/dist/types/hosting/standingAgent.d.ts +6 -2
  58. package/dist/types/hosting/standingAgent.d.ts.map +1 -1
  59. package/dist/types/index.d.ts +2 -1
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/package.json +1 -1
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /**
3
+ * conversation — the refusals that guard a runner's per-instance state.
4
+ *
5
+ * Pattern: teaching refusal at a boundary (the shape `runInput` uses for a
6
+ * caller's message, applied to a caller's TIMING).
7
+ * Role: core/ layer. An `Agent` keeps the last run's executor, run context,
8
+ * answer and pause on ITSELF — that is what makes `checkpoint()`,
9
+ * `getLastSnapshot()` and `followUp()` possible at all. Those fields
10
+ * have exactly one owner at a time, and until 9.2.0 nothing said so.
11
+ * Emits: N/A — these fire before a run starts.
12
+ *
13
+ * ## Why these are refusals and not warnings
14
+ *
15
+ * Both shapes below used to SUCCEED, which is the entire problem. Two `run()`
16
+ * calls overlapping on one Agent both resolved with plausible answers, and the
17
+ * per-instance state afterwards belonged to whichever finished last: the
18
+ * conversation `checkpoint()` handed back was the other run's, the snapshot
19
+ * `getLastSnapshot()` served was the other run's, and every event carried the
20
+ * other run's meta. That is not concurrency, it is corruption — and nothing in
21
+ * the recording said so, because each run's own trace looked perfect.
22
+ *
23
+ * A message sent while a person still owes the agent an answer used to start a
24
+ * fresh run and silently abandon the pending question. A consent gate that can
25
+ * be walked around by sending another message is not a consent gate.
26
+ *
27
+ * Neither refusal is new policy. `standingAgent` has refused both since it
28
+ * existed (it serializes runs globally and calls that "a correctness
29
+ * requirement rather than a tuning choice", and answers a message that arrives
30
+ * mid-question with `AwaitingDecisionError`), and `recordedChat.send` refuses
31
+ * an overlapping turn in the same words. 9.2.0 moves the guarantee from the
32
+ * compositions down to the primitive, so it holds however you drive it.
33
+ *
34
+ * The names are deliberately NOT the hosting ones. `hosting/errors.ts` already
35
+ * owns `ConcurrentRunError` and `AwaitingDecisionError`, both of which carry a
36
+ * `sessionId` and speak about a session; core has no sessions, and two classes
37
+ * sharing one name across two doors is the duplicate-type hazard this codebase
38
+ * has fixed before.
39
+ */
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.NoConversationError = exports.PendingQuestionError = exports.RunInFlightError = void 0;
42
+ /**
43
+ * Thrown when `run()` / `resume()` is called on a runner that is already
44
+ * running.
45
+ *
46
+ * One instance answers one turn at a time. To run two turns at once, build two
47
+ * agents — a chart is built once per instance and instances are cheap — or put
48
+ * the turns behind `standingAgent({ onConcurrentInvoke: 'enqueue' })`, which
49
+ * queues them.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * // Refused: both would write the same instance's last-run state.
54
+ * await Promise.all([agent.run({ message: 'a' }), agent.run({ message: 'b' })]);
55
+ *
56
+ * // Fine: two instances, two sets of state.
57
+ * await Promise.all([agentA.run({ message: 'a' }), agentB.run({ message: 'b' })]);
58
+ * ```
59
+ */
60
+ class RunInFlightError extends Error {
61
+ code = 'ERR_RUN_IN_FLIGHT';
62
+ /** The runner that is busy, by its configured id. */
63
+ agentId;
64
+ /** The run already in flight, so a log line can be joined to its trace. */
65
+ activeRunId;
66
+ constructor(door, agentId, activeRunId) {
67
+ super(`${door}: this agent is already running (run '${activeRunId}'). One instance answers one ` +
68
+ `turn at a time — its last executor, run context, answer and pause all live on the ` +
69
+ `instance, so two overlapping runs would each finish having overwritten the other's. ` +
70
+ `Both would return a plausible answer and checkpoint() would then hand back whichever ` +
71
+ `finished last, which is why this is refused rather than left to look like it worked. ` +
72
+ `Await the run in flight, build a second Agent for the second turn (charts are ` +
73
+ `built per instance and instances are cheap), or serve the agent through ` +
74
+ `standingAgent({ onConcurrentInvoke: 'enqueue' }) to queue turns behind each other.`);
75
+ this.name = 'RunInFlightError';
76
+ this.agentId = agentId;
77
+ this.activeRunId = activeRunId;
78
+ }
79
+ }
80
+ exports.RunInFlightError = RunInFlightError;
81
+ /**
82
+ * Thrown when a new message is sent to an agent whose last run PAUSED to ask a
83
+ * person something, and that question has not been answered.
84
+ *
85
+ * The pause is not a failure and not a stale flag — it is unfinished work with
86
+ * a person on the other end. Answer it with `resume(checkpoint, decision)`, or
87
+ * say plainly that it is being dropped with `abandonPause()`; both are visible
88
+ * in the record, and silently starting a fresh run was not.
89
+ */
90
+ class PendingQuestionError extends Error {
91
+ code = 'ERR_PENDING_QUESTION';
92
+ /** The tool that asked, when the pause named one. */
93
+ toolName;
94
+ /** The id of the tool call that asked, for joining back to the trace. */
95
+ toolCallId;
96
+ constructor(door, pending) {
97
+ const asked = pending.toolName !== undefined
98
+ ? `'${pending.toolName}'${pending.toolCallId ? ` (call ${pending.toolCallId})` : ''}`
99
+ : 'a tool';
100
+ const quoted = pending.question !== undefined ? ` It asked: "${pending.question}"` : '';
101
+ super(`${door}: this agent's last run paused to ask a person something and is still waiting. ` +
102
+ `${asked} raised the question and nothing has answered it.${quoted} Answer it with ` +
103
+ `agent.resume(outcome.checkpoint, decision) — that continues the paused run from where ` +
104
+ `it stopped, with no earlier tool re-executed. If the question really is being dropped, ` +
105
+ `call agent.abandonPause() first and then run() again: a pending question that a later ` +
106
+ `message silently discards is a consent gate anyone can walk around.`);
107
+ this.name = 'PendingQuestionError';
108
+ if (pending.toolName !== undefined)
109
+ this.toolName = pending.toolName;
110
+ if (pending.toolCallId !== undefined)
111
+ this.toolCallId = pending.toolCallId;
112
+ }
113
+ }
114
+ exports.PendingQuestionError = PendingQuestionError;
115
+ /**
116
+ * Thrown by `followUp()` when there is no conversation to follow up on.
117
+ *
118
+ * `followUp()` continues THIS agent's own last completed run. Before the first
119
+ * one there is nothing to continue, and a "follow-up" that quietly became a
120
+ * first turn would be the very confusion the door exists to remove.
121
+ */
122
+ class NoConversationError extends Error {
123
+ code = 'ERR_NO_CONVERSATION';
124
+ constructor(door, reason) {
125
+ super(reason === 'never-run'
126
+ ? `${door}: this agent has not completed a run, so there is no conversation to ` +
127
+ `continue. Start it with agent.run({ message }) — the first turn is a run; every ` +
128
+ `turn after it is a followUp(). To continue a conversation this PROCESS did not ` +
129
+ `have (a stored one, or one from another instance), pass it explicitly: ` +
130
+ `agent.run({ message, continueFrom: storedConversation }).`
131
+ : `${door}: this agent's last run did not finish with an answer, so there is no ` +
132
+ `conversation to continue yet. A failed run's conversation is carried by ` +
133
+ `RunCheckpointError.checkpoint — catch it and pass that to ` +
134
+ `run({ message, continueFrom }) or resumeOnError(checkpoint).`);
135
+ this.name = 'NoConversationError';
136
+ }
137
+ }
138
+ exports.NoConversationError = NoConversationError;
139
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","sourceRoot":"","sources":["../../src/core/conversation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;;;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAChC,IAAI,GAAG,mB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SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACrE,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAC7E,CAAC;CACF;AA5BD,oDA4BC;AAED;;;;;;GAMG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IACnC,IAAI,GAAG,qBAA8B,CAAC;IAE/C,YAAY,IAAY,EAAE,MAA2C;QACnE,KAAK,CACH,MAAM,KAAK,WAAW;YACpB,CAAC,CAAC,GAAG,IAAI,uEAAuE;gBAC5E,kFAAkF;gBAClF,iFAAiF;gBACjF,yEAAyE;gBACzE,2DAA2D;YAC/D,CAAC,CAAC,GAAG,IAAI,wEAAwE;gBAC7E,0EAA0E;gBAC1E,4DAA4D;gBAC5D,8DAA8D,CACrE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAlBD,kDAkBC"}
@@ -55,7 +55,7 @@
55
55
  * DFS stage).
56
56
  */
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
- exports.classifyFailurePhase = exports.validateCheckpoint = exports.buildCheckpoint = exports.RunCheckpointError = void 0;
58
+ exports.classifyFailurePhase = exports.validateCheckpoint = exports.buildCheckpoint = exports.assertContinuable = exports.ConversationMismatchError = exports.RunCheckpointError = void 0;
59
59
  /**
60
60
  * Thrown by `agent.run()` when a fault occurs mid-run. Carries the
61
61
  * underlying error AND the last-known-good checkpoint. Catch this
@@ -101,6 +101,55 @@ class RunCheckpointError extends Error {
101
101
  }
102
102
  }
103
103
  exports.RunCheckpointError = RunCheckpointError;
104
+ /**
105
+ * Thrown when a stored conversation is handed to an agent that is provably
106
+ * not the one that recorded it (9.2.0).
107
+ *
108
+ * Raised only when BOTH sides named themselves with an explicit
109
+ * `Agent.create({ id })` and the two names differ — see
110
+ * {@link AgentRunCheckpoint.agent} for why that is the whole of the rule.
111
+ * An agent that gained a tool, changed its prompt or moved to a new model
112
+ * since the conversation was stored is NOT this error; continuing across a
113
+ * deploy is the ordinary case and must keep working.
114
+ */
115
+ class ConversationMismatchError extends Error {
116
+ code = 'ERR_CONVERSATION_MISMATCH';
117
+ /** The id stamped on the stored conversation. */
118
+ storedAgentId;
119
+ /** The id of the agent it was handed to. */
120
+ agentId;
121
+ constructor(door, storedAgentId, agentId) {
122
+ super(`${door}: this conversation was recorded by agent '${storedAgentId}' and was handed to ` +
123
+ `agent '${agentId}'. Both agents named themselves with Agent.create({ id }), and the ` +
124
+ `names differ — so this is one agent answering another one's conversation, not a ` +
125
+ `deploy that changed. Continue it on the agent whose id is '${storedAgentId}', or, if ` +
126
+ `handing conversations between these two really is intended, give them the same id. ` +
127
+ `(An agent that merely gained a tool, changed its prompt or moved model since the ` +
128
+ `conversation was stored keeps the same id and is never refused here.)`);
129
+ this.name = 'ConversationMismatchError';
130
+ this.storedAgentId = storedAgentId;
131
+ this.agentId = agentId;
132
+ }
133
+ }
134
+ exports.ConversationMismatchError = ConversationMismatchError;
135
+ /**
136
+ * Refuse a stored conversation that provably belongs to a different agent.
137
+ *
138
+ * Both-sides-named-themselves, or nothing happens. `storedId` is absent on
139
+ * every conversation written before 9.2.0 and on every agent that never chose
140
+ * an id; `agentId` is undefined for the same reason on the reading side.
141
+ *
142
+ * @internal
143
+ */
144
+ function assertContinuable(checkpoint, agentId, door) {
145
+ const storedId = checkpoint.agent?.id;
146
+ if (storedId === undefined || agentId === undefined)
147
+ return;
148
+ if (storedId === agentId)
149
+ return;
150
+ throw new ConversationMismatchError(door, storedId, agentId);
151
+ }
152
+ exports.assertContinuable = assertContinuable;
104
153
  /**
105
154
  * The human half of `failurePoint`, as one clause.
106
155
  *
@@ -135,7 +184,14 @@ function buildCheckpoint(tracker, failurePoint,
135
184
  * and a fold's span is committed state — and because the same reader then
136
185
  * serves both checkpoint carriers, so neither can lose what the other keeps.
137
186
  */
138
- folded) {
187
+ folded,
188
+ /**
189
+ * Who the run was for and which agent ran it — the two fields that make a
190
+ * stored conversation continuable rather than merely readable (9.2.0).
191
+ * Both are absent unless the caller chose them explicitly; see
192
+ * {@link AgentRunCheckpoint.identity} and {@link AgentRunCheckpoint.agent}.
193
+ */
194
+ owner) {
139
195
  return {
140
196
  version: 1,
141
197
  runId: tracker.runId,
@@ -145,6 +201,8 @@ folded) {
145
201
  checkpointedAt: Date.now(),
146
202
  ...(failurePoint && { failurePoint }),
147
203
  ...(folded !== undefined && folded.length > 0 && { folded }),
204
+ ...(owner?.identity !== undefined && { identity: owner.identity }),
205
+ ...(owner?.agentId !== undefined && { agent: { id: owner.agentId } }),
148
206
  };
149
207
  }
150
208
  exports.buildCheckpoint = buildCheckpoint;
@@ -1 +1 @@
1
- {"version":3,"file":"runCheckpoint.js","sourceRoot":"","sources":["../../src/core/runCheckpoint.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;;;AAkFH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAClC,IAAI,GAAG,oBAA6B,CAAC;IAC9C;;6BAEyB;IACP,KAAK,CAAQ;IAC/B;mEAC+D;IACtD,UAAU,CAAqB;IAExC,YAAY,KAAY,EAAE,UAA8B;QACtD,KAAK,CACH,mCAAmC,UAAU,CAAC,YAAY,EAAE,SAAS,IAAI,GAAG,GAAG;YAC7E,GAAG,oBAAoB,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI;YACpD,8CAA8C,UAAU,CAAC,sBAAsB,IAAI;YACnF,uDAAuD;YACvD,qBAAqB,KAAK,CAAC,OAAO,EAAE,CACvC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAtBD,gDAsBC;AAED;;;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,EACxD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/D,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,WAAW,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAnBD,oDAmBC"}
@@ -20,6 +20,8 @@ import { type RunnerPauseOutcome } from './pause.js';
20
20
  import type { WindowStrategy } from './agent/window/strategy.js';
21
21
  import { type CheckInBuilderOptions } from './checkin.js';
22
22
  import type { MemoryDefinition } from '../memory/define.types.js';
23
+ import type { MemoryIdentity } from '../memory/identity/types.js';
24
+ import type { SelfExplainBinding } from '../lib/trace-toolpack/selfExplain.js';
23
25
  import type { Injection, InjectionContext } from '../lib/injection-engine/types.js';
24
26
  import type { CursorMove, EntryScoring } from '../lib/injection-engine/skillGraph.js';
25
27
  import { type ResolvedOutputFallback } from './outputFallback.js';
@@ -55,6 +57,19 @@ export interface AgentRunOptions extends RunOptions {
55
57
  correlationId?: string;
56
58
  /** OTEL-style trace id — forwarded onto every emitted event's `EventMeta.traceId`. Falls back to `options.env?.traceId` when unset. */
57
59
  traceId?: string;
60
+ /**
61
+ * Who this run is for — the same tuple as `run({ identity })`, reachable
62
+ * from the doors whose input is a stored conversation rather than a
63
+ * message bag: `resumeOnError(checkpoint, { identity })` and
64
+ * `followUp(message, { identity })` (9.2.0).
65
+ *
66
+ * Before this existed, `resumeOnError` could not carry an identity at all,
67
+ * so every continued turn silently re-namespaced its memory under a fresh
68
+ * runId. Omitted, the conversation's own stored `identity` is used; given,
69
+ * it wins. On `run()` this is a second spelling of `run({ identity })` and
70
+ * the one on the input wins, since that is where the caller looked first.
71
+ */
72
+ identity?: MemoryIdentity;
58
73
  }
59
74
  export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
60
75
  readonly name: string;
@@ -245,6 +260,28 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
245
260
  * kept here rather than read back from the recording. Undefined after a run
246
261
  * that failed or paused. */
247
262
  private lastRunAnswer?;
263
+ /** The id the CONSUMER chose, or undefined when they took the default.
264
+ * `this.id` cannot answer that question — it is `'agent'` either way — and
265
+ * the stored-conversation fingerprint refuses only on ids somebody picked
266
+ * (see `AgentRunCheckpoint.agent`). */
267
+ private readonly explicitId?;
268
+ /** The identity the caller gave the last run, or undefined when they gave
269
+ * none. Only an EXPLICIT identity is carried onto `checkpoint()`: the
270
+ * default is derived from a runId, and storing that would pin a whole
271
+ * conversation to the id of the one run that started it. */
272
+ private lastRunIdentity?;
273
+ /** The run in flight, by id — the whole of the one-turn-at-a-time guard.
274
+ * Set before the executor is built and cleared in `finally`, so a run that
275
+ * throws does not leave the agent permanently refusing. */
276
+ private inFlightRunId?;
277
+ /** The question a person still owes this agent an answer to. Set when a run
278
+ * ends paused, cleared by `resume()`, `abandonPause()`, or a run that
279
+ * completes. Read by the `run()` guard — see `PendingQuestionError`. */
280
+ private pendingQuestion?;
281
+ /** The `.selfExplain()` binding, when the builder mounted one. Held so
282
+ * `canExplain()` can answer the same question the trace tools answer, from
283
+ * the same fact. Undefined on every agent that never called `.selfExplain()`. */
284
+ private selfExplainBinding?;
248
285
  /**
249
286
  * Optional `ToolProvider` set via the builder's `.toolProvider()`.
250
287
  * When present, the Tools slot subflow consults it per iteration
@@ -309,9 +346,17 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
309
346
  * prop) so consumers can scrub the execution timeline post-run without
310
347
  * threading a recorder through the call site.
311
348
  *
312
- * Returns `undefined` before the first run completes. Returns the
313
- * snapshot of the most recent run on every call after — including
314
- * across multiple turns of the same Agent instance.
349
+ * `undefined` until a run has STARTED. After that it is the most recent
350
+ * run's snapshot — including across multiple turns of the same instance.
351
+ *
352
+ * **It is LIVE during a run, not a completed-runs-only view.** The executor
353
+ * is assigned at run start, so calling this from an event listener, a tool,
354
+ * or any other mid-run vantage point returns the IN-FLIGHT run, partially
355
+ * filled. That is deliberate (Lens scrubs a running agent through it), and
356
+ * it is why `.selfExplain()` captures at the terminal flush instead of
357
+ * resolving through this: evidence that is supposed to describe a FINISHED
358
+ * turn cannot be read from a getter that also answers about an unfinished
359
+ * one.
315
360
  */
316
361
  getLastSnapshot(): RuntimeSnapshot | undefined;
317
362
  /**
@@ -383,7 +428,112 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
383
428
  * pauses (use `run()` directly when pauses are expected).
384
429
  */
385
430
  runTyped<T = unknown>(input: AgentInput | string, options?: AgentRunOptions): Promise<T>;
431
+ /**
432
+ * Answer one turn.
433
+ *
434
+ * **`run()` is ONE turn, and it starts a new conversation every time.** The
435
+ * chart seeds its history from this call's `message` alone, so a second
436
+ * `run()` on the same agent does not continue the first: the model is shown
437
+ * one user message and will honestly tell your user it has not spoken to
438
+ * them before. That is deliberate — a primitive that quietly accumulated
439
+ * state across calls could never be used for one-shot work, and a hidden
440
+ * transcript is the most expensive thing an agent can carry.
441
+ *
442
+ * To continue a conversation, name it:
443
+ *
444
+ * - `agent.followUp(message)` — continue THIS agent's own last completed
445
+ * run. The one-liner, and what most callers want.
446
+ * - `run({ message, continueFrom })` — continue a conversation you are
447
+ * holding: `agent.checkpoint()` from an earlier turn, persisted anywhere
448
+ * and handed back. Works across a restart, a deploy, or a different
449
+ * machine, and is what `standingAgent` uses per session.
450
+ *
451
+ * Passing the same `identity.conversationId` to two `run()` calls does NOT
452
+ * continue anything — see {@link AgentInput.identity}. What a registered
453
+ * memory adds is *recall* of prior turns into the system-prompt slot, which
454
+ * is a different thing from the conversation itself.
455
+ *
456
+ * Two refusals guard the per-instance state this agent keeps; both replace
457
+ * behavior that used to succeed while quietly being wrong (9.2.0):
458
+ * {@link RunInFlightError} when a run is already in flight, and
459
+ * {@link PendingQuestionError} when the last run paused to ask a person
460
+ * something that nobody has answered.
461
+ *
462
+ * @example One turn, then a follow-up
463
+ * ```ts
464
+ * await agent.run({ message: 'Book me a table for two.' });
465
+ * await agent.followUp('Make it three.'); // remembers the table
466
+ * ```
467
+ */
386
468
  run(input: AgentInput | string, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
469
+ /**
470
+ * Continue this agent's own last completed conversation.
471
+ *
472
+ * The one-liner for turn two and after. `run()` is one turn and starts a new
473
+ * conversation each time (see {@link Agent.run}); this reads the
474
+ * conversation off the last completed run, appends `message` as the next
475
+ * user turn, and runs from there — so the model sees what was actually said.
476
+ *
477
+ * Sugar over `run({ message, continueFrom: this.checkpoint() })` and nothing
478
+ * more: one restoration path, so the convenience cannot drift from the
479
+ * mechanism. Reach for `run({ continueFrom })` directly when the
480
+ * conversation comes from somewhere other than this instance's last run — a
481
+ * store, another process, a different machine.
482
+ *
483
+ * Refuses rather than guessing: {@link NoConversationError} when this agent
484
+ * has no completed run to continue (a "follow-up" that quietly became a
485
+ * first turn would be exactly the confusion this door exists to remove),
486
+ * and — through `run()` — {@link PendingQuestionError} when the last run
487
+ * paused to ask a person something, because a pause has its own door:
488
+ * `resume(checkpoint, decision)`.
489
+ *
490
+ * The conversation grows every turn and nothing here trims it; bounding what
491
+ * the model is shown is `.window()` / `.compaction()` / `.memory()`, not a
492
+ * silent cap on the way through.
493
+ *
494
+ * @example
495
+ * ```ts
496
+ * await agent.run({ message: 'Book me a table for two.' });
497
+ * await agent.followUp('Make it three.');
498
+ * await agent.followUp('And move it to 8pm.');
499
+ * ```
500
+ */
501
+ followUp(message: string, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
502
+ /**
503
+ * Drop the question this agent's last run paused to ask, on the record.
504
+ *
505
+ * A paused run is waiting on a person. Sending a different message while one
506
+ * is outstanding is refused ({@link PendingQuestionError}) because silently
507
+ * discarding a pending question makes a consent gate something any later
508
+ * message can walk around. When the question really is being dropped —
509
+ * the user changed the subject, the session timed out, the approval is no
510
+ * longer wanted — say so with this, and the next `run()` proceeds.
511
+ *
512
+ * Returns what was dropped (`undefined` when nothing was pending), so a
513
+ * caller can log or audit the abandonment rather than perform it blind. It
514
+ * does not touch the paused run's checkpoint: if you still hold that, it
515
+ * remains resumable.
516
+ */
517
+ abandonPause(): {
518
+ readonly toolName?: string;
519
+ readonly toolCallId?: string;
520
+ readonly question?: string;
521
+ } | undefined;
522
+ /**
523
+ * Whether {@link Agent.selfExplain}'s why-questions have a run to answer
524
+ * from right now.
525
+ *
526
+ * `false` for two different reasons, both honest: this agent was not built
527
+ * with `.selfExplain()`, or it was and no turn has completed yet (evidence
528
+ * binds at the END of a run, never to the one in flight). Either way there
529
+ * is nothing to explain, which is what a caller routing a why-question needs
530
+ * to know before it routes.
531
+ *
532
+ * The model is told the same thing by the same fact — the trace tools answer
533
+ * "No completed run is available yet" and the skill body says to say so
534
+ * plainly. This is that answer, for the program.
535
+ */
536
+ canExplain(): boolean;
387
537
  /**
388
538
  * Resume an agent run from a checkpoint produced by a prior
389
539
  * `RunCheckpointError`. Unlike `agent.resume()` (which takes a
@@ -429,6 +579,13 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
429
579
  * ```
430
580
  */
431
581
  resumeOnError(checkpoint: AgentRunCheckpoint | unknown, options?: AgentRunOptions): Promise<AgentOutput | RunnerPauseOutcome>;
582
+ /**
583
+ * Which identity a continued turn runs under: the caller's if they named
584
+ * one, otherwise the conversation's own.
585
+ *
586
+ * @internal
587
+ */
588
+ private identityFor;
432
589
  /**
433
590
  * Install a per-run checkpoint tracker. Listens for the agent's
434
591
  * own iteration_end events on `this.dispatcher` and snapshots the
@@ -493,6 +650,64 @@ export declare class Agent extends RunnerBase<AgentInput, AgentOutput> {
493
650
  * @internal
494
651
  */
495
652
  private foldedSpansOf;
653
+ /**
654
+ * The two owner facts every conversation carrier stamps — who the run was
655
+ * for, and which agent ran it (9.2.0).
656
+ *
657
+ * One reader for `checkpoint()` and the crash checkpoint, the same rule
658
+ * `foldedSpansOf` follows: a fact kept on one carrier and lost on the other
659
+ * is worse than a fact kept on neither. Both are absent unless the caller
660
+ * chose them, which is what keeps the fingerprint refusal narrow and the
661
+ * default `conversationId` out of storage.
662
+ *
663
+ * @internal
664
+ */
665
+ private conversationOwner;
666
+ /**
667
+ * Restore a stored conversation onto the side channel `seed` reads.
668
+ *
669
+ * THE one restoration path — `run({ continueFrom })` and `resumeOnError()`
670
+ * both come through here, so the conversation door and the error door cannot
671
+ * disagree about what continuing means. It checks the agent fingerprint,
672
+ * restores history + folded spans, and adopts the conversation's identity so
673
+ * the continued turn writes its memory where the earlier turns are.
674
+ *
675
+ * `appendMessage` is the difference between the two callers, and it is the
676
+ * whole difference. Continuing a conversation ADDS this turn's user message
677
+ * to the stored history; resuming after an error does NOT, because there the
678
+ * message is already the last user turn in that history and appending it
679
+ * would ask the same question twice.
680
+ *
681
+ * @internal
682
+ */
683
+ private applyContinuation;
684
+ /** One turn at a time — see `RunInFlightError`. @internal */
685
+ private assertNotRunning;
686
+ /** A person's unanswered question outranks a new message — see
687
+ * `PendingQuestionError`. @internal */
688
+ private assertNoPendingQuestion;
689
+ /**
690
+ * Remember (or forget) the question this run ended on.
691
+ *
692
+ * A paused outcome sets it; anything else clears it, because a run that
693
+ * reached an answer has no outstanding question by definition. Reads the
694
+ * same `pauseData` fields `standingAgent.describePause` reads — the tool
695
+ * name and question the dispatch loop stamped — and invents nothing.
696
+ *
697
+ * @internal
698
+ */
699
+ private recordPendingQuestion;
700
+ /**
701
+ * Hand the `.selfExplain()` binding to the agent that owns it.
702
+ *
703
+ * Called once by `AgentBuilder.build()`, immediately after `bindTo`. The
704
+ * binding stays the tool provider's to read; the Agent holds it only so
705
+ * `canExplain()` answers from the same fact the trace tools answer from,
706
+ * rather than from a second guess about whether a run has completed.
707
+ *
708
+ * @internal
709
+ */
710
+ bindSelfExplain(binding: SelfExplainBinding): void;
496
711
  /**
497
712
  * Refuse, at run start, any declared messages-slot role this provider
498
713
  * cannot carry inside its message list (7.21, D2).