@genesislcap/ai-assistant 15.95.2 → 15.96.0-GENC-1665.3
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/dist/ai-assistant.api.json +264 -0
- package/dist/ai-assistant.d.ts +124 -0
- package/dist/chat-driver.cjs +340 -50
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +338 -50
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +98 -3
- package/dist/dts/autopilot/decision-message.d.ts.map +1 -1
- package/dist/dts/chat-driver-node.d.ts +1 -1
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.constants.d.ts +14 -0
- package/dist/dts/components/chat-driver/chat-driver.constants.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +16 -0
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/config/config.d.ts +76 -0
- package/dist/dts/config/config.d.ts.map +1 -1
- package/dist/dts/config/define-stateful-agent.d.ts +30 -1
- package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
- package/dist/dts/state/debug-event-log.d.ts +1 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts +2 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
- package/dist/dts/suggestions/generate-suggestions.d.ts.map +1 -1
- package/dist/dts/utils/driver-note.d.ts +26 -0
- package/dist/dts/utils/driver-note.d.ts.map +1 -0
- package/dist/dts/utils/history-transform.d.ts.map +1 -1
- package/dist/dts/utils/message-partition.d.ts.map +1 -1
- package/dist/dts/utils/preserved-user-messages.d.ts.map +1 -1
- package/dist/esm/autopilot/decision-message.js +3 -0
- package/dist/esm/chat-driver-node.js +1 -1
- package/dist/esm/components/chat-driver/chat-driver.constants.js +17 -0
- package/dist/esm/components/chat-driver/chat-driver.js +123 -6
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +4 -0
- package/dist/esm/config/define-stateful-agent.js +20 -13
- package/dist/esm/state/debug-event-log.js +4 -3
- package/dist/esm/state/persistence/session-snapshot.js +11 -3
- package/dist/esm/suggestions/generate-suggestions.js +2 -0
- package/dist/esm/utils/driver-note.js +30 -0
- package/dist/esm/utils/history-transform.js +4 -0
- package/dist/esm/utils/message-partition.js +5 -0
- package/dist/esm/utils/preserved-user-messages.js +2 -1
- package/docs/finish-guard.md +125 -0
- package/package.json +17 -17
|
@@ -20547,6 +20547,207 @@
|
|
|
20547
20547
|
}
|
|
20548
20548
|
]
|
|
20549
20549
|
},
|
|
20550
|
+
{
|
|
20551
|
+
"kind": "Interface",
|
|
20552
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext:interface",
|
|
20553
|
+
"docComment": "/**\n * Context passed to an agent's `finishGuard` hook: the model has just replied with no tool call, so the turn is about to end. The standard {@link SystemPromptContext} plus the reply and how many times this guard has already held the turn open.\n *\n * @beta\n */\n",
|
|
20554
|
+
"excerptTokens": [
|
|
20555
|
+
{
|
|
20556
|
+
"kind": "Content",
|
|
20557
|
+
"text": "export interface FinishGuardContext extends "
|
|
20558
|
+
},
|
|
20559
|
+
{
|
|
20560
|
+
"kind": "Reference",
|
|
20561
|
+
"text": "SystemPromptContext",
|
|
20562
|
+
"canonicalReference": "@genesislcap/ai-assistant!SystemPromptContext:interface"
|
|
20563
|
+
},
|
|
20564
|
+
{
|
|
20565
|
+
"kind": "Content",
|
|
20566
|
+
"text": " "
|
|
20567
|
+
}
|
|
20568
|
+
],
|
|
20569
|
+
"fileUrlPath": "src/config/config.ts",
|
|
20570
|
+
"releaseTag": "Beta",
|
|
20571
|
+
"name": "FinishGuardContext",
|
|
20572
|
+
"preserveMemberOrder": false,
|
|
20573
|
+
"members": [
|
|
20574
|
+
{
|
|
20575
|
+
"kind": "PropertySignature",
|
|
20576
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext#canContinue:member",
|
|
20577
|
+
"docComment": "/**\n * Whether a `'continue'` answer would be honoured. `false` on the tool loop's last iteration (`maxToolIterations`), where there is no call left to hold the turn open for: a `'continue'` then ends the turn, while `{ action: 'end', release: true }` still releases the agent (and the turn ends cleanly, not as the iteration cap).\n */\n",
|
|
20578
|
+
"excerptTokens": [
|
|
20579
|
+
{
|
|
20580
|
+
"kind": "Content",
|
|
20581
|
+
"text": "canContinue: "
|
|
20582
|
+
},
|
|
20583
|
+
{
|
|
20584
|
+
"kind": "Content",
|
|
20585
|
+
"text": "boolean"
|
|
20586
|
+
},
|
|
20587
|
+
{
|
|
20588
|
+
"kind": "Content",
|
|
20589
|
+
"text": ";"
|
|
20590
|
+
}
|
|
20591
|
+
],
|
|
20592
|
+
"isReadonly": false,
|
|
20593
|
+
"isOptional": false,
|
|
20594
|
+
"releaseTag": "Beta",
|
|
20595
|
+
"name": "canContinue",
|
|
20596
|
+
"propertyTypeTokenRange": {
|
|
20597
|
+
"startIndex": 1,
|
|
20598
|
+
"endIndex": 2
|
|
20599
|
+
}
|
|
20600
|
+
},
|
|
20601
|
+
{
|
|
20602
|
+
"kind": "PropertySignature",
|
|
20603
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext#continuations:member",
|
|
20604
|
+
"docComment": "/**\n * How many times this guard has answered `'continue'` in the current turn (0 the first time it is consulted). Enforce your own per-turn cap with it: answer `'end'` once it reaches the cap. The driver's completion nudges to a sub-agent are not counted.\n */\n",
|
|
20605
|
+
"excerptTokens": [
|
|
20606
|
+
{
|
|
20607
|
+
"kind": "Content",
|
|
20608
|
+
"text": "continuations: "
|
|
20609
|
+
},
|
|
20610
|
+
{
|
|
20611
|
+
"kind": "Content",
|
|
20612
|
+
"text": "number"
|
|
20613
|
+
},
|
|
20614
|
+
{
|
|
20615
|
+
"kind": "Content",
|
|
20616
|
+
"text": ";"
|
|
20617
|
+
}
|
|
20618
|
+
],
|
|
20619
|
+
"isReadonly": false,
|
|
20620
|
+
"isOptional": false,
|
|
20621
|
+
"releaseTag": "Beta",
|
|
20622
|
+
"name": "continuations",
|
|
20623
|
+
"propertyTypeTokenRange": {
|
|
20624
|
+
"startIndex": 1,
|
|
20625
|
+
"endIndex": 2
|
|
20626
|
+
}
|
|
20627
|
+
},
|
|
20628
|
+
{
|
|
20629
|
+
"kind": "PropertySignature",
|
|
20630
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext#reply:member",
|
|
20631
|
+
"docComment": "/**\n * The text of the reply that would end the turn. Already in `history`.\n */\n",
|
|
20632
|
+
"excerptTokens": [
|
|
20633
|
+
{
|
|
20634
|
+
"kind": "Content",
|
|
20635
|
+
"text": "reply: "
|
|
20636
|
+
},
|
|
20637
|
+
{
|
|
20638
|
+
"kind": "Content",
|
|
20639
|
+
"text": "string"
|
|
20640
|
+
},
|
|
20641
|
+
{
|
|
20642
|
+
"kind": "Content",
|
|
20643
|
+
"text": ";"
|
|
20644
|
+
}
|
|
20645
|
+
],
|
|
20646
|
+
"isReadonly": false,
|
|
20647
|
+
"isOptional": false,
|
|
20648
|
+
"releaseTag": "Beta",
|
|
20649
|
+
"name": "reply",
|
|
20650
|
+
"propertyTypeTokenRange": {
|
|
20651
|
+
"startIndex": 1,
|
|
20652
|
+
"endIndex": 2
|
|
20653
|
+
}
|
|
20654
|
+
}
|
|
20655
|
+
],
|
|
20656
|
+
"extendsTokenRanges": [
|
|
20657
|
+
{
|
|
20658
|
+
"startIndex": 1,
|
|
20659
|
+
"endIndex": 2
|
|
20660
|
+
}
|
|
20661
|
+
]
|
|
20662
|
+
},
|
|
20663
|
+
{
|
|
20664
|
+
"kind": "TypeAlias",
|
|
20665
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardInput:type",
|
|
20666
|
+
"docComment": "/**\n * Optional per-agent hook consulted when a model reply in the tool loop carries no tool call, so the turn would end. Lets the agent hold the turn open with a note (\"your change is not applied yet …\"), or end it and release the agent. See {@link FinishGuardVerdict}.\n *\n * Return `undefined` (or throw) to end the turn as if there were no hook. Not consulted on a closing call, nor after a tool handler released the agent earlier in the turn. A continuation spends a tool-loop iteration, so `maxToolIterations` also bounds a guard that never says `'end'`: on the last iteration (`ctx.canContinue === false`) a `'continue'` ends the turn, though a release is still honoured. Use `ctx.continuations` for a tighter per-turn cap. A turn stopped while the hook is pending ends as stopped, whatever it answers.\n *\n * On a sub-agent, which succeeds only by calling `completeSubAgent`, prose is never an answer: `'end'` gives up (the sub-agent fails, as it does today), `release` is ignored, and when the hook answers nothing (or there is no hook) the driver holds the turn itself with a completion nudge, asking for the completion call (`driverNote: 'completion-nudge'`), up to twice per turn.\n *\n * @beta\n */\n",
|
|
20667
|
+
"excerptTokens": [
|
|
20668
|
+
{
|
|
20669
|
+
"kind": "Content",
|
|
20670
|
+
"text": "export type FinishGuardInput = "
|
|
20671
|
+
},
|
|
20672
|
+
{
|
|
20673
|
+
"kind": "Content",
|
|
20674
|
+
"text": "(ctx: "
|
|
20675
|
+
},
|
|
20676
|
+
{
|
|
20677
|
+
"kind": "Reference",
|
|
20678
|
+
"text": "FinishGuardContext",
|
|
20679
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext:interface"
|
|
20680
|
+
},
|
|
20681
|
+
{
|
|
20682
|
+
"kind": "Content",
|
|
20683
|
+
"text": ") => "
|
|
20684
|
+
},
|
|
20685
|
+
{
|
|
20686
|
+
"kind": "Reference",
|
|
20687
|
+
"text": "FinishGuardVerdict",
|
|
20688
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardVerdict:type"
|
|
20689
|
+
},
|
|
20690
|
+
{
|
|
20691
|
+
"kind": "Content",
|
|
20692
|
+
"text": " | undefined | "
|
|
20693
|
+
},
|
|
20694
|
+
{
|
|
20695
|
+
"kind": "Reference",
|
|
20696
|
+
"text": "Promise",
|
|
20697
|
+
"canonicalReference": "!Promise:interface"
|
|
20698
|
+
},
|
|
20699
|
+
{
|
|
20700
|
+
"kind": "Content",
|
|
20701
|
+
"text": "<"
|
|
20702
|
+
},
|
|
20703
|
+
{
|
|
20704
|
+
"kind": "Reference",
|
|
20705
|
+
"text": "FinishGuardVerdict",
|
|
20706
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardVerdict:type"
|
|
20707
|
+
},
|
|
20708
|
+
{
|
|
20709
|
+
"kind": "Content",
|
|
20710
|
+
"text": " | undefined>"
|
|
20711
|
+
},
|
|
20712
|
+
{
|
|
20713
|
+
"kind": "Content",
|
|
20714
|
+
"text": ";"
|
|
20715
|
+
}
|
|
20716
|
+
],
|
|
20717
|
+
"fileUrlPath": "src/config/config.ts",
|
|
20718
|
+
"releaseTag": "Beta",
|
|
20719
|
+
"name": "FinishGuardInput",
|
|
20720
|
+
"typeTokenRange": {
|
|
20721
|
+
"startIndex": 1,
|
|
20722
|
+
"endIndex": 10
|
|
20723
|
+
}
|
|
20724
|
+
},
|
|
20725
|
+
{
|
|
20726
|
+
"kind": "TypeAlias",
|
|
20727
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardVerdict:type",
|
|
20728
|
+
"docComment": "/**\n * What an agent's `finishGuard` hook answers when the model replies with no tool call.\n *\n * - `{ action: 'end' }`: let the turn end, as it would with no hook. - `{ action: 'end', release: true }`: end the turn and release the agent, exactly as a tool handler calling `releaseAgent()` would. A turn that ends in prose has no handler context, so this is the only way such a turn can release the flow lock (e.g. a question answered in prose). - `{ action: 'continue', note }`: hold the turn open. The driver stores `note` in history as a model-facing message (`role: 'user'`, `driverNote: 'finish-guard'`, framed as a `<system-reminder>`, hidden from the transcript) and makes the next model call in the same turn. Stored rather than sent once in the tail, so later calls and later turns see why the turn went on, and it sits between the two assistant replies so they are never merged.\n *\n * @beta\n */\n",
|
|
20729
|
+
"excerptTokens": [
|
|
20730
|
+
{
|
|
20731
|
+
"kind": "Content",
|
|
20732
|
+
"text": "export type FinishGuardVerdict = "
|
|
20733
|
+
},
|
|
20734
|
+
{
|
|
20735
|
+
"kind": "Content",
|
|
20736
|
+
"text": "{\n action: 'end';\n release?: boolean;\n} | {\n action: 'continue';\n note: string;\n}"
|
|
20737
|
+
},
|
|
20738
|
+
{
|
|
20739
|
+
"kind": "Content",
|
|
20740
|
+
"text": ";"
|
|
20741
|
+
}
|
|
20742
|
+
],
|
|
20743
|
+
"fileUrlPath": "src/config/config.ts",
|
|
20744
|
+
"releaseTag": "Beta",
|
|
20745
|
+
"name": "FinishGuardVerdict",
|
|
20746
|
+
"typeTokenRange": {
|
|
20747
|
+
"startIndex": 1,
|
|
20748
|
+
"endIndex": 2
|
|
20749
|
+
}
|
|
20750
|
+
},
|
|
20550
20751
|
{
|
|
20551
20752
|
"kind": "Class",
|
|
20552
20753
|
"canonicalReference": "@genesislcap/ai-assistant!FoundationAiAssistant:class",
|
|
@@ -41441,6 +41642,69 @@
|
|
|
41441
41642
|
"endIndex": 2
|
|
41442
41643
|
}
|
|
41443
41644
|
},
|
|
41645
|
+
{
|
|
41646
|
+
"kind": "PropertySignature",
|
|
41647
|
+
"canonicalReference": "@genesislcap/ai-assistant!StatefulAgentInit#finishGuard:member",
|
|
41648
|
+
"docComment": "/**\n * Hook consulted when the model replies with no tool call, so the turn would end (U1). Receives the live `state` alongside the reply and `continuations` (how many times this hook has held the current turn open), so a machine agent can read its own step and buffer:\n *\n * - `{ action: 'continue', note }` holds the turn open: the note is stored in history as a hidden model-facing message and the driver makes the next model call in the same turn. - `{ action: 'end', release: true }` ends the turn and releases this agent, as `releaseAgent()` from a tool handler would (U5) — the way to drop the flow lock when the flow ends in prose, e.g. a question answered without a tool call. - `{ action: 'end' }` or `undefined` ends the turn as usual.\n *\n * Enforce a per-turn cap with `continuations`; the driver's iteration cap bounds it regardless. A pre-init call, or a thrown error, ends the turn as if there were no hook. See {@link FinishGuardVerdict}.\n *\n * @example\n * ```ts\n * finishGuard: ({ state, continuations }) => {\n * if (continuations >= 2) return { action: 'end' };\n * const v = stopGuardVerdict(state.machine, state.buffer);\n * if (v.hold) return { action: 'continue', note: v.note };\n * return { action: 'end', release: state.machine.state === 'answered' };\n * },\n * ```\n *\n */\n",
|
|
41649
|
+
"excerptTokens": [
|
|
41650
|
+
{
|
|
41651
|
+
"kind": "Content",
|
|
41652
|
+
"text": "finishGuard?: "
|
|
41653
|
+
},
|
|
41654
|
+
{
|
|
41655
|
+
"kind": "Content",
|
|
41656
|
+
"text": "(ctx: "
|
|
41657
|
+
},
|
|
41658
|
+
{
|
|
41659
|
+
"kind": "Reference",
|
|
41660
|
+
"text": "FinishGuardContext",
|
|
41661
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardContext:interface"
|
|
41662
|
+
},
|
|
41663
|
+
{
|
|
41664
|
+
"kind": "Content",
|
|
41665
|
+
"text": " & {\n state: S;\n }) => "
|
|
41666
|
+
},
|
|
41667
|
+
{
|
|
41668
|
+
"kind": "Reference",
|
|
41669
|
+
"text": "FinishGuardVerdict",
|
|
41670
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardVerdict:type"
|
|
41671
|
+
},
|
|
41672
|
+
{
|
|
41673
|
+
"kind": "Content",
|
|
41674
|
+
"text": " | undefined | "
|
|
41675
|
+
},
|
|
41676
|
+
{
|
|
41677
|
+
"kind": "Reference",
|
|
41678
|
+
"text": "Promise",
|
|
41679
|
+
"canonicalReference": "!Promise:interface"
|
|
41680
|
+
},
|
|
41681
|
+
{
|
|
41682
|
+
"kind": "Content",
|
|
41683
|
+
"text": "<"
|
|
41684
|
+
},
|
|
41685
|
+
{
|
|
41686
|
+
"kind": "Reference",
|
|
41687
|
+
"text": "FinishGuardVerdict",
|
|
41688
|
+
"canonicalReference": "@genesislcap/ai-assistant!FinishGuardVerdict:type"
|
|
41689
|
+
},
|
|
41690
|
+
{
|
|
41691
|
+
"kind": "Content",
|
|
41692
|
+
"text": " | undefined>"
|
|
41693
|
+
},
|
|
41694
|
+
{
|
|
41695
|
+
"kind": "Content",
|
|
41696
|
+
"text": ";"
|
|
41697
|
+
}
|
|
41698
|
+
],
|
|
41699
|
+
"isReadonly": false,
|
|
41700
|
+
"isOptional": true,
|
|
41701
|
+
"releaseTag": "Beta",
|
|
41702
|
+
"name": "finishGuard",
|
|
41703
|
+
"propertyTypeTokenRange": {
|
|
41704
|
+
"startIndex": 1,
|
|
41705
|
+
"endIndex": 10
|
|
41706
|
+
}
|
|
41707
|
+
},
|
|
41444
41708
|
{
|
|
41445
41709
|
"kind": "PropertySignature",
|
|
41446
41710
|
"canonicalReference": "@genesislcap/ai-assistant!StatefulAgentInit#getDebugSnapshot:member",
|
package/dist/ai-assistant.d.ts
CHANGED
|
@@ -2513,6 +2513,16 @@ declare interface BaseAgentConfig {
|
|
|
2513
2513
|
* @beta
|
|
2514
2514
|
*/
|
|
2515
2515
|
onUnresolvedTool?: UnresolvedToolInput;
|
|
2516
|
+
/**
|
|
2517
|
+
* Optional hook consulted when the model replies with no tool call, so the turn would end. Answer
|
|
2518
|
+
* `{ action: 'continue', note }` to hold the turn open with a stored note, `{ action: 'end',
|
|
2519
|
+
* release: true }` to end it and release the agent (a prose answer has no handler context to call
|
|
2520
|
+
* `releaseAgent()` from), or `undefined` to end it as usual. `ctx.continuations` counts this
|
|
2521
|
+
* hook's holds this turn, for a per-turn cap. See {@link FinishGuardInput}.
|
|
2522
|
+
*
|
|
2523
|
+
* @beta
|
|
2524
|
+
*/
|
|
2525
|
+
finishGuard?: FinishGuardInput;
|
|
2516
2526
|
/**
|
|
2517
2527
|
* Optional primer history prepended to every call (not visible to the user).
|
|
2518
2528
|
* Used to establish agent identity and behavioural rules.
|
|
@@ -3190,6 +3200,8 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
3190
3200
|
* `resolveUnresolvedToolContent`.
|
|
3191
3201
|
*/
|
|
3192
3202
|
private activeOnUnresolvedTool?;
|
|
3203
|
+
/** The active agent's `finishGuard` hook (U1), consulted by `consultFinishGuard`. */
|
|
3204
|
+
private activeFinishGuard?;
|
|
3193
3205
|
/**
|
|
3194
3206
|
* Caches validated provider lookups per name within the current agent. Cleared
|
|
3195
3207
|
* by `installAgent` so each new agent's static/function-resolved names are
|
|
@@ -3597,6 +3609,20 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
3597
3609
|
* can never break tool dispatch.
|
|
3598
3610
|
*/
|
|
3599
3611
|
private resolveUnresolvedToolContent;
|
|
3612
|
+
/**
|
|
3613
|
+
* Consult the active agent's `finishGuard` hook (U1) after a reply with no tool call. Returns the
|
|
3614
|
+
* verdict, normalised: `undefined` when there is no hook, it answered nothing, it threw, or it
|
|
3615
|
+
* answered `'continue'` with a blank note (nothing to tell the model, so nothing to hold for). A
|
|
3616
|
+
* misbehaving hook can never break the turn: it ends as if there were no hook.
|
|
3617
|
+
*/
|
|
3618
|
+
private consultFinishGuard;
|
|
3619
|
+
/**
|
|
3620
|
+
* Act on a finish guard's `{ action: 'end', release: true }` (U5): the same release a tool handler's
|
|
3621
|
+
* `releaseAgent()` asks for, for a turn that ended in prose and so had no handler context to call
|
|
3622
|
+
* it from. Subject to the same guards: not after a hand-off, not twice, and not on a sub-agent,
|
|
3623
|
+
* which owns no flow lock (it ends with `completeSubAgent`). Returns whether it released.
|
|
3624
|
+
*/
|
|
3625
|
+
private requestReleaseFromFinishGuard;
|
|
3600
3626
|
/**
|
|
3601
3627
|
* Returns the most recently resolved provider name. Falls back to the
|
|
3602
3628
|
* registry's default when no per-turn resolution has happened yet.
|
|
@@ -5056,6 +5082,75 @@ export declare interface FallbackAgentConfig extends BaseAgentConfig {
|
|
|
5056
5082
|
description?: never;
|
|
5057
5083
|
}
|
|
5058
5084
|
|
|
5085
|
+
/**
|
|
5086
|
+
* Context passed to an agent's `finishGuard` hook: the model has just replied with no tool call, so
|
|
5087
|
+
* the turn is about to end. The standard {@link SystemPromptContext} plus the reply and how many
|
|
5088
|
+
* times this guard has already held the turn open.
|
|
5089
|
+
*
|
|
5090
|
+
* @beta
|
|
5091
|
+
*/
|
|
5092
|
+
export declare interface FinishGuardContext extends SystemPromptContext {
|
|
5093
|
+
/** The text of the reply that would end the turn. Already in `history`. */
|
|
5094
|
+
reply: string;
|
|
5095
|
+
/**
|
|
5096
|
+
* How many times this guard has answered `'continue'` in the current turn (0 the first time it is
|
|
5097
|
+
* consulted). Enforce your own per-turn cap with it: answer `'end'` once it reaches the cap. The
|
|
5098
|
+
* driver's completion nudges to a sub-agent are not counted.
|
|
5099
|
+
*/
|
|
5100
|
+
continuations: number;
|
|
5101
|
+
/**
|
|
5102
|
+
* Whether a `'continue'` answer would be honoured. `false` on the tool loop's last iteration
|
|
5103
|
+
* (`maxToolIterations`), where there is no call left to hold the turn open for: a `'continue'`
|
|
5104
|
+
* then ends the turn, while `{ action: 'end', release: true }` still releases the agent (and the
|
|
5105
|
+
* turn ends cleanly, not as the iteration cap).
|
|
5106
|
+
*/
|
|
5107
|
+
canContinue: boolean;
|
|
5108
|
+
}
|
|
5109
|
+
|
|
5110
|
+
/**
|
|
5111
|
+
* Optional per-agent hook consulted when a model reply in the tool loop carries no tool call, so
|
|
5112
|
+
* the turn would end. Lets the agent hold the turn open with a note ("your change is not applied
|
|
5113
|
+
* yet …"), or end it and release the agent. See {@link FinishGuardVerdict}.
|
|
5114
|
+
*
|
|
5115
|
+
* Return `undefined` (or throw) to end the turn as if there were no hook. Not consulted on a
|
|
5116
|
+
* closing call, nor after a tool handler released the agent earlier in the turn. A continuation spends a tool-loop iteration, so `maxToolIterations` also bounds a
|
|
5117
|
+
* guard that never says `'end'`: on the last iteration (`ctx.canContinue === false`) a
|
|
5118
|
+
* `'continue'` ends the turn, though a release is still honoured. Use `ctx.continuations` for a
|
|
5119
|
+
* tighter per-turn cap. A turn stopped while the hook is pending ends as stopped, whatever it
|
|
5120
|
+
* answers.
|
|
5121
|
+
*
|
|
5122
|
+
* On a sub-agent, which succeeds only by calling `completeSubAgent`, prose is never an answer:
|
|
5123
|
+
* `'end'` gives up (the sub-agent fails, as it does today), `release` is ignored, and when the hook
|
|
5124
|
+
* answers nothing (or there is no hook) the driver holds the turn itself with a completion nudge,
|
|
5125
|
+
* asking for the completion call (`driverNote: 'completion-nudge'`), up to twice per turn.
|
|
5126
|
+
*
|
|
5127
|
+
* @beta
|
|
5128
|
+
*/
|
|
5129
|
+
export declare type FinishGuardInput = (ctx: FinishGuardContext) => FinishGuardVerdict | undefined | Promise<FinishGuardVerdict | undefined>;
|
|
5130
|
+
|
|
5131
|
+
/**
|
|
5132
|
+
* What an agent's `finishGuard` hook answers when the model replies with no tool call.
|
|
5133
|
+
*
|
|
5134
|
+
* - `{ action: 'end' }`: let the turn end, as it would with no hook.
|
|
5135
|
+
* - `{ action: 'end', release: true }`: end the turn and release the agent, exactly as a tool
|
|
5136
|
+
* handler calling `releaseAgent()` would. A turn that ends in prose has no handler context, so
|
|
5137
|
+
* this is the only way such a turn can release the flow lock (e.g. a question answered in prose).
|
|
5138
|
+
* - `{ action: 'continue', note }`: hold the turn open. The driver stores `note` in history as a
|
|
5139
|
+
* model-facing message (`role: 'user'`, `driverNote: 'finish-guard'`, framed as a
|
|
5140
|
+
* `<system-reminder>`, hidden from the transcript) and makes the next model call in the same
|
|
5141
|
+
* turn. Stored rather than sent once in the tail, so later calls and later turns see why the turn
|
|
5142
|
+
* went on, and it sits between the two assistant replies so they are never merged.
|
|
5143
|
+
*
|
|
5144
|
+
* @beta
|
|
5145
|
+
*/
|
|
5146
|
+
export declare type FinishGuardVerdict = {
|
|
5147
|
+
action: 'end';
|
|
5148
|
+
release?: boolean;
|
|
5149
|
+
} | {
|
|
5150
|
+
action: 'continue';
|
|
5151
|
+
note: string;
|
|
5152
|
+
};
|
|
5153
|
+
|
|
5059
5154
|
/**
|
|
5060
5155
|
* Banner copy built from the figures a 402 actually reported, or `undefined`
|
|
5061
5156
|
* when the proxy sent none.
|
|
@@ -10138,6 +10233,35 @@ export declare interface StatefulAgentInit<S> {
|
|
|
10138
10233
|
onUnresolvedTool?: (ctx: UnresolvedToolContext & {
|
|
10139
10234
|
state: S;
|
|
10140
10235
|
}) => string | undefined | Promise<string | undefined>;
|
|
10236
|
+
/**
|
|
10237
|
+
* Hook consulted when the model replies with no tool call, so the turn would end (U1). Receives the
|
|
10238
|
+
* live `state` alongside the reply and `continuations` (how many times this hook has held the
|
|
10239
|
+
* current turn open), so a machine agent can read its own step and buffer:
|
|
10240
|
+
*
|
|
10241
|
+
* - `{ action: 'continue', note }` holds the turn open: the note is stored in history as a hidden
|
|
10242
|
+
* model-facing message and the driver makes the next model call in the same turn.
|
|
10243
|
+
* - `{ action: 'end', release: true }` ends the turn and releases this agent, as `releaseAgent()`
|
|
10244
|
+
* from a tool handler would (U5) — the way to drop the flow lock when the flow ends in prose,
|
|
10245
|
+
* e.g. a question answered without a tool call.
|
|
10246
|
+
* - `{ action: 'end' }` or `undefined` ends the turn as usual.
|
|
10247
|
+
*
|
|
10248
|
+
* Enforce a per-turn cap with `continuations`; the driver's iteration cap bounds it regardless.
|
|
10249
|
+
* A pre-init call, or a thrown error, ends the turn as if there were no hook.
|
|
10250
|
+
* See {@link FinishGuardVerdict}.
|
|
10251
|
+
*
|
|
10252
|
+
* @example
|
|
10253
|
+
* ```ts
|
|
10254
|
+
* finishGuard: ({ state, continuations }) => {
|
|
10255
|
+
* if (continuations >= 2) return { action: 'end' };
|
|
10256
|
+
* const v = stopGuardVerdict(state.machine, state.buffer);
|
|
10257
|
+
* if (v.hold) return { action: 'continue', note: v.note };
|
|
10258
|
+
* return { action: 'end', release: state.machine.state === 'answered' };
|
|
10259
|
+
* },
|
|
10260
|
+
* ```
|
|
10261
|
+
*/
|
|
10262
|
+
finishGuard?: (ctx: FinishGuardContext & {
|
|
10263
|
+
state: S;
|
|
10264
|
+
}) => FinishGuardVerdict | undefined | Promise<FinishGuardVerdict | undefined>;
|
|
10141
10265
|
/**
|
|
10142
10266
|
* Optional getter for the debug-log snapshot. Defaults to auto-snapshotting
|
|
10143
10267
|
* any property on `state` that looks like a foundation-state-machine
|