agentfootprint 14.2.0 → 14.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/AGENTS.md +2 -2
- package/CAPABILITIES.md +2 -0
- package/ai-instructions/claude-code/SKILL.md +2 -2
- package/dist/adapters/observability/auditShapes.js +8 -9
- package/dist/adapters/observability/auditShapes.js.map +1 -1
- package/dist/core/Agent.js +91 -158
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +29 -69
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/aroundTurn/errors.js +38 -0
- package/dist/core/agent/aroundTurn/errors.js.map +1 -0
- package/dist/core/agent/aroundTurn/funnel.js +164 -0
- package/dist/core/agent/aroundTurn/funnel.js.map +1 -0
- package/dist/core/agent/aroundTurn/guards.js +34 -0
- package/dist/core/agent/aroundTurn/guards.js.map +1 -0
- package/dist/core/agent/aroundTurn/index.js +13 -0
- package/dist/core/agent/aroundTurn/index.js.map +1 -0
- package/dist/core/agent/aroundTurn/readOnlyCopy.js +52 -0
- package/dist/core/agent/aroundTurn/readOnlyCopy.js.map +1 -0
- package/dist/core/agent/aroundTurn/types.js +6 -0
- package/dist/core/agent/aroundTurn/types.js.map +1 -0
- package/dist/core/agent/assessment/answerLayerOptions.js +72 -0
- package/dist/core/agent/assessment/answerLayerOptions.js.map +1 -0
- package/dist/core/agent/hostTurn.js +1 -0
- package/dist/core/agent/hostTurn.js.map +1 -1
- package/dist/core/agent/run/eventStageIds.js +6 -1
- package/dist/core/agent/run/eventStageIds.js.map +1 -1
- package/dist/core/agent/run/outputStrategySupport.js +62 -0
- package/dist/core/agent/run/outputStrategySupport.js.map +1 -0
- package/dist/core/agent/run/terminalRunError.js +44 -0
- package/dist/core/agent/run/terminalRunError.js.map +1 -0
- package/dist/core/runnerLive.js.map +1 -1
- package/dist/doors/time.js +11 -3
- package/dist/doors/time.js.map +1 -1
- package/dist/esm/adapters/observability/auditShapes.js +8 -9
- package/dist/esm/adapters/observability/auditShapes.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +13 -27
- package/dist/esm/core/Agent.js +86 -153
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +22 -0
- package/dist/esm/core/agent/AgentBuilder.js +27 -67
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/aroundTurn/errors.d.ts +15 -0
- package/dist/esm/core/agent/aroundTurn/errors.js +34 -0
- package/dist/esm/core/agent/aroundTurn/errors.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/funnel.d.ts +18 -0
- package/dist/esm/core/agent/aroundTurn/funnel.js +159 -0
- package/dist/esm/core/agent/aroundTurn/funnel.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/guards.d.ts +16 -0
- package/dist/esm/core/agent/aroundTurn/guards.js +28 -0
- package/dist/esm/core/agent/aroundTurn/guards.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/index.d.ts +4 -0
- package/dist/esm/core/agent/aroundTurn/index.js +4 -0
- package/dist/esm/core/agent/aroundTurn/index.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.d.ts +12 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.js +48 -0
- package/dist/esm/core/agent/aroundTurn/readOnlyCopy.js.map +1 -0
- package/dist/esm/core/agent/aroundTurn/types.d.ts +57 -0
- package/dist/esm/core/agent/aroundTurn/types.js +5 -0
- package/dist/esm/core/agent/aroundTurn/types.js.map +1 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.d.ts +21 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.js +67 -0
- package/dist/esm/core/agent/assessment/answerLayerOptions.js.map +1 -0
- package/dist/esm/core/agent/hostTurn.d.ts +2 -0
- package/dist/esm/core/agent/hostTurn.js +1 -0
- package/dist/esm/core/agent/hostTurn.js.map +1 -1
- package/dist/esm/core/agent/run/eventStageIds.d.ts +5 -0
- package/dist/esm/core/agent/run/eventStageIds.js +5 -0
- package/dist/esm/core/agent/run/eventStageIds.js.map +1 -1
- package/dist/esm/core/agent/run/outputStrategySupport.d.ts +26 -0
- package/dist/esm/core/agent/run/outputStrategySupport.js +58 -0
- package/dist/esm/core/agent/run/outputStrategySupport.js.map +1 -0
- package/dist/esm/core/agent/run/terminalRunError.d.ts +22 -0
- package/dist/esm/core/agent/run/terminalRunError.js +40 -0
- package/dist/esm/core/agent/run/terminalRunError.js.map +1 -0
- package/dist/esm/core/runnerLive.d.ts +3 -0
- package/dist/esm/core/runnerLive.js.map +1 -1
- package/dist/esm/doors/time.d.ts +9 -2
- package/dist/esm/doors/time.js +9 -2
- package/dist/esm/doors/time.js.map +1 -1
- package/dist/esm/events/dispatcher.d.ts +4 -4
- package/dist/esm/events/dispatcher.js +4 -4
- package/dist/esm/events/payloads/agent.d.ts +8 -0
- package/dist/esm/events/payloads.d.ts +1 -1
- package/dist/esm/events/registry.d.ts +4 -5
- package/dist/esm/events/registry.js +4 -7
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/hosting/errors.d.ts +18 -15
- package/dist/esm/hosting/errors.js +23 -22
- package/dist/esm/hosting/errors.js.map +1 -1
- package/dist/esm/hosting/index.d.ts +2 -1
- package/dist/esm/hosting/index.js +2 -1
- package/dist/esm/hosting/index.js.map +1 -1
- package/dist/esm/hosting/requireCapability.d.ts +8 -0
- package/dist/esm/hosting/requireCapability.js +16 -0
- package/dist/esm/hosting/requireCapability.js.map +1 -0
- package/dist/esm/hosting/standingAgent.js +33 -34
- package/dist/esm/hosting/standingAgent.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +6 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/locales/timeAsk.js +1 -1
- package/dist/esm/locales/timeAsk.js.map +1 -1
- package/dist/esm/redaction/knownStrings.d.ts +3 -5
- package/dist/esm/redaction/knownStrings.js +2 -0
- package/dist/esm/redaction/knownStrings.js.map +1 -1
- package/dist/esm/time/readers/english/grammar.d.ts +3 -3
- package/dist/esm/time/readers/english/grammar.js +4 -4
- package/dist/esm/time/readers/english/grammar.js.map +1 -1
- package/dist/esm/time/readers/english.d.ts +1 -1
- package/dist/esm/time/readers/english.js +1 -1
- package/dist/esm/time/replyForm/bindings.d.ts +20 -1
- package/dist/esm/time/replyForm/bindings.js +31 -12
- package/dist/esm/time/replyForm/bindings.js.map +1 -1
- package/dist/events/dispatcher.js +4 -4
- package/dist/events/registry.js +4 -7
- package/dist/events/registry.js.map +1 -1
- package/dist/hosting/errors.js +25 -24
- package/dist/hosting/errors.js.map +1 -1
- package/dist/hosting/index.js +6 -4
- package/dist/hosting/index.js.map +1 -1
- package/dist/hosting/requireCapability.js +20 -0
- package/dist/hosting/requireCapability.js.map +1 -0
- package/dist/hosting/standingAgent.js +32 -33
- package/dist/hosting/standingAgent.js.map +1 -1
- package/dist/index.js +122 -131
- package/dist/index.js.map +1 -1
- package/dist/locales/timeAsk.js +1 -1
- package/dist/locales/timeAsk.js.map +1 -1
- package/dist/redaction/knownStrings.js +2 -0
- package/dist/redaction/knownStrings.js.map +1 -1
- package/dist/time/readers/english/grammar.js +4 -4
- package/dist/time/readers/english/grammar.js.map +1 -1
- package/dist/time/readers/english.js +1 -1
- package/dist/time/replyForm/bindings.js +31 -12
- package/dist/time/replyForm/bindings.js.map +1 -1
- package/dist/types/core/Agent.d.ts +13 -27
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts +22 -0
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/aroundTurn/errors.d.ts +16 -0
- package/dist/types/core/agent/aroundTurn/errors.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/funnel.d.ts +19 -0
- package/dist/types/core/agent/aroundTurn/funnel.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/guards.d.ts +17 -0
- package/dist/types/core/agent/aroundTurn/guards.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/index.d.ts +5 -0
- package/dist/types/core/agent/aroundTurn/index.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/readOnlyCopy.d.ts +13 -0
- package/dist/types/core/agent/aroundTurn/readOnlyCopy.d.ts.map +1 -0
- package/dist/types/core/agent/aroundTurn/types.d.ts +58 -0
- package/dist/types/core/agent/aroundTurn/types.d.ts.map +1 -0
- package/dist/types/core/agent/assessment/answerLayerOptions.d.ts +22 -0
- package/dist/types/core/agent/assessment/answerLayerOptions.d.ts.map +1 -0
- package/dist/types/core/agent/hostTurn.d.ts +2 -0
- package/dist/types/core/agent/hostTurn.d.ts.map +1 -1
- package/dist/types/core/agent/run/eventStageIds.d.ts +5 -0
- package/dist/types/core/agent/run/eventStageIds.d.ts.map +1 -1
- package/dist/types/core/agent/run/outputStrategySupport.d.ts +27 -0
- package/dist/types/core/agent/run/outputStrategySupport.d.ts.map +1 -0
- package/dist/types/core/agent/run/terminalRunError.d.ts +23 -0
- package/dist/types/core/agent/run/terminalRunError.d.ts.map +1 -0
- package/dist/types/core/runnerLive.d.ts +3 -0
- package/dist/types/core/runnerLive.d.ts.map +1 -1
- package/dist/types/doors/time.d.ts +9 -2
- package/dist/types/doors/time.d.ts.map +1 -1
- package/dist/types/events/dispatcher.d.ts +4 -4
- package/dist/types/events/payloads/agent.d.ts +8 -0
- package/dist/types/events/payloads/agent.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +1 -1
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +4 -5
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/hosting/errors.d.ts +18 -15
- package/dist/types/hosting/errors.d.ts.map +1 -1
- package/dist/types/hosting/index.d.ts +2 -1
- package/dist/types/hosting/index.d.ts.map +1 -1
- package/dist/types/hosting/requireCapability.d.ts +9 -0
- package/dist/types/hosting/requireCapability.d.ts.map +1 -0
- package/dist/types/hosting/standingAgent.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/redaction/knownStrings.d.ts +3 -5
- package/dist/types/redaction/knownStrings.d.ts.map +1 -1
- package/dist/types/time/readers/english/grammar.d.ts +3 -3
- package/dist/types/time/readers/english/grammar.d.ts.map +1 -1
- package/dist/types/time/readers/english.d.ts +1 -1
- package/dist/types/time/replyForm/bindings.d.ts +20 -1
- package/dist/types/time/replyForm/bindings.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/core/Agent.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { refuseFollowUpIdentity, refuseKnownSpentAnswer, refuseMissingPlainAnswer, } from './agent/resumeAnswer.js';
|
|
2
2
|
import { hostedTurns } from './agent/hostTurn.js';
|
|
3
|
+
import { refuseMountedWrapper, replacedTurnMethods, runInputWith, throughAroundTurn, } from './agent/aroundTurn/index.js';
|
|
4
|
+
import { assertOutputStrategySupported } from './agent/run/outputStrategySupport.js';
|
|
5
|
+
import { isTerminalRunError } from './agent/run/terminalRunError.js';
|
|
3
6
|
import { componentResources } from './agent/componentResources.js';
|
|
4
7
|
import { resumeStateOf, resumeSessionOf } from './agent/resumeCheckpoint.js';
|
|
5
8
|
import { capturePauseOwnership, pendingQuestionOf, preservePendingQuestion, abandonStoredPause, abandonPendingQuestion, } from './agent/pauseOwnership.js';
|
|
@@ -9,15 +12,10 @@ import { bindScopeComputation, captureLateEmitter } from '../redaction/runRedact
|
|
|
9
12
|
import { createAgentRunValues } from './agent/runValues.js';
|
|
10
13
|
import { bindRunnerStage, } from './runnerExecution.js';
|
|
11
14
|
import { findingsContextBytes } from './agent/findings/context.js';
|
|
12
|
-
import { ReliabilityFailFastError } from '../reliability/types.js';
|
|
13
15
|
import { extractSequence } from '../security/extractSequence.js';
|
|
14
|
-
import { PolicyHaltError } from '../security/PolicyHaltError.js';
|
|
15
16
|
import { updateSkillHistory as updateSkillHistoryStage } from '../cache/CacheGateDecider.js';
|
|
16
17
|
import { cacheStrategyFor } from '../cache/cacheStrategyFor.js';
|
|
17
18
|
import { cacheRequestedWithoutSupport } from './agent/cacheSupport.js';
|
|
18
|
-
import { forcedToolChoiceFor, UnsupportedToolChoiceError, } from '../provider-contract/forcedToolChoice.js';
|
|
19
|
-
import { nativeOutputSchemaFor, UnsupportedNativeOutputError, } from '../provider-contract/nativeOutputSchema.js';
|
|
20
|
-
import { isRequestRefusal } from '../provider-contract/requestRefusal.js';
|
|
21
19
|
import { assistantReplayFields } from './agent/assistantReplay.js';
|
|
22
20
|
import { buildBrainFor, describeServingBrain } from './agent/skillBrains.js';
|
|
23
21
|
import { SUBFLOW_IDS } from '../lib/conventions.js';
|
|
@@ -68,7 +66,6 @@ import { requireKeepLastToolResults } from './agent/window/options.js';
|
|
|
68
66
|
import { buildDeliverStage } from './agent/stages/deliver.js';
|
|
69
67
|
import { providerTargets } from './agent/providerTargets.js';
|
|
70
68
|
import { assertInjectionDelivery } from './agent/run/injectionDelivery.js';
|
|
71
|
-
import { CompactionUnmeasurableError } from './agent/window/errors.js';
|
|
72
69
|
import { resolveCheckInConfig, } from './checkin.js';
|
|
73
70
|
import { assertCostBudgetHasPricing, resolveCostBudget } from './cost.js';
|
|
74
71
|
import { buildSystemPromptSlot } from './slots/buildSystemPromptSlot.js';
|
|
@@ -86,7 +83,6 @@ import { failFastRecordOf } from '../reliability/failFastRecord.js';
|
|
|
86
83
|
import { terminalErrorOf } from './terminalVerdict.js';
|
|
87
84
|
import { isValidatedDelivery } from './agent/stages/breakFinal.js';
|
|
88
85
|
import { evidenceRefusalSentence } from './agent/evidence/gate.js';
|
|
89
|
-
import { UnsupportedValuesError } from './agent/evidence/errors.js';
|
|
90
86
|
import { checkerGoverns } from '../provider-contract/types.js';
|
|
91
87
|
import { skillTarget } from '../security/skillTarget.js';
|
|
92
88
|
import { buildInjectionEngineSubflow } from '../injection-engine/buildInjectionEngineSubflow.js';
|
|
@@ -111,7 +107,7 @@ import { negativeRecheckStage } from './agent/negativeClaims/recheck.js';
|
|
|
111
107
|
import { withAnswerValidation } from './agent/stages/answerValidation.js';
|
|
112
108
|
import { hasOutputMiddleware } from './agent/middleware/messagePhase.js';
|
|
113
109
|
import { withAnswerCoverage } from './agent/stages/answerCoverage.js';
|
|
114
|
-
import {
|
|
110
|
+
import { resolveAnswerValidation, } from '../answer-validation/index.js';
|
|
115
111
|
import { buildSeedStage } from './agent/stages/seed.js';
|
|
116
112
|
import { buildCallLLMStage } from './agent/stages/callLLM.js';
|
|
117
113
|
import { buildToolCallsHandler, notServedResult } from './agent/stages/toolCalls/index.js';
|
|
@@ -131,7 +127,7 @@ import { buildToolRegistry } from './agent/buildToolRegistry.js';
|
|
|
131
127
|
import { AgentBuilder } from './agent/AgentBuilder.js';
|
|
132
128
|
import { buildThinkingSubflow } from './slots/buildThinkingSubflow.js';
|
|
133
129
|
import { thinkingForProviders } from '../thinking/dispatch.js';
|
|
134
|
-
import { TOOL_TEARDOWN_STAGE_ID, LATE_ARTIFACT_FACT_STAGE_ID, RUN_MANIFEST_STAGE_ID, INTEGRITY_DISPOSITION_STAGE_ID, GRAPH_DECLARED_STAGE_ID, } from './agent/run/eventStageIds.js';
|
|
130
|
+
import { TOOL_TEARDOWN_STAGE_ID, LATE_ARTIFACT_FACT_STAGE_ID, RUN_MANIFEST_STAGE_ID, AROUND_TURN_STAGE_ID, INTEGRITY_DISPOSITION_STAGE_ID, GRAPH_DECLARED_STAGE_ID, } from './agent/run/eventStageIds.js';
|
|
135
131
|
import { requireKeepLedgerFacts, resolveKeepLedgerFacts } from './agent/run/ledgerFacts.js';
|
|
136
132
|
import { withoutTime } from './agent/run/withoutTime.js';
|
|
137
133
|
import { resumeRedactionOf } from './agent/run/resumeRedaction.js';
|
|
@@ -360,6 +356,8 @@ export class Agent extends RunnerBase {
|
|
|
360
356
|
/** The message chain (`.messageMiddleware()`), in declaration order. Empty
|
|
361
357
|
* keeps seed synchronous and prepare-final untouched. */
|
|
362
358
|
messageMiddleware;
|
|
359
|
+
/** `.aroundTurn()`, or undefined: the funnel then adds nothing to a turn. */
|
|
360
|
+
aroundTurnPort;
|
|
363
361
|
/** Snapshot read-tracking policy (#18/#14) — forwarded to the internal
|
|
364
362
|
* executor. Agent default is `'summary'` (cheap markers), NOT
|
|
365
363
|
* footprintjs's `'full'`. See AgentOptions.readTracking. */
|
|
@@ -634,7 +632,7 @@ export class Agent extends RunnerBase {
|
|
|
634
632
|
negativeClaimsConfig;
|
|
635
633
|
typedNegativeClaimsConfig;
|
|
636
634
|
applicationAnswerValidation;
|
|
637
|
-
constructor(opts, systemPromptValue, registry, voice, injections = [], memories = [], outputSchemaParser, toolProvider, systemPromptCachePolicy = 'always', cachingDisabled = false, cacheStrategy, outputFallbackCfg, reliabilityConfig, thinkingHandlerValue, thinkingBudgetValue, skillGraphNextSkill, skillGraphReachable, skillGraphScoreEntries, checkInOptions, runConfigFn, windowStrategy, toolMiddleware, messageMiddleware, outputEnforcement, skillGraphEdgeTargets, skillGraphExplainNextSkill, skillGraphIsTree, skillGraphSupersededEntries, skillGraphCascade, skillBrains, evidenceGate, limitsTravelWithTheAnswer, recipes, skillGraphDeclared, mapsPlan, claimContract, answerValidationConfig, systemPromptCacheExplicit = false, negativeClaimsConfig, scriptTravel) {
|
|
635
|
+
constructor(opts, systemPromptValue, registry, voice, injections = [], memories = [], outputSchemaParser, toolProvider, systemPromptCachePolicy = 'always', cachingDisabled = false, cacheStrategy, outputFallbackCfg, reliabilityConfig, thinkingHandlerValue, thinkingBudgetValue, skillGraphNextSkill, skillGraphReachable, skillGraphScoreEntries, checkInOptions, runConfigFn, windowStrategy, toolMiddleware, messageMiddleware, outputEnforcement, skillGraphEdgeTargets, skillGraphExplainNextSkill, skillGraphIsTree, skillGraphSupersededEntries, skillGraphCascade, skillBrains, evidenceGate, limitsTravelWithTheAnswer, recipes, skillGraphDeclared, mapsPlan, claimContract, answerValidationConfig, systemPromptCacheExplicit = false, negativeClaimsConfig, scriptTravel, aroundTurn) {
|
|
638
636
|
super();
|
|
639
637
|
// Which conversation this instance's self-explain evidence belongs to —
|
|
640
638
|
// held in a module registry, not on the class, so it is not public API
|
|
@@ -773,7 +771,7 @@ export class Agent extends RunnerBase {
|
|
|
773
771
|
if (opts.answerLayer === true)
|
|
774
772
|
this.answerLayerOption = {};
|
|
775
773
|
else if (typeof opts.answerLayer === 'object' && opts.answerLayer !== null) {
|
|
776
|
-
// The builder judged the option (`
|
|
774
|
+
// The builder judged the option (`assessment/answerLayerOptions.ts` · `answerLayerArm`); `true` is 'always'.
|
|
777
775
|
const line = opts.answerLayer.standingLine;
|
|
778
776
|
this.answerLayerOption =
|
|
779
777
|
line === true
|
|
@@ -846,6 +844,7 @@ export class Agent extends RunnerBase {
|
|
|
846
844
|
// call that provably never ran from one whose outcome is not known.
|
|
847
845
|
registerConsentLedger(this, this.decisionLedger);
|
|
848
846
|
this.messageMiddleware = messageMiddleware ?? [];
|
|
847
|
+
this.aroundTurnPort = aroundTurn;
|
|
849
848
|
// Default 'summary' — measurement-gated (#18): stageReads values have
|
|
850
849
|
// zero consumers across af/lens/eui, and 'full' clones ~18MB of unread
|
|
851
850
|
// data per 200 iterations. Consumers opt into 'full' explicitly.
|
|
@@ -1094,6 +1093,10 @@ export class Agent extends RunnerBase {
|
|
|
1094
1093
|
return {
|
|
1095
1094
|
recorder: observers.recorder,
|
|
1096
1095
|
bindScope: (scope) => {
|
|
1096
|
+
// No entry: mounted in a run this agent did not start. Refused as its
|
|
1097
|
+
// first stage opens, where the mounting run's recorders hear the name.
|
|
1098
|
+
if (entry === undefined)
|
|
1099
|
+
refuseMountedWrapper(this.aroundTurnPort);
|
|
1097
1100
|
const run = this.runExecution().forScope(scope);
|
|
1098
1101
|
value.resources?.bindReporter((status) => captureLateEmitter(scope, TOOL_TEARDOWN_STAGE_ID)?.('agentfootprint.tools.resource_restore', status));
|
|
1099
1102
|
bindScopeComputation(scope, {
|
|
@@ -1115,6 +1118,7 @@ export class Agent extends RunnerBase {
|
|
|
1115
1118
|
resume: (run, checkpoint, input, options) => this.resumeOwned(run, checkpoint, input, options),
|
|
1116
1119
|
prepareResume: (checkpoint) => this.noteResumeTakenUp(checkpoint),
|
|
1117
1120
|
checkpoint: (run) => this.checkpointFor(run),
|
|
1121
|
+
replaced: () => replacedTurnMethods(this, OWN_TURN_METHODS),
|
|
1118
1122
|
}),
|
|
1119
1123
|
pause: {
|
|
1120
1124
|
capture: (outcome) => capturePauseOwnership(this.runExecution().selected()?.value, outcome),
|
|
@@ -1499,39 +1503,42 @@ export class Agent extends RunnerBase {
|
|
|
1499
1503
|
throw new Error(`Agent.runTyped: this agent has no outputSchema. Use ` +
|
|
1500
1504
|
`Agent.create({...}).outputSchema(parser).build() to enable typed output.`);
|
|
1501
1505
|
}
|
|
1502
|
-
|
|
1503
|
-
if (typeof out !== 'string') {
|
|
1504
|
-
throw new Error('Agent.runTyped: run paused — typed mode does not support pauses. ' +
|
|
1505
|
-
'Use agent.run() + agent.parseOutput(...) after resume.');
|
|
1506
|
-
}
|
|
1507
|
-
// `strategy: 'native'`: an answer whose last attempt failed on a refusal
|
|
1508
|
-
// or truncation stop is refused here even when its text parses — the
|
|
1509
|
-
// format did not hold for it (outputEnforcement.ts · nativeStopFailure).
|
|
1510
|
-
// FIRST, before any delivery path. It takes the same path a parse failure
|
|
1511
|
-
// takes, `.outputFallback()` included.
|
|
1512
|
-
const stopped = this.outputEnforcement?.outputFormat !== undefined ? this.outputContractUnmet() : undefined;
|
|
1513
|
-
if (stopped?.stopReason !== undefined) {
|
|
1514
|
-
return this.settleTypedFailure(out, new OutputSchemaError(stopped.error, { rawOutput: out, stage: stopped.stage }), invocation);
|
|
1515
|
-
}
|
|
1516
|
-
if (this.answerValidationConfig !== undefined) {
|
|
1517
|
-
// The validator judged the schema's JSON output. Do not run a transforming
|
|
1518
|
-
// or stateful parser again and hand back a value the validator never saw.
|
|
1519
|
-
if (this.answerValidation()?.schemaAccepted !== true) {
|
|
1520
|
-
throw new OutputSchemaError('Answer validation could not establish a JSON schema result.', {
|
|
1521
|
-
rawOutput: out,
|
|
1522
|
-
stage: 'schema-validate',
|
|
1523
|
-
});
|
|
1524
|
-
}
|
|
1525
|
-
return applyOutputSchema(out, { parse: (value) => value });
|
|
1526
|
-
}
|
|
1527
|
-
try {
|
|
1528
|
-
return applyOutputSchema(out, this.outputSchemaParser);
|
|
1529
|
-
}
|
|
1530
|
-
catch (error) {
|
|
1531
|
-
return this.settleTypedFailure(out, error, invocation);
|
|
1532
|
-
}
|
|
1506
|
+
return this.runTurn(invocation, input, options, async (turnInput) => this.typedOutcome(invocation, await this.runLeg(invocation, turnInput, options)));
|
|
1533
1507
|
});
|
|
1534
1508
|
}
|
|
1509
|
+
/** What `runTyped` makes of the answer: inside the turn, so a wrapper's context reaches it. */
|
|
1510
|
+
async typedOutcome(invocation, out) {
|
|
1511
|
+
if (typeof out !== 'string') {
|
|
1512
|
+
throw new Error('Agent.runTyped: run paused — typed mode does not support pauses. ' +
|
|
1513
|
+
'Use agent.run() + agent.parseOutput(...) after resume.');
|
|
1514
|
+
}
|
|
1515
|
+
// `strategy: 'native'`: an answer whose last attempt failed on a refusal
|
|
1516
|
+
// or truncation stop is refused here even when its text parses — the
|
|
1517
|
+
// format did not hold for it (outputEnforcement.ts · nativeStopFailure).
|
|
1518
|
+
// FIRST, before any delivery path. It takes the same path a parse failure
|
|
1519
|
+
// takes, `.outputFallback()` included.
|
|
1520
|
+
const stopped = this.outputEnforcement?.outputFormat !== undefined ? this.outputContractUnmet() : undefined;
|
|
1521
|
+
if (stopped?.stopReason !== undefined) {
|
|
1522
|
+
return this.settleTypedFailure(out, new OutputSchemaError(stopped.error, { rawOutput: out, stage: stopped.stage }), invocation);
|
|
1523
|
+
}
|
|
1524
|
+
if (this.answerValidationConfig !== undefined) {
|
|
1525
|
+
// The validator judged the schema's JSON output. Do not run a transforming
|
|
1526
|
+
// or stateful parser again and hand back a value the validator never saw.
|
|
1527
|
+
if (this.answerValidation()?.schemaAccepted !== true) {
|
|
1528
|
+
throw new OutputSchemaError('Answer validation could not establish a JSON schema result.', {
|
|
1529
|
+
rawOutput: out,
|
|
1530
|
+
stage: 'schema-validate',
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
return applyOutputSchema(out, { parse: (value) => value });
|
|
1534
|
+
}
|
|
1535
|
+
try {
|
|
1536
|
+
return applyOutputSchema(out, this.outputSchemaParser);
|
|
1537
|
+
}
|
|
1538
|
+
catch (error) {
|
|
1539
|
+
return this.settleTypedFailure(out, error, invocation);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1535
1542
|
/**
|
|
1536
1543
|
* Answer one turn.
|
|
1537
1544
|
*
|
|
@@ -1572,7 +1579,25 @@ export class Agent extends RunnerBase {
|
|
|
1572
1579
|
async run(input, options) {
|
|
1573
1580
|
return this.runExecution().withRun((invocation) => this.runOwned(invocation, input, options));
|
|
1574
1581
|
}
|
|
1575
|
-
|
|
1582
|
+
runOwned(invocation, input, options) {
|
|
1583
|
+
return this.runTurn(invocation, input, options, (turnInput) => this.runLeg(invocation, turnInput, options));
|
|
1584
|
+
}
|
|
1585
|
+
/** The funnel, for a new turn. Every top-level run enters here, inside its lease. */
|
|
1586
|
+
runTurn(invocation, input, options, leg) {
|
|
1587
|
+
return throughAroundTurn(this.aroundTurnPort, { kind: 'run', input, options }, (changes) => leg(runInputWith(input, options, changes)), (failure) => this.noteAroundTurnFailed(invocation, failure));
|
|
1588
|
+
}
|
|
1589
|
+
/** A wrapper failed after its run: the outcome stands, and the record says so. */
|
|
1590
|
+
noteAroundTurnFailed(invocation, payload) {
|
|
1591
|
+
const meta = { runtimeStageId: AROUND_TURN_STAGE_ID };
|
|
1592
|
+
this.getDispatcher().dispatch({
|
|
1593
|
+
type: 'agentfootprint.agent.around_turn_failed',
|
|
1594
|
+
payload,
|
|
1595
|
+
meta: invocation.run.origin === undefined
|
|
1596
|
+
? { ...this.minimalMeta(), ...meta }
|
|
1597
|
+
: buildEventMeta(meta, invocation.context()),
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
async runLeg(invocation, input, options) {
|
|
1576
1601
|
invocation.value.hadAdmitted = invocation.previous?.value.hadAdmitted === true;
|
|
1577
1602
|
// Normalize or refuse BEFORE anything is created. A bare string is the
|
|
1578
1603
|
// message; anything that is not a message is named and refused here
|
|
@@ -1710,45 +1735,8 @@ export class Agent extends RunnerBase {
|
|
|
1710
1735
|
catch (cause) {
|
|
1711
1736
|
// A THROWN pause is still a pause — see `endRunToolSessions`.
|
|
1712
1737
|
// Wrap recoverable errors with the last-known-good checkpoint.
|
|
1713
|
-
// Don't wrap intentional terminal signals — let them propagate as
|
|
1714
|
-
// their typed shapes so callers can `instanceof` them:
|
|
1715
|
-
// • PauseSignal — askHuman pause, not a failure
|
|
1716
|
-
// • PolicyHaltError — policy-driven termination; resuming would
|
|
1717
|
-
// immediately re-trigger the same halt (the synthetic
|
|
1718
|
-
// tool_result is already in history)
|
|
1719
|
-
// • ReliabilityFailFastError — finalizeResult constructs and
|
|
1720
|
-
// throws this AFTER the chart returns cleanly, so it never
|
|
1721
|
-
// enters this catch (kept here for documentation only)
|
|
1722
|
-
const isTerminalTypedError = cause instanceof Error &&
|
|
1723
|
-
(cause.name === 'PauseSignal' ||
|
|
1724
|
-
cause instanceof PolicyHaltError ||
|
|
1725
|
-
cause instanceof ReliabilityFailFastError ||
|
|
1726
|
-
// A provider that reports no usage will report none on resume
|
|
1727
|
-
// either — wrapping this in a checkpoint would invite the caller to
|
|
1728
|
-
// retry into the same wall.
|
|
1729
|
-
cause instanceof CompactionUnmeasurableError ||
|
|
1730
|
-
// A forced-output capability refusal is terminal even after a
|
|
1731
|
-
// correction turn: a checkpoint cannot repair this model contract.
|
|
1732
|
-
isRequestRefusal(cause) ||
|
|
1733
|
-
// 8.6.0 — a consent block is answered by a PERSON at the identity
|
|
1734
|
-
// provider, not by replaying the run. Wrapping it in a crash
|
|
1735
|
-
// checkpoint would hand the caller a retry handle for a wall, and
|
|
1736
|
-
// would bury the `authorizationUrl` one `.cause` deep where the
|
|
1737
|
-
// person who has to click it will not look.
|
|
1738
|
-
cause instanceof CredentialConsentRequiredError ||
|
|
1739
|
-
// 9.35.0 — an evidence refusal is a VERDICT, not a crash: the run
|
|
1740
|
-
// finished, the loop already spent its one revision, and resuming
|
|
1741
|
-
// would put the same model in front of the same evidence. Wrapping
|
|
1742
|
-
// it would hand the caller a retry handle for a wall and bury the
|
|
1743
|
-
// named values one `.cause` deep, where the person deciding what to
|
|
1744
|
-
// do about them will not look.
|
|
1745
|
-
cause instanceof UnsupportedValuesError ||
|
|
1746
|
-
cause instanceof AnswerValidationError ||
|
|
1747
|
-
// 9.60.0 — a dead checker is a WIRING verdict on this build, not a
|
|
1748
|
-
// recoverable run state: resuming would run the same dead wiring.
|
|
1749
|
-
cause.name === 'CheckerDeadError');
|
|
1750
1738
|
if (cause instanceof Error &&
|
|
1751
|
-
!
|
|
1739
|
+
!isTerminalRunError(cause) &&
|
|
1752
1740
|
!invocation.value.checkpointObservationFailed &&
|
|
1753
1741
|
tracker.history.length > 0) {
|
|
1754
1742
|
// Observation beats the heuristic: if a bracket was open, it says
|
|
@@ -2026,7 +2014,11 @@ export class Agent extends RunnerBase {
|
|
|
2026
2014
|
this.noteResumeTakenUp(checkpoint);
|
|
2027
2015
|
return this.runExecution().withRun((invocation) => preservePendingQuestion(invocation.previous?.value, () => invocation.value.resources?.answer.consumed === true, () => this.resumeOwned(invocation, checkpoint, input, options)));
|
|
2028
2016
|
}
|
|
2029
|
-
|
|
2017
|
+
/** The funnel, for an answered pause. Inside the lease and `preservePendingQuestion`. */
|
|
2018
|
+
resumeOwned(invocation, checkpoint, input, options) {
|
|
2019
|
+
return throughAroundTurn(this.aroundTurnPort, { kind: 'resume', checkpoint, answer: input, options }, () => this.resumeLeg(invocation, checkpoint, input, options), (failure) => this.noteAroundTurnFailed(invocation, failure));
|
|
2020
|
+
}
|
|
2021
|
+
async resumeLeg(invocation, checkpoint, input, options) {
|
|
2030
2022
|
// Taken up, before anything can refuse: from here every use of a consent
|
|
2031
2023
|
// decision passes through the one spend a door watching this pause sees
|
|
2032
2024
|
// (`consentRequest.ts` · `watchDecisionUse`) — so a resume that fails
|
|
@@ -2866,76 +2858,15 @@ export class Agent extends RunnerBase {
|
|
|
2866
2858
|
assertDeliverableRoles() {
|
|
2867
2859
|
assertInjectionDelivery(this.injections, providerTargets(this.provider, this.model, this.reliabilityConfig?.providers).map((target) => target.provider));
|
|
2868
2860
|
}
|
|
2869
|
-
/**
|
|
2870
|
-
* Refuse, at run start, a `'tool-forced'` output strategy on a provider
|
|
2871
|
-
* that does not put a forced tool choice on its wire (7.26).
|
|
2872
|
-
*
|
|
2873
|
-
* Run start rather than build time for the reason `assertDeliverableRoles`
|
|
2874
|
-
* gives one method up: a decorated provider (`withFallback`, `withRetry`,
|
|
2875
|
-
* a breaker) is only the thing it is once composed, and `withFallback`
|
|
2876
|
-
* publishes the AND of its pair.
|
|
2877
|
-
*
|
|
2878
|
-
* Refusal rather than a quiet fall back to `'instruct'`, because the two
|
|
2879
|
-
* are not interchangeable: one constrains the shape at generation, the
|
|
2880
|
-
* other asks for it in prose. An agent that silently got the second while
|
|
2881
|
-
* its config said the first would be a promise the recording could not
|
|
2882
|
-
* even show was broken.
|
|
2883
|
-
*/
|
|
2884
|
-
assertForcedToolChoiceSupported() {
|
|
2885
|
-
if (this.outputEnforcement?.schemaTool === undefined)
|
|
2886
|
-
return;
|
|
2887
|
-
const first = this.reliabilityConfig?.providers?.[0];
|
|
2888
|
-
const provider = first?.provider ?? this.provider;
|
|
2889
|
-
const model = first?.model ?? this.model;
|
|
2890
|
-
if (provider.carriesForcedToolChoice === true) {
|
|
2891
|
-
// Configuration resolves the actual model at seed, after this check.
|
|
2892
|
-
// Keep the early wire refusal, but let callLLM judge that final model.
|
|
2893
|
-
if ((first === undefined && this.runConfigFn !== undefined) ||
|
|
2894
|
-
forcedToolChoiceFor(provider, model))
|
|
2895
|
-
return;
|
|
2896
|
-
throw new UnsupportedToolChoiceError({ provider: provider.name, model });
|
|
2897
|
-
}
|
|
2898
|
-
throw new Error(`Agent: .outputSchema(parser, { strategy: 'tool-forced' }) needs a provider that puts ` +
|
|
2899
|
-
`a forced tool choice on its wire, and '${provider.name}' does not declare one. ` +
|
|
2900
|
-
`Anthropic, Bedrock, real OpenAI/Azure and the mock do; an OpenAI-COMPATIBLE endpoint ` +
|
|
2901
|
-
`behind a custom baseURL (Ollama, vLLM, …) deliberately does not, because what that ` +
|
|
2902
|
-
`server does with tool_choice is not this library's to promise. Use ` +
|
|
2903
|
-
`{ strategy: 'instruct', retries: N } on this provider — it works on every wire — or ` +
|
|
2904
|
-
`run the forced strategy on a provider that declares the capability.`);
|
|
2905
|
-
}
|
|
2906
|
-
/**
|
|
2907
|
-
* Refuse, at run start, a `'native'` output strategy on a provider that
|
|
2908
|
-
* does not put a structured-output format on its wire, or on a model that
|
|
2909
|
-
* does not take one — the `assertForcedToolChoiceSupported` twin, for the
|
|
2910
|
-
* same reasons: run start because a decorated provider is only what it is
|
|
2911
|
-
* once composed; a refusal because `'instruct'` asks in prose for what this
|
|
2912
|
-
* strategy constrains at decoding, and a quiet swap would be config that
|
|
2913
|
-
* lies.
|
|
2914
|
-
*/
|
|
2915
|
-
assertNativeOutputSchemaSupported() {
|
|
2916
|
-
if (this.outputEnforcement?.outputFormat === undefined ||
|
|
2917
|
-
this.outputEnforcement.nativeOutputAuto === true)
|
|
2918
|
-
return;
|
|
2919
|
-
const first = this.reliabilityConfig?.providers?.[0];
|
|
2920
|
-
const provider = first?.provider ?? this.provider;
|
|
2921
|
-
const model = first?.model ?? this.model;
|
|
2922
|
-
if (provider.carriesNativeOutputSchema === true) {
|
|
2923
|
-
// A configured agent resolves its model at seed; callLLM judges it there.
|
|
2924
|
-
if ((first === undefined && this.runConfigFn !== undefined) ||
|
|
2925
|
-
nativeOutputSchemaFor(provider, model))
|
|
2926
|
-
return;
|
|
2927
|
-
throw new UnsupportedNativeOutputError({ provider: provider.name, model });
|
|
2928
|
-
}
|
|
2929
|
-
throw new Error(`Agent: .outputSchema(parser, { strategy: 'native' }) needs a provider that puts a ` +
|
|
2930
|
-
`structured-output format on its wire, and '${provider.name}' does not declare one. ` +
|
|
2931
|
-
`anthropic(), browserAnthropic() and the mock do; the Bedrock and gateway adapters do ` +
|
|
2932
|
-
`not in this release. Use { strategy: 'instruct', retries: N } on this provider — it ` +
|
|
2933
|
-
`works on every wire — or run the native strategy on a provider that declares it.`);
|
|
2934
|
-
}
|
|
2935
2861
|
prepareAgentRun(invocation, runOptions, request) {
|
|
2936
2862
|
this.assertDeliverableRoles();
|
|
2937
|
-
|
|
2938
|
-
|
|
2863
|
+
assertOutputStrategySupported({
|
|
2864
|
+
enforcement: this.outputEnforcement,
|
|
2865
|
+
provider: this.provider,
|
|
2866
|
+
model: this.model,
|
|
2867
|
+
providers: this.reliabilityConfig?.providers,
|
|
2868
|
+
modelResolvedAtSeed: this.runConfigFn !== undefined,
|
|
2869
|
+
});
|
|
2939
2870
|
const correlationId = runOptions?.correlationId;
|
|
2940
2871
|
const traceId = runOptions?.traceId ?? runOptions?.env?.traceId;
|
|
2941
2872
|
const sessionId = runOptions?.sessionId;
|
|
@@ -5244,7 +5175,9 @@ export class Agent extends RunnerBase {
|
|
|
5244
5175
|
: buildAgentChart(chartDeps);
|
|
5245
5176
|
}
|
|
5246
5177
|
}
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5178
|
+
/** The class's own turn doors, captured at load: patching the prototype later still counts. */
|
|
5179
|
+
const OWN_TURN_METHODS = Object.freeze({
|
|
5180
|
+
run: Agent.prototype.run,
|
|
5181
|
+
resume: Agent.prototype.resume,
|
|
5182
|
+
});
|
|
5250
5183
|
//# sourceMappingURL=Agent.js.map
|