@andorra-labs/code 0.1.17 → 0.1.19
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/src/account-jev-savings.d.ts +4 -0
- package/dist/src/account-jev-savings.js +92 -0
- package/dist/src/acp-agent.js +2 -2
- package/dist/src/agent-execution.js +441 -53
- package/dist/src/agent-mcp.js +7 -1
- package/dist/src/agent-modifiers.js +5 -7
- package/dist/src/analytics.d.ts +19 -1
- package/dist/src/analytics.js +9 -1
- package/dist/src/andorra/entry.js +15 -6
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +8 -0
- package/dist/src/andorra/hosted.js +22 -3
- package/dist/src/andorra/streams.d.ts +49 -0
- package/dist/src/andorra/streams.js +98 -0
- package/dist/src/antigravity-acp.d.ts +28 -0
- package/dist/src/antigravity-acp.js +150 -0
- package/dist/src/antigravity-terminal.d.ts +2 -0
- package/dist/src/antigravity-terminal.js +214 -0
- package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
- package/dist/src/app-server/adaptive-routing-settings.js +69 -0
- package/dist/src/app-server/artifact.d.ts +14 -0
- package/dist/src/app-server/artifact.js +46 -0
- package/dist/src/app-server/legal-protocol.d.ts +33 -0
- package/dist/src/app-server/legal-protocol.js +16 -0
- package/dist/src/app-server/protocol.d.ts +34 -3
- package/dist/src/app-server/protocol.js +3 -1
- package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
- package/dist/src/app-server/telemetry-protocol.js +2 -0
- package/dist/src/app-server/telemetry.d.ts +38 -0
- package/dist/src/app-server/telemetry.js +163 -0
- package/dist/src/app-server/workspace.d.ts +21 -0
- package/dist/src/app-server/workspace.js +192 -10
- package/dist/src/app-server.d.ts +82 -26
- package/dist/src/app-server.js +1573 -417
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/auth/AuthManager.d.ts +11 -2
- package/dist/src/auth/AuthManager.js +56 -13
- package/dist/src/auth/index.d.ts +5 -1
- package/dist/src/auth/index.js +8 -1
- package/dist/src/auth/lifecycle.d.ts +13 -0
- package/dist/src/auth/lifecycle.js +109 -0
- package/dist/src/auth/store.d.ts +1 -0
- package/dist/src/auth/store.js +12 -0
- package/dist/src/auth/types.d.ts +12 -0
- package/dist/src/automation-runner.js +2 -0
- package/dist/src/automation-service.js +7 -2
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +16 -1
- package/dist/src/bridge/control.d.ts +3 -1
- package/dist/src/bridge/control.js +9 -3
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -0
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +3 -3
- package/dist/src/bridge/host-ops.js +14 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +70 -16
- package/dist/src/bridge/protocol.d.ts +1 -0
- package/dist/src/bridge/protocol.js +1 -0
- package/dist/src/browser-panel-tool.d.ts +12 -0
- package/dist/src/browser-panel-tool.js +30 -3
- package/dist/src/browser-runner.js +53 -62
- package/dist/src/browser-server.js +10 -4
- package/dist/src/browser-session.d.ts +14 -0
- package/dist/src/browser-session.js +57 -12
- package/dist/src/browser-view.d.ts +40 -1
- package/dist/src/browser-view.js +163 -9
- package/dist/src/browser-window-style.d.ts +27 -0
- package/dist/src/browser-window-style.js +244 -0
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +245 -62
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +44 -8
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +28 -7
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +9 -2
- package/dist/src/commands.js +69 -64
- package/dist/src/completion.js +13 -7
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +57 -17
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +38 -4
- package/dist/src/context-compaction.d.ts +10 -8
- package/dist/src/context-compaction.js +23 -24
- package/dist/src/deadline.js +1 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +16 -0
- package/dist/src/decision/DecisionManager.js +75 -2
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -3
- package/dist/src/decision/optimizationPolicy.d.ts +10 -0
- package/dist/src/decision/optimizationPolicy.js +23 -3
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +4 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +29 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +3 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +80 -1
- package/dist/src/efficiency.js +119 -4
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/extensions.d.ts +2 -0
- package/dist/src/extensions.js +30 -20
- package/dist/src/github-app/agent-writes.d.ts +1 -1
- package/dist/src/github-app/agent-writes.js +1 -1
- package/dist/src/github-app/client.d.ts +19 -0
- package/dist/src/github-app/client.js +21 -1
- package/dist/src/github-app/event-source.d.ts +0 -5
- package/dist/src/github-app/event-source.js +1 -31
- package/dist/src/github-app/metrics.d.ts +2 -5
- package/dist/src/github-app/metrics.js +2 -14
- package/dist/src/github-app/review-loop.d.ts +5 -5
- package/dist/src/github-app/review-loop.js +1 -1
- package/dist/src/github-app/review-node.d.ts +2 -2
- package/dist/src/github-app/triggers.d.ts +3 -3
- package/dist/src/github-names.d.ts +7 -0
- package/dist/src/github-names.js +7 -0
- package/dist/src/glob-search.d.ts +1 -0
- package/dist/src/glob-search.js +3 -0
- package/dist/src/google-provider.d.ts +5 -28
- package/dist/src/google-provider.js +6 -141
- package/dist/src/graph-editor-session.d.ts +1 -0
- package/dist/src/graph-editor-session.js +2 -0
- package/dist/src/graph-health.js +3 -1
- package/dist/src/graph-preview.d.ts +2 -0
- package/dist/src/graph-preview.js +1 -0
- package/dist/src/graph-runner.js +20 -14
- package/dist/src/graph-selection.d.ts +3 -1
- package/dist/src/graph-selection.js +2 -2
- package/dist/src/graph-server.d.ts +8 -1
- package/dist/src/graph-server.js +49 -12
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +49 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +23 -1
- package/dist/src/graphs.js +58 -7
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +39 -25
- package/dist/src/jev-savings.d.ts +4 -0
- package/dist/src/jev-savings.js +13 -0
- package/dist/src/legal/client.d.ts +25 -0
- package/dist/src/legal/client.js +47 -0
- package/dist/src/legal/command.d.ts +13 -0
- package/dist/src/legal/command.js +98 -0
- package/dist/src/legal/documents.d.ts +2 -0
- package/dist/src/legal/documents.js +14 -0
- package/dist/src/legal/gate.d.ts +13 -0
- package/dist/src/legal/gate.js +96 -0
- package/dist/src/legal/manifest.d.ts +21 -0
- package/dist/src/legal/manifest.js +23 -0
- package/dist/src/legal/receipt.d.ts +13 -0
- package/dist/src/legal/receipt.js +137 -0
- package/dist/src/legal/release.d.ts +27 -0
- package/dist/src/legal/release.js +28 -0
- package/dist/src/managed-sign-in.d.ts +0 -1
- package/dist/src/managed-sign-in.js +0 -13
- package/dist/src/membership.d.ts +27 -1
- package/dist/src/membership.js +139 -7
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.js +3 -7
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-pool.d.ts +99 -0
- package/dist/src/model-pool.js +136 -0
- package/dist/src/model-relay/local.js +5 -0
- package/dist/src/model-relay/remote.d.ts +2 -0
- package/dist/src/model-relay/remote.js +4 -0
- package/dist/src/model-tiers.d.ts +16 -1
- package/dist/src/model-tiers.js +31 -7
- package/dist/src/opencode-cli-provider.js +59 -56
- package/dist/src/opencode-provider.js +16 -13
- package/dist/src/permissions.d.ts +5 -0
- package/dist/src/permissions.js +7 -0
- package/dist/src/plan-pass.js +2 -1
- package/dist/src/pool-scores.d.ts +45 -0
- package/dist/src/pool-scores.js +40 -0
- package/dist/src/provider-connection.js +3 -17
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +116 -12
- package/dist/src/provider-request-error.d.ts +8 -0
- package/dist/src/provider-request-error.js +12 -0
- package/dist/src/provider-settings.d.ts +1 -1
- package/dist/src/provider-settings.js +36 -18
- package/dist/src/provider-turn-deadline.d.ts +39 -0
- package/dist/src/provider-turn-deadline.js +139 -0
- package/dist/src/providers.d.ts +8 -9
- package/dist/src/providers.js +211 -150
- package/dist/src/pull-request-merge.d.ts +1 -8
- package/dist/src/pull-request-merge.js +0 -4
- package/dist/src/pull-requests.d.ts +83 -57
- package/dist/src/pull-requests.js +266 -225
- package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
- package/dist/src/qa/runtime/ProcessManager.js +9 -3
- package/dist/src/react-runtime.js +245 -71
- package/dist/src/reasoning-probe-cloud.d.ts +10 -0
- package/dist/src/reasoning-probe-cloud.js +209 -0
- package/dist/src/remote/engine-pool.d.ts +3 -0
- package/dist/src/remote/engine-pool.js +88 -21
- package/dist/src/remote/recovery.d.ts +6 -0
- package/dist/src/remote/recovery.js +37 -0
- package/dist/src/run-records.d.ts +13 -3
- package/dist/src/run-records.js +59 -34
- package/dist/src/runtime.d.ts +47 -2
- package/dist/src/runtime.js +33 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +32 -0
- package/dist/src/sessions.js +65 -3
- package/dist/src/shell.js +6 -0
- package/dist/src/side-panel.js +36 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +4 -10
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/subagent-run.js +50 -50
- package/dist/src/subscription-usage.d.ts +50 -0
- package/dist/src/subscription-usage.js +92 -0
- package/dist/src/task-checkout.d.ts +157 -0
- package/dist/src/task-checkout.js +628 -0
- package/dist/src/telemetry/access.d.ts +18 -0
- package/dist/src/telemetry/access.js +43 -0
- package/dist/src/telemetry/aggregate.d.ts +18 -2
- package/dist/src/telemetry/aggregate.js +22 -9
- package/dist/src/telemetry/capture-core.d.ts +33 -14
- package/dist/src/telemetry/capture-core.js +124 -25
- package/dist/src/telemetry/capture.d.ts +3 -2
- package/dist/src/telemetry/capture.js +21 -1
- package/dist/src/telemetry/decision-capture.js +4 -0
- package/dist/src/telemetry/emitter.d.ts +6 -7
- package/dist/src/telemetry/emitter.js +124 -29
- package/dist/src/telemetry/gate.d.ts +41 -2
- package/dist/src/telemetry/gate.js +89 -4
- package/dist/src/telemetry/home.d.ts +1 -0
- package/dist/src/telemetry/home.js +20 -0
- package/dist/src/telemetry/identity.d.ts +6 -3
- package/dist/src/telemetry/identity.js +19 -6
- package/dist/src/telemetry/lifecycle.d.ts +8 -0
- package/dist/src/telemetry/lifecycle.js +76 -0
- package/dist/src/telemetry/outbox.d.ts +13 -8
- package/dist/src/telemetry/outbox.js +68 -12
- package/dist/src/telemetry/permission-command.d.ts +38 -0
- package/dist/src/telemetry/permission-command.js +208 -0
- package/dist/src/telemetry/permission.d.ts +168 -0
- package/dist/src/telemetry/permission.js +662 -0
- package/dist/src/telemetry/record-installation.d.ts +1 -0
- package/dist/src/telemetry/record-installation.js +9 -0
- package/dist/src/telemetry/region-data.d.ts +12 -0
- package/dist/src/telemetry/region-data.js +1314 -0
- package/dist/src/telemetry/region.d.ts +34 -0
- package/dist/src/telemetry/region.js +87 -0
- package/dist/src/telemetry/run-privacy.d.ts +11 -0
- package/dist/src/telemetry/run-privacy.js +165 -0
- package/dist/src/telemetry/schema.d.ts +27 -6
- package/dist/src/telemetry/schema.js +109 -14
- package/dist/src/telemetry/state.d.ts +11 -7
- package/dist/src/telemetry/state.js +39 -6
- package/dist/src/telemetry/surface.d.ts +20 -3
- package/dist/src/telemetry/surface.js +71 -15
- package/dist/src/telemetry/uploader.d.ts +6 -11
- package/dist/src/telemetry/uploader.js +72 -46
- package/dist/src/telemetry/uploads.d.ts +5 -1
- package/dist/src/telemetry/uploads.js +25 -6
- package/dist/src/telemetry/version.d.ts +5 -0
- package/dist/src/telemetry/version.js +34 -0
- package/dist/src/telemetry/workspace.d.ts +4 -1
- package/dist/src/telemetry/workspace.js +18 -3
- package/dist/src/terminal-ui.d.ts +3 -0
- package/dist/src/terminal-ui.js +48 -6
- package/dist/src/test-edit-guard.d.ts +30 -0
- package/dist/src/test-edit-guard.js +167 -2
- package/dist/src/thinking-level-detect.d.ts +13 -0
- package/dist/src/thinking-level-detect.js +52 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +131 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/todos.d.ts +2 -1
- package/dist/src/todos.js +24 -4
- package/dist/src/tool-argument-coercion.d.ts +7 -0
- package/dist/src/tool-argument-coercion.js +49 -0
- package/dist/src/tool-catalog.d.ts +2 -2
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +67 -22
- package/dist/src/transcript.js +3 -2
- package/dist/src/types.d.ts +48 -1
- package/dist/src/update.js +4 -0
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +85 -13
- package/dist/telemetry-consent-v1 +1 -0
- package/package.json +97 -96
|
@@ -2,16 +2,22 @@ import { goalRoute, routedOutcomes, runEndingOutcomes as goalRunEndingOutcomes }
|
|
|
2
2
|
import { DecisionPolicy } from './decision/DecisionPolicy.js';
|
|
3
3
|
import { answerOnlyTask, hasAdaptiveAlternative } from './decision/optimizationPolicy.js';
|
|
4
4
|
import { resolveEfficiency } from './efficiency.js';
|
|
5
|
+
import { ANDORRA_STREAMS_TOOL, currentAndorraStreams, holdAndorraStream } from './andorra/streams.js';
|
|
5
6
|
import { collectWorkspaceFacts } from './workspace-facts.js';
|
|
6
7
|
import { conversationContains, omittedContextNote, selectContext } from './context-selection.js';
|
|
7
8
|
import { MAPPED_INPUTS_HEADING } from './context-compaction.js';
|
|
8
9
|
import { orderSkillCatalog, selectToolCatalog } from './tool-catalog.js';
|
|
9
10
|
import { decideModelTier } from './model-tiers.js';
|
|
11
|
+
import { decidePoolModel, isPoolClass } from './model-pool.js';
|
|
12
|
+
import { decideEffort, EFFORT_ESCALATION_REASONS } from './effort-routing.js';
|
|
13
|
+
import { nearestEnabled } from './thinking-levels.js';
|
|
14
|
+
import { REASONING_EFFORTS, supportsReasoningEffort } from './providers.js';
|
|
15
|
+
import { POOL_CLASSES } from './efficiency.js';
|
|
10
16
|
import { structuredText } from './code-intelligence/CodeIntelligenceManager.js';
|
|
11
17
|
import { buildMemoryBlock } from './memory/MemoryRetriever.js';
|
|
12
18
|
import { discoverRuntimeSkills, matchRuntimeSkill, runtimeSkillTools } from './skills/runtime-skills.js';
|
|
13
19
|
import { promptSkillReferences } from './skills/prompt-skills.js';
|
|
14
|
-
import { BUG_REPORT_SKILL, bugReportTool } from './bug-report.js';
|
|
20
|
+
import { BUG_REPORT_SKILL, bugReportSessionsTool, bugReportTool } from './bug-report.js';
|
|
15
21
|
import { toolFamilies, routeToolFamilies, decisionExecutionGuidance } from './decision/toolFamilies.js';
|
|
16
22
|
import { allowsGraphRouting, route as codeGraphRoute } from './code-intelligence/ContextRouter.js';
|
|
17
23
|
import { randomUUID } from 'node:crypto';
|
|
@@ -21,13 +27,13 @@ import { promisify } from 'node:util';
|
|
|
21
27
|
import { mkdtemp, realpath } from 'node:fs/promises';
|
|
22
28
|
import { tmpdir } from 'node:os';
|
|
23
29
|
import { join, relative } from 'node:path';
|
|
24
|
-
import { ClarificationRequiredError, DEFAULT_GRAPH, LIMIT_KEYS, isUnlimitedAlias, resolveLimits, turnModelTask } from './runtime.js';
|
|
25
|
-
import { createRunTelemetry, mergeRunTelemetry, recordAttempt, recordDecisionEvent, recordEfficiencyEvent } from './telemetry/capture.js';
|
|
30
|
+
import { ClarificationRequiredError, DEFAULT_GRAPH, LIMIT_KEYS, isUnlimitedAlias, resolveLimits, turnModelCompletion, turnModelTask } from './runtime.js';
|
|
31
|
+
import { resolveTelemetryCapture, bindRunTelemetry, hasRunTelemetry, createRunTelemetry, mergeRunTelemetry, recordAttempt, recordDecisionEvent, recordEfficiencyEvent } from './telemetry/capture.js';
|
|
26
32
|
import { bindUserWaits, createRuntimeBudget } from './deadline.js';
|
|
27
33
|
import { createAgentEngine } from './hardened-runtime.js';
|
|
28
34
|
import { completionTool } from './completion.js';
|
|
29
35
|
import { applyToolProfile } from './tool-profile.js';
|
|
30
|
-
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, REVIEWER_GRAPH_ID, capabilitySubset, isolatedGraph, reviewerOutputProblem, delegatesWriting, effectiveCapabilities, intakeCapabilities, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
36
|
+
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, REVIEWER_GRAPH_ID, capabilitySubset, isolatedGraph, reviewerOutputProblem, delegatesWriting, effectiveCapabilities, freeformRole, intakeCapabilities, isCommandToolName, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
31
37
|
import { DELEGATION_DIFF_LIMIT, LandingRestoreError, addChangeWorktree, assertDelegationGit, applyLanding, collectChange, prepareLanding, removeChangeWorktree, repositoryRoot, snapshotWorkspace } from './delegation-changes.js';
|
|
32
38
|
import { stopQaProcessesUnder } from './qa/runtime/ProcessManager.js';
|
|
33
39
|
import { qaGuidance } from './qa/guidance.js';
|
|
@@ -37,7 +43,7 @@ import { ArtifactStore } from './artifacts.js';
|
|
|
37
43
|
import { approveOperation, capabilityTools, gitReadTool } from './capabilities.js';
|
|
38
44
|
import { removeUntrackedFileTool } from './untracked-file-removal.js';
|
|
39
45
|
import { permissionMode, serializeApprovals, assertPlanMutationAllowed } from './permissions.js';
|
|
40
|
-
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList } from './tool-names.js';
|
|
46
|
+
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList, toolNameMatches } from './tool-names.js';
|
|
41
47
|
const exec = promisify(execFile);
|
|
42
48
|
const LANDING_ATTEMPTS = 3;
|
|
43
49
|
const RESTORE_TOOL_SCHEMA_CHARS = 420;
|
|
@@ -89,6 +95,26 @@ function references(value, result = new Set()) {
|
|
|
89
95
|
}
|
|
90
96
|
return result;
|
|
91
97
|
}
|
|
98
|
+
// Artifact references an agent names explicitly: artifact:// references appearing anywhere in text
|
|
99
|
+
// (a task, a summary, a field value) plus {type, ref} object fields wherever they sit. Naming a
|
|
100
|
+
// reference is a request for read access, never a grant in itself. Only a well-formed reference
|
|
101
|
+
// counts as a request: a string that merely begins like one ('artifact://run/id/suffix') never
|
|
102
|
+
// matches a real reference, so a malformed quote cannot grant anything by prefix.
|
|
103
|
+
const ARTIFACT_REF_PATTERN = /artifact:\/\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+(?![/\w-])/g;
|
|
104
|
+
const ARTIFACT_REF_EXACT = /^artifact:\/\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+$/;
|
|
105
|
+
function quotedArtifactRefs(value, result = new Set()) {
|
|
106
|
+
if (typeof value === 'string') {
|
|
107
|
+
for (const match of value.matchAll(ARTIFACT_REF_PATTERN))
|
|
108
|
+
result.add(match[0]);
|
|
109
|
+
}
|
|
110
|
+
else if (value && typeof value === 'object') {
|
|
111
|
+
if ('ref' in value && typeof value.ref === 'string' && ARTIFACT_REF_EXACT.test(value.ref))
|
|
112
|
+
result.add(value.ref);
|
|
113
|
+
for (const child of Object.values(value))
|
|
114
|
+
quotedArtifactRefs(child, result);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
92
118
|
async function resolveBeforeAbort(resolve, signal) {
|
|
93
119
|
signal.throwIfAborted();
|
|
94
120
|
let abort;
|
|
@@ -122,6 +148,7 @@ async function retryReadOnly(context, operation) {
|
|
|
122
148
|
}
|
|
123
149
|
}
|
|
124
150
|
export async function executeAgentNode(node, options) {
|
|
151
|
+
options = { ...options, telemetry: resolveTelemetryCapture(options.telemetry) };
|
|
125
152
|
if (node.maxSubagents !== undefined && (!Number.isSafeInteger(node.maxSubagents) || node.maxSubagents < 0 || node.maxSubagents > 100))
|
|
126
153
|
throw new Error('maxSubagents must be an integer from 0 to 100');
|
|
127
154
|
const limits = mergeLimits(node, options.limits);
|
|
@@ -301,20 +328,25 @@ export async function executeAgentNode(node, options) {
|
|
|
301
328
|
const intake = await runIntake();
|
|
302
329
|
if (intake)
|
|
303
330
|
return intake;
|
|
304
|
-
|
|
331
|
+
// Subagent nodes whose model was inherited or routed, not named by the graph. The runtime fills in their provider
|
|
332
|
+
// and model, which must not read as a pin when such a subagent spawns its own.
|
|
333
|
+
const inheritingChildren = new WeakSet();
|
|
334
|
+
const run = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, commandScope = depth > 0, sharedRefs) => {
|
|
305
335
|
const nodeLimits = mergeLimits(configured, depth ? { ...limits, wallTimeMs: configured.limits?.wallTimeMs } : limits);
|
|
306
336
|
const nodeBudget = createRuntimeBudget(context.signal, nodeLimits.wallTimeMs, context.runControl);
|
|
307
337
|
const observationController = options.decisionManager?.enabled ? new AbortController() : undefined;
|
|
308
338
|
const nodeSignal = observationController ? AbortSignal.any([nodeBudget.signal, observationController.signal]) : nodeBudget.signal;
|
|
339
|
+
// This agent's place among the account's Andorra streams, held for the whole run and not only while a request is out.
|
|
340
|
+
const streamHold = holdAndorraStream();
|
|
309
341
|
try {
|
|
310
342
|
let result;
|
|
311
343
|
try {
|
|
312
344
|
nodeSignal.throwIfAborted();
|
|
313
|
-
result = await runWithinDeadline(configured, bindUserWaits({ ...context, signal: nodeSignal }, nodeBudget, nodeSignal), depth, inputs, task, subagentId, parentFallback, () => {
|
|
345
|
+
result = await streamHold.run(() => runWithinDeadline(configured, bindUserWaits({ ...context, signal: nodeSignal }, nodeBudget, nodeSignal), depth, inputs, task, subagentId, parentFallback, () => {
|
|
314
346
|
const resumeInvocation = suspendInvocationMemoryBudget();
|
|
315
347
|
const resume = nodeBudget.suspend();
|
|
316
348
|
return () => { resume(); resumeInvocation(); };
|
|
317
|
-
}, commandScope);
|
|
349
|
+
}, commandScope, sharedRefs, streamHold));
|
|
318
350
|
}
|
|
319
351
|
catch (error) {
|
|
320
352
|
if (!nodeSignal.aborted)
|
|
@@ -331,11 +363,12 @@ export async function executeAgentNode(node, options) {
|
|
|
331
363
|
return result;
|
|
332
364
|
}
|
|
333
365
|
finally {
|
|
366
|
+
streamHold.release();
|
|
334
367
|
observationController?.abort();
|
|
335
368
|
nodeBudget.dispose();
|
|
336
369
|
}
|
|
337
370
|
};
|
|
338
|
-
const runWithinDeadline = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, suspendMemoryBudget, commandScope = depth > 0) => {
|
|
371
|
+
const runWithinDeadline = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, suspendMemoryBudget, commandScope = depth > 0, sharedRefs, streamHold) => {
|
|
339
372
|
const delegatedChild = commandScope === 'delegated-worktree';
|
|
340
373
|
if (orchestrator && !delegatedChild)
|
|
341
374
|
configured = { ...configured, capabilities: intakeCapabilities(configured) };
|
|
@@ -364,15 +397,47 @@ export async function executeAgentNode(node, options) {
|
|
|
364
397
|
throw new Error('Mapped inputs exceed context limit; pass artifact references instead');
|
|
365
398
|
const configuredProvider = configured.provider ?? options.provider;
|
|
366
399
|
const configuredModel = configured.model ?? (configured.provider === undefined ? options.model : undefined);
|
|
367
|
-
const resolve = async (provider, model) => retryReadOnly(context, signal => options.resolveModel
|
|
368
|
-
? options.resolveModel(provider, model, signal)
|
|
400
|
+
const resolve = async (provider, model, effort) => retryReadOnly(context, signal => options.resolveModel
|
|
401
|
+
? options.resolveModel(provider, model, signal, effort)
|
|
369
402
|
: provider === options.provider ? { model: options.model, adapter: options.adapter, contextWindow: options.contextWindow } : options.resolveProvider?.(provider));
|
|
370
403
|
let provider = configuredProvider, resolved = await resolve(provider, configuredModel);
|
|
371
404
|
if (!resolved)
|
|
372
405
|
throw new Error(`Unknown provider ${provider}. Run andorra and open /providers first.`);
|
|
406
|
+
// The model a live change moved the running attempt to; the runtime applies it without telling this function.
|
|
407
|
+
let liveResolved;
|
|
408
|
+
streamHold?.watch(() => (liveResolved ?? resolved)?.providerType === 'andorra');
|
|
373
409
|
// The resolved model is the provider's own spelling of the configured one when they differ only in case.
|
|
374
410
|
const spelled = (wanted, got) => wanted !== undefined && wanted.toLowerCase() === got.toLowerCase() ? got : wanted ?? got;
|
|
375
411
|
let model = spelled(configured.model, resolved.model);
|
|
412
|
+
// The thinking level in force for this node's requests; a subagent that inherits the model runs at it too.
|
|
413
|
+
let activeEffort;
|
|
414
|
+
// Pool routing names a thinking level with the pair it picks; a node's own level still wins over it.
|
|
415
|
+
let poolEffort;
|
|
416
|
+
// With `subagents` on, a subagent that would inherit its parent's model gets its own routing decision, under either
|
|
417
|
+
// strategy and whether or not the run's own model was chosen: a chosen model pins only the agent it was chosen for.
|
|
418
|
+
const subagentRouting = (() => {
|
|
419
|
+
const routing = resolveEfficiency(options.efficiency).adaptiveRouting;
|
|
420
|
+
return routing.enabled && routing.subagents === true ? routing : undefined;
|
|
421
|
+
})();
|
|
422
|
+
const poolSubagents = subagentRouting?.strategy === 'pool' ? subagentRouting : undefined;
|
|
423
|
+
// A usage reading that fails is an unknown reading: the pair is neither preferred nor held back.
|
|
424
|
+
const readQuota = async (signal) => {
|
|
425
|
+
try {
|
|
426
|
+
return await options.quotaReadings?.(signal);
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
signal.throwIfAborted();
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
// The thinking levels a model takes, for routing that chooses a level from the model's scores.
|
|
434
|
+
const poolLevels = (id, name) => options.thinkingLevels?.(id, name, false);
|
|
435
|
+
const asLevel = (value) => value !== undefined && REASONING_EFFORTS.includes(value) ? value : undefined;
|
|
436
|
+
const levelsFor = (id, name, type, forAuto) => options.thinkingLevels?.(id, name, forAuto) ?? (type === undefined || !supportsReasoningEffort(type) ? [] : forAuto ? ['low', 'medium', 'high'] : [...REASONING_EFFORTS]);
|
|
437
|
+
// The run's own model: the one it started on, or the one a live whole-run change moved it to.
|
|
438
|
+
let sessionModel = { provider: options.provider, model: options.model };
|
|
439
|
+
const wantedEffort = () => configured.reasoningEffort ?? poolEffort
|
|
440
|
+
?? (options.sessionEffortAuto && depth === 0 && provider === sessionModel.provider && model === sessionModel.model ? 'auto' : undefined);
|
|
376
441
|
let fallbackAttempt = parentFallback;
|
|
377
442
|
const orchestratorCompletionGuard = () => {
|
|
378
443
|
if (!clarified)
|
|
@@ -455,11 +520,28 @@ export async function executeAgentNode(node, options) {
|
|
|
455
520
|
throw new Error('Clarification response exceeds 16000 characters; ask for a shorter decision.');
|
|
456
521
|
clarified = true;
|
|
457
522
|
confirmedClarifications.push({ question: args.question, answer, proposedDesign: args.proposedDesign });
|
|
458
|
-
await emit('agent.clarification.answered', { answered: true });
|
|
523
|
+
await emit('agent.clarification.answered', { answered: true, question, answer });
|
|
459
524
|
return JSON.stringify({ answer, proposedDesign: args.proposedDesign });
|
|
460
525
|
} });
|
|
461
526
|
if (orchestrator && depth === 0 && effectiveCapabilities(configured).filesystem !== 'none')
|
|
462
527
|
tools.push(removeUntrackedFileTool());
|
|
528
|
+
if (depth === 0 && !isolated && options.context.chatHandoffs && options.context.askUser && !headlessRun)
|
|
529
|
+
tools.push({
|
|
530
|
+
name: 'propose_chat', executionMode: 'sequential',
|
|
531
|
+
description: 'Offer a fresh child chat for a distinct next stage of work. Ask one concise question, supply a self-contained handoff prompt (the child gets no transcript), and suggest a model and reasoning effort. Only the user can start it. Do not propose again after Skip.',
|
|
532
|
+
parameters: { type: 'object', additionalProperties: false, required: ['question', 'prompt', 'model', 'effort'], properties: {
|
|
533
|
+
question: { type: 'string', minLength: 1, maxLength: 240 }, prompt: { type: 'string', minLength: 1, maxLength: 16000 },
|
|
534
|
+
model: { type: 'string', minLength: 1, maxLength: 200 }, effort: { type: 'string', enum: ['default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] },
|
|
535
|
+
} },
|
|
536
|
+
execute: async (args, ctx) => {
|
|
537
|
+
const { question, prompt, model, effort } = args;
|
|
538
|
+
if (typeof question !== 'string' || !question.trim() || question.length > 240 || typeof prompt !== 'string' || !prompt.trim() || prompt.length > 16000 || typeof model !== 'string' || !model.trim() || model.length > 200 || typeof effort !== 'string' || !['default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'].includes(effort))
|
|
539
|
+
throw new Error('Provide one short question, a self-contained prompt, a suggested model and a valid effort.');
|
|
540
|
+
ctx.signal.throwIfAborted();
|
|
541
|
+
const decision = await ctx.askUser(question.trim(), ctx.userSignal ?? ctx.signal, ['Skip', 'Start'], { prompt: prompt.trim(), model: model.trim(), ...(effort === 'default' ? {} : { effort }) });
|
|
542
|
+
return JSON.stringify({ decision: decision === 'Start' ? 'user-approved' : 'skipped' });
|
|
543
|
+
},
|
|
544
|
+
});
|
|
463
545
|
if (!orchestrator && !isolated && depth === 0 && options.context.approvalMode !== 'headless' && options.context.askUser)
|
|
464
546
|
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user a question only they can answer and wait for the answer. Use it whenever a choice is theirs to make: a skill or instruction that says to ask, a preference, a missing requirement. A question written in your reply does not pause the run and may go unseen, so never ask that way. Ask one short question per call in plain language; when the options are known give 2-4 short choices, the recommended one first and labelled (Recommended). Do not ask what your tools can find out or what you can reasonably decide yourself. Before asking where something is or what a name refers to, finish a search for it by file name and by content; a search that was cut short or timed out does not count.',
|
|
465
547
|
parameters: { type: 'object', properties: { question: { type: 'string', minLength: 1, maxLength: 500, description: 'One plain-language question.' }, choices: { type: 'array', items: { type: 'string', minLength: 1, maxLength: 200 }, minItems: 2, maxItems: 8, description: 'Short answers the user can pick from; they can always type their own.' } }, required: ['question'], additionalProperties: false },
|
|
@@ -477,7 +559,7 @@ export async function executeAgentNode(node, options) {
|
|
|
477
559
|
const answer = await ctx.askUser(question, ctx.userSignal ?? ctx.signal, choices);
|
|
478
560
|
ctx.signal.throwIfAborted();
|
|
479
561
|
const answered = typeof answer === 'string' && !!answer.trim() && answer.trim().toLowerCase() !== '/cancel';
|
|
480
|
-
await emit('agent.clarification.answered', { answered });
|
|
562
|
+
await emit('agent.clarification.answered', { answered, ...(answered && answer.length <= 16000 ? { question, answer } : {}) });
|
|
481
563
|
if (typeof answer !== 'string' || answer.trim().toLowerCase() === '/cancel')
|
|
482
564
|
throw new ClarificationRequiredError('Needs clarification: the user cancelled the task at a question. Nothing further was done.');
|
|
483
565
|
if (!answered)
|
|
@@ -523,6 +605,14 @@ export async function executeAgentNode(node, options) {
|
|
|
523
605
|
references(predecessorContext, scopedRefs);
|
|
524
606
|
if (depth === 0 && options.previousIterationCompletion)
|
|
525
607
|
references(options.previousIterationCompletion, scopedRefs);
|
|
608
|
+
// A subagent starts with only the artifact references its start explicitly granted, not with whatever
|
|
609
|
+
// its parent can read: the parent's grant is the filter, so sharing cannot amplify privileges. An
|
|
610
|
+
// undefined sharedRefs means a top-level invocation, which keeps its own mapped-input references.
|
|
611
|
+
if (sharedRefs) {
|
|
612
|
+
scopedRefs.clear();
|
|
613
|
+
for (const ref of sharedRefs)
|
|
614
|
+
scopedRefs.add(ref);
|
|
615
|
+
}
|
|
526
616
|
const artifactTools = store.tools(scopedRefs);
|
|
527
617
|
const write = artifactTools.find(tool => tool.name === 'write_artifact');
|
|
528
618
|
if (configured.tools === undefined || configured.tools.includes('read_artifact'))
|
|
@@ -531,12 +621,48 @@ export async function executeAgentNode(node, options) {
|
|
|
531
621
|
tools.push({ ...write, execute: async (args, ctx) => { const result = await write.execute(args, ctx); scopedRefs.add(JSON.parse(result).ref); return result; } });
|
|
532
622
|
const canDelegateSkillReader = tools.some(tool => tool.name === 'read_skill_resource');
|
|
533
623
|
if (policy.enabled && maxTotal > 0 && depth < (policy.maxDepth ?? 1) && !(delegationActive && depth > 0)) {
|
|
534
|
-
|
|
535
|
-
|
|
624
|
+
const freeformMode = policy.freeform ?? 'off';
|
|
625
|
+
// Offered where a subagent, or this agent itself, can be on an Andorra model: the only models with a stream cap.
|
|
626
|
+
// Routing and a live model change can move either onto any configured provider after this list is built.
|
|
627
|
+
const providerTypeOf = (id) => {
|
|
628
|
+
if (id === undefined || id === provider)
|
|
629
|
+
return resolved?.providerType;
|
|
630
|
+
// A graph run resolves only the providers its nodes name; the run's provider list has every configured one.
|
|
631
|
+
const configuredType = options.configuredModels?.find(entry => entry.id === id)?.type;
|
|
632
|
+
if (configuredType !== undefined)
|
|
633
|
+
return configuredType;
|
|
634
|
+
try {
|
|
635
|
+
return options.resolveProvider?.(id)?.providerType;
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
const andorraStreams = [provider, policy.provider, ...(policy.roles ?? []).map(role => role.provider),
|
|
642
|
+
...(options.configuredModels ?? []).map(entry => entry.id)].some(id => providerTypeOf(id) === 'andorra');
|
|
643
|
+
if (andorraStreams)
|
|
644
|
+
tools.push({ name: ANDORRA_STREAMS_TOOL,
|
|
645
|
+
description: 'Report how many Andorra streams the account has in use and how many are free. Andorra models allow a limited number of agents at once, and a subagent started past the limit fails. Call this before starting subagents when you or they run on an Andorra model, and start no more than it reports available. An agent holds its stream for its whole run, also while it runs a tool or waits, so every running agent is counted, you included.',
|
|
646
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
647
|
+
execute: async (args, ctx) => {
|
|
648
|
+
ctx.signal.throwIfAborted();
|
|
649
|
+
if (Object.keys(args).length)
|
|
650
|
+
throw new Error(`${ANDORRA_STREAMS_TOOL} takes no arguments`);
|
|
651
|
+
return JSON.stringify(await currentAndorraStreams(options.andorraHostedCheck, ctx.signal));
|
|
652
|
+
} });
|
|
653
|
+
tools.push({ name: 'spawn_subagent', description: (freeformMode === 'off' ? 'Run one configured role on a bounded task.' : 'Run a subagent on a bounded task. Omit role to run a general subagent that follows the task you write' + ((policy.roles ?? []).length ? ', or name a configured role' : '') + (freeformMode === 'write' ? '. A general subagent may write within the configured permissions.' : '. A general subagent is read-only.')) + ' Its typed result returns as an observation. Batch spawn calls can run concurrently within configured limits.' + (policy.workspace === 'worktree' ? ' A subagent that runs commands (one whose tools include a command tool such as PowerShell, Bash or NativeExec) works in its own Git worktree started from the working folder; to let a subagent run commands it would not otherwise get, for example a verifier that must run the build, name those tools in tools.' : '') + (andorraStreams ? ` On an Andorra model, call ${ANDORRA_STREAMS_TOOL} first and start no more subagents at once than it reports available.` : '') + ' Role contracts: ' + JSON.stringify((policy.roles ?? []).map(role => ({ id: role.id, name: role.name, instruction: role.instruction, inputSchema: role.inputSchema, outputSchema: role.outputSchema }))),
|
|
654
|
+
parameters: { type: 'object', properties: { ...(freeformMode !== 'off' && !(policy.roles ?? []).length ? {} : { role: { type: 'string', enum: (policy.roles ?? []).map(role => role.id), ...(freeformMode === 'off' ? {} : { description: 'Optional. Omit it to run a general subagent.' }) } }), task: { type: 'string', description: 'The bounded task. Quoting an artifact:// reference in it or in input gives the subagent read access to that artifact only if you can already read it yourself; everything else stays outside its context.' }, input: { type: 'object' }, tools: { type: 'array', items: { type: 'string', minLength: 1 }, maxItems: 32, description: 'Optional. Tools from your own tool list to give this subagent in addition to its usual ones, for example PowerShell or NativeExec so it can run a build or tests.' + (policy.workspace === 'worktree' ? ' A subagent given a command tool runs it in its own Git worktree.' : ' Command tools cannot be given here: this node\'s subagents share its working folder.') }, ...(poolSubagents ? { class: { type: 'string', enum: [...POOL_CLASSES], description: 'Optional. How demanding the task is; it selects the model the subagent runs on.' } } : {}) }, required: freeformMode === 'off' ? ['role', 'task'] : ['task'], additionalProperties: false },
|
|
536
655
|
execute: async (args, callContext) => {
|
|
537
|
-
if (
|
|
538
|
-
throw new Error('
|
|
539
|
-
|
|
656
|
+
if (poolSubagents && args.class !== undefined && !isPoolClass(args.class))
|
|
657
|
+
throw new Error('class must be one of routine, quick, standard, deep or escalated');
|
|
658
|
+
if (args.tools !== undefined && (!Array.isArray(args.tools) || args.tools.length > 32 || args.tools.some(name => typeof name !== 'string' || !name.trim())))
|
|
659
|
+
throw new Error('tools must be an array of at most 32 tool names from your own tool list');
|
|
660
|
+
if (Object.keys(args).some(key => !['role', 'task', 'input', 'tools', ...(poolSubagents ? ['class'] : [])].includes(key)) || (typeof args.role !== 'string' && !(args.role === undefined && freeformMode !== 'off')) || typeof args.task !== 'string' || !args.task.trim() || args.task.length > 16000)
|
|
661
|
+
throw new Error((freeformMode === 'off' ? 'Choose a configured role' : 'Name a configured role or omit role') + ' and provide a task of 1–16000 characters');
|
|
662
|
+
// No role named: a general subagent bounded by the freeform setting. In write mode it takes the node's own
|
|
663
|
+
// permissions where this Orchestrator delegates, and its parent's everywhere else.
|
|
664
|
+
const general = args.role === undefined ? freeformRole(policy, freeformMode === 'write' && delegationActive && depth === 0 ? effectiveCapabilities(node) : effectiveCapabilities(configured)) : undefined;
|
|
665
|
+
const role = general ?? policy.roles?.find(item => item.id === args.role);
|
|
540
666
|
if (!role)
|
|
541
667
|
throw new Error('Subagent role is not allowed');
|
|
542
668
|
if (total >= maxTotal)
|
|
@@ -546,13 +672,30 @@ export async function executeAgentNode(node, options) {
|
|
|
546
672
|
throw new Error('Subagent input must be an object');
|
|
547
673
|
if (role.inputSchema)
|
|
548
674
|
validateValue(role.inputSchema, childInputs, `Subagent ${role.name} input`);
|
|
549
|
-
|
|
675
|
+
// Explicit artifact sharing: the subagent gains read access to an artifact it names in its task
|
|
676
|
+
// or input only when this agent can already read it itself. Everything else stays outside its
|
|
677
|
+
// context: what it merely mentions without access, what this agent cannot read, and unquoted
|
|
678
|
+
// artifacts, whatever this agent can do with them.
|
|
679
|
+
const requestedRefs = quotedArtifactRefs(args.task);
|
|
680
|
+
quotedArtifactRefs(childInputs, requestedRefs);
|
|
681
|
+
const sharedArtifactRefs = [...requestedRefs].filter(ref => scopedRefs.has(ref));
|
|
682
|
+
const refusedRefs = [...requestedRefs].filter(ref => !scopedRefs.has(ref));
|
|
683
|
+
// Tools the spawning agent grants for this spawn. A command tool among them gives the child the shell and
|
|
684
|
+
// its own worktree; commands never run in a folder the child shares with its parent.
|
|
685
|
+
const granted = [...new Set((args.tools ?? []).map(name => canonicalToolName(name.trim())))];
|
|
686
|
+
const grantsCommands = granted.some(isCommandToolName);
|
|
687
|
+
if (grantsCommands && policy.workspace !== 'worktree')
|
|
688
|
+
throw new Error('Command tools can only be given to a subagent that runs in its own Git worktree, and this node\'s subagents share its working folder. Select Separate Git worktree for its subagents, or run the commands yourself.');
|
|
689
|
+
const delegated = delegationActive && depth === 0 && (isWritingRole(role) || grantsCommands);
|
|
550
690
|
if (delegated && !clarified)
|
|
551
691
|
throw new Error('Ask the user to confirm the design before starting writing subagents: a real ask_user answer is required first.');
|
|
552
692
|
if (delegated && policy.workspace !== 'worktree')
|
|
553
693
|
throw new Error('Writing roles on an Orchestrator require separate worktrees; select Separate Git worktree.');
|
|
554
694
|
const parentCapabilities = delegated ? effectiveCapabilities(node) : effectiveCapabilities(configured);
|
|
555
|
-
const
|
|
695
|
+
const roleCapabilities = role.capabilities ?? { ...parentCapabilities, ...(policy.workspace === undefined || policy.workspace === 'shared-read-only' ? { filesystem: parentCapabilities.filesystem === 'none' ? 'none' : 'read', git: parentCapabilities.git === 'none' ? 'none' : 'read', shell: 'disabled' } : {}) };
|
|
696
|
+
if (grantsCommands && parentCapabilities.shell !== 'allowed')
|
|
697
|
+
throw new Error('Command tools cannot be given: this agent is not allowed to run commands, so its subagents cannot be either.');
|
|
698
|
+
const childCapabilities = grantsCommands ? { ...roleCapabilities, shell: 'allowed' } : roleCapabilities;
|
|
556
699
|
if (!capabilitySubset(childCapabilities, parentCapabilities))
|
|
557
700
|
throw new Error('Subagent capabilities exceed its parent');
|
|
558
701
|
const writingChild = childCapabilities.filesystem === 'read-write' || childCapabilities.git === 'write';
|
|
@@ -564,16 +707,65 @@ export async function executeAgentNode(node, options) {
|
|
|
564
707
|
? [...capabilityTools({ ...node, capabilities: parentCapabilities, tools: undefined }, catalog, 'delegated-worktree').map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'),
|
|
565
708
|
...tools.map(tool => tool.name).filter(name => name === 'read_artifact' || name === 'write_artifact'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]
|
|
566
709
|
: [...tools.map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]);
|
|
567
|
-
const
|
|
568
|
-
|
|
710
|
+
const unavailable = granted.filter(name => ![...available].some(own => toolNameMatches(own, name)));
|
|
711
|
+
if (unavailable.length)
|
|
712
|
+
throw new Error(`These tools are not in your own tool list, so they cannot be given to a subagent: ${unavailable.join(', ')}`);
|
|
713
|
+
const grantedNames = granted.map(name => [...available].find(own => toolNameMatches(own, name)));
|
|
714
|
+
const baseToolNames = delegated ? canonicalizeToolList(role.tools) ?? [...available]
|
|
715
|
+
: policy.toolInheritance === 'inherit' || (general !== undefined && writingChild) ? [...available] : canonicalizeToolList(role.tools) ?? [...available].filter(name => ['Read', 'Glob', 'Grep', 'git_read', 'qa.browser_session', 'read_skill_resource'].includes(canonicalToolName(name)));
|
|
716
|
+
const childToolNames = [...new Set([...baseToolNames, ...grantedNames])];
|
|
569
717
|
if (childToolNames.some(name => !available.has(name)))
|
|
570
718
|
throw new Error('Subagent tool selection exceeds its parent');
|
|
571
|
-
|
|
572
|
-
|
|
719
|
+
// A child runs commands only in its own worktree: a delegated one always has one, and any other child gets one
|
|
720
|
+
// when its tools include a command tool its permissions allow. Creating that worktree needs Git write on the
|
|
721
|
+
// parent: without it a grant is refused up front, and an inherited command tool is simply not offered.
|
|
722
|
+
if (grantsCommands && !delegated && parentCapabilities.git !== 'write')
|
|
723
|
+
throw new Error('Command tools cannot be given: a subagent that runs commands needs its own Git worktree, and creating one needs Git write access, which this agent does not have.');
|
|
724
|
+
const runsCommands = !delegated && policy.workspace === 'worktree' && parentCapabilities.git === 'write' && childCapabilities.shell === 'allowed' && childToolNames.some(isCommandToolName);
|
|
725
|
+
const childScope = delegated ? 'delegated-worktree' : runsCommands ? 'worktree' : undefined;
|
|
726
|
+
const refused = grantedNames.filter(name => isCommandToolName(name) && !permitsBuiltInTool({ capabilities: childCapabilities }, name, childScope ?? true));
|
|
727
|
+
if (refused.length)
|
|
728
|
+
throw new Error(`These command tools are outside the subagent's permissions: ${refused.join(', ')}`);
|
|
729
|
+
let childProvider = policy.modelPolicy === 'specific' ? policy.provider ?? provider : policy.modelPolicy === 'per-role' ? role.provider ?? provider : provider;
|
|
730
|
+
let childModel = policy.modelPolicy === 'specific' ? policy.model : policy.modelPolicy === 'per-role' ? role.model ?? (childProvider === provider ? model : undefined) : model;
|
|
731
|
+
let childEffort = activeEffort !== undefined && childProvider === provider && childModel === model ? activeEffort : undefined;
|
|
732
|
+
// Routing picks the pair for a subagent that would otherwise inherit its parent's; a graph that names the subagent's model, or a
|
|
733
|
+
// node that sets its own, keeps it. A model chosen for the run pins the parent alone, so its subagents are still routed.
|
|
734
|
+
const inheritsModel = policy.modelPolicy !== 'specific' && !(policy.modelPolicy === 'per-role' && (role.provider !== undefined || role.model !== undefined));
|
|
735
|
+
const unpinnedNode = (configured.provider === undefined && configured.model === undefined) || inheritingChildren.has(configured);
|
|
736
|
+
if (subagentRouting && !poolSubagents && inheritsModel && !fallbackAttempt && unpinnedNode) {
|
|
737
|
+
const decision = decideModelTier({ task: args.task, routing: subagentRouting, baseline: { provider: childProvider, model: childModel ?? model },
|
|
738
|
+
node: {}, configured: options.configuredModels ?? [], levels: poolLevels });
|
|
739
|
+
if (decision.target) {
|
|
740
|
+
childProvider = decision.target.provider;
|
|
741
|
+
childModel = decision.target.model;
|
|
742
|
+
childEffort = decision.target.effort;
|
|
743
|
+
}
|
|
744
|
+
await emit('efficiency.routing.decided', { strategy: 'tiers', role: role.id, tier: decision.tier, reason: decision.reason, evidence: decision.evidence, applied: decision.applied });
|
|
745
|
+
}
|
|
746
|
+
if (poolSubagents && inheritsModel && !fallbackAttempt && unpinnedNode) {
|
|
747
|
+
const decision = decidePoolModel({ task: args.task, routing: poolSubagents, baseline: { provider: childProvider, model: childModel ?? model, effort: childEffort },
|
|
748
|
+
node: {}, configured: options.configuredModels ?? [], levels: poolLevels, quota: await readQuota(context.signal), ...(isPoolClass(args.class) ? { declaredClass: args.class } : {}) });
|
|
749
|
+
const shadow = poolSubagents.mode === 'shadow';
|
|
750
|
+
if (decision.target && !shadow) {
|
|
751
|
+
// A pair that names no level runs at the provider's saved one, not at the level its parent is running at.
|
|
752
|
+
childProvider = decision.target.provider;
|
|
753
|
+
childModel = decision.target.model;
|
|
754
|
+
childEffort = decision.target.effort;
|
|
755
|
+
}
|
|
756
|
+
await emit('efficiency.routing.decided', { strategy: 'pool', role: role.id, poolClass: decision.poolClass, reason: decision.reason, evidence: decision.evidence,
|
|
757
|
+
applied: !shadow && decision.applied, candidates: decision.candidates, blocked: decision.blocked, ...(decision.standing === undefined ? {} : { standing: decision.standing }),
|
|
758
|
+
...(shadow ? { shadow: true, ...(decision.target ? { would: decision.target } : {}) } : {}) });
|
|
759
|
+
}
|
|
573
760
|
const child = { id: role.id, type: 'agent', executor: 'react-basic', name: role.name, instruction: role.instruction,
|
|
574
|
-
provider: childProvider, ...(childModel ? { model: childModel } : {}),
|
|
761
|
+
provider: childProvider, ...(childModel ? { model: childModel } : {}),
|
|
762
|
+
// With no model named, a child on the same provider runs that provider's default, which may not be the parent's.
|
|
763
|
+
...(childEffort === undefined ? {} : { reasoningEffort: childEffort }),
|
|
764
|
+
capabilities: childCapabilities, tools: childToolNames,
|
|
575
765
|
completion: { mode: 'single', outcome: 'completed' }, inputSchema: role.inputSchema, outputSchema: role.outputSchema,
|
|
576
766
|
contextPolicy: { history: false, maxChars: Math.min(contextChars, 16000) } };
|
|
767
|
+
if (inheritsModel && unpinnedNode)
|
|
768
|
+
inheritingChildren.add(child);
|
|
577
769
|
if (depth > 0 && active >= (policy.maxConcurrent ?? 3))
|
|
578
770
|
throw new Error('Nested spawn would exceed concurrent subagent limit; finish current work first');
|
|
579
771
|
// A message for the parent ends the wait for a free slot too: the subagents holding the slots keep
|
|
@@ -607,6 +799,8 @@ export async function executeAgentNode(node, options) {
|
|
|
607
799
|
active++;
|
|
608
800
|
total++;
|
|
609
801
|
const id = randomUUID();
|
|
802
|
+
if (requestedRefs.size)
|
|
803
|
+
await emit('subagent.artifacts.shared', { role: role.id, shared: sharedArtifactRefs, refused: refusedRefs });
|
|
610
804
|
const cancel = new AbortController();
|
|
611
805
|
const childSignal = AbortSignal.any([callContext.signal, cancel.signal]);
|
|
612
806
|
const inbox = [];
|
|
@@ -627,6 +821,8 @@ export async function executeAgentNode(node, options) {
|
|
|
627
821
|
const work = (async () => {
|
|
628
822
|
let workspaceArtifact;
|
|
629
823
|
let delegatedWorktree;
|
|
824
|
+
// An ordinary child's worktree where it runs commands: its jobs stop with it, though the worktree is retained.
|
|
825
|
+
let commandWorktree;
|
|
630
826
|
let keepWorktree = false;
|
|
631
827
|
try {
|
|
632
828
|
const parentWorkspace = parentContext.workspace;
|
|
@@ -650,7 +846,7 @@ export async function executeAgentNode(node, options) {
|
|
|
650
846
|
workspace = inside ? join(worktree, inside) : worktree;
|
|
651
847
|
task += `\n\nThis task runs in a separate Git worktree started from the working folder as it stands: ${workspace}. Files ignored by Git (for example node_modules) are not in this worktree. Install what you need inside this worktree if a build or test requires it. Report the commands and tests you ran and their results in the tests list of your completion. This worktree shares the Git repository of the user's working folder: do not create or change stashes, branches, tags or Git configuration. Commit only if the task needs it; commits stay in this worktree, and your result is taken from the files as you leave them.`;
|
|
652
848
|
}
|
|
653
|
-
else if (policy.workspace === 'worktree' && writingChild) {
|
|
849
|
+
else if (policy.workspace === 'worktree' && (writingChild || runsCommands)) {
|
|
654
850
|
if (parentCapabilities.git !== 'write')
|
|
655
851
|
throw new Error('Creating child worktrees requires parent Git write capability');
|
|
656
852
|
const temporaryDirectoryPrefix = join(tmpdir(), 'andorra-subagent-');
|
|
@@ -683,6 +879,8 @@ export async function executeAgentNode(node, options) {
|
|
|
683
879
|
await authorizeWorktree();
|
|
684
880
|
const directory = await mkdtemp(temporaryDirectoryPrefix);
|
|
685
881
|
workspace = join(directory, 'worktree');
|
|
882
|
+
if (runsCommands)
|
|
883
|
+
commandWorktree = workspace;
|
|
686
884
|
await authorizeWorktree();
|
|
687
885
|
await exec('git', [...args, 'worktree', 'add', '--detach', workspace, 'HEAD'], gitOptions);
|
|
688
886
|
workspaceArtifact = await store.put('git-worktree', JSON.stringify({ workspace, role: role.id, note: 'Changes retained for explicit inspection and integration; not merged automatically.' }));
|
|
@@ -698,7 +896,7 @@ export async function executeAgentNode(node, options) {
|
|
|
698
896
|
task, ...(Object.keys(childInputs).length > 0 ? { input: childInputs } : {}) });
|
|
699
897
|
let result;
|
|
700
898
|
try {
|
|
701
|
-
result = await run(child, { ...parentContext, signal: childSignal, steerSignal: undefined, workspace, ...(parentContext.delegationRoots ? { delegationRoots: undefined } : {}) }, depth + 1, childInputs, task, id, fallbackAttempt,
|
|
899
|
+
result = await run(child, { ...parentContext, signal: childSignal, steerSignal: undefined, workspace, ...(parentContext.delegationRoots ? { delegationRoots: undefined } : {}) }, depth + 1, childInputs, task, id, fallbackAttempt, childScope, sharedArtifactRefs);
|
|
702
900
|
}
|
|
703
901
|
catch (error) {
|
|
704
902
|
await emit('subagent.completed', { subagentId: id, role: role.id, status: childSignal.aborted ? 'cancelled' : 'failed' });
|
|
@@ -707,6 +905,8 @@ export async function executeAgentNode(node, options) {
|
|
|
707
905
|
finally {
|
|
708
906
|
if (delegatedWorktree)
|
|
709
907
|
await stopWorktreeJobs(delegatedWorktree.worktree);
|
|
908
|
+
if (commandWorktree)
|
|
909
|
+
await stopWorktreeJobs(commandWorktree);
|
|
710
910
|
}
|
|
711
911
|
if (result.telemetry)
|
|
712
912
|
mergeRunTelemetry(telemetry, result.telemetry);
|
|
@@ -718,6 +918,9 @@ export async function executeAgentNode(node, options) {
|
|
|
718
918
|
scopedRefs.add(artifact.ref);
|
|
719
919
|
references(result.completion?.output, scopedRefs);
|
|
720
920
|
const observation = { status: result.status, reason: result.reason, outcome: result.completion?.outcome, output: result.completion?.output, artifacts: returnedArtifacts };
|
|
921
|
+
// A general subagent has no output schema, so its answer is its summary: without it the parent gets an empty output.
|
|
922
|
+
if (general !== undefined && result.completion?.summary)
|
|
923
|
+
observation.summary = result.completion.summary.slice(0, 16000);
|
|
721
924
|
if (delegatedWorktree) {
|
|
722
925
|
observation.tests = result.completion?.tests ?? [];
|
|
723
926
|
const collected = result.status === 'succeeded' ? await collectChange(delegatedWorktree.worktree, delegatedWorktree.base, parentContext.signal) : undefined;
|
|
@@ -1002,21 +1205,28 @@ export async function executeAgentNode(node, options) {
|
|
|
1002
1205
|
}).map(requirePublishedPlan) : [];
|
|
1003
1206
|
if (skillTools.length)
|
|
1004
1207
|
tools = tools.filter(tool => tool.name !== 'read_skill_resource');
|
|
1005
|
-
// The report
|
|
1208
|
+
// The report tools exist only in a run that carries the bug-report skill, so no other run pays for their schemas.
|
|
1006
1209
|
if (depth === 0 && [...inheritedSkills, ...promptSkills].includes(BUG_REPORT_SKILL))
|
|
1007
|
-
tools.push(bugReportTool({ emit }));
|
|
1210
|
+
tools.push(bugReportSessionsTool(), bugReportTool({ emit }));
|
|
1008
1211
|
const effectiveTask = typeof inputs.taskInstruction === 'string' && inputs.taskInstruction.trim() ? inputs.taskInstruction.trim() : task;
|
|
1009
1212
|
const graphFirstSearch = depth === 0 && !!codeIntel?.active && codeGraphRoute(effectiveTask) === 'graph';
|
|
1010
1213
|
const decisionTask = depth > 0 ? task : options.decisionPreflight?.task ?? effectiveTask;
|
|
1011
1214
|
let result;
|
|
1012
|
-
const telemetry = createRunTelemetry();
|
|
1215
|
+
const telemetry = createRunTelemetry(options.telemetry);
|
|
1013
1216
|
let attempts = depth === 0 ? configured.retry?.maxAttempts ?? 1 : 1;
|
|
1014
1217
|
const efficiency = resolveEfficiency(options.efficiency);
|
|
1015
1218
|
const facts = depth === 0 && (efficiency.contextSelection || efficiency.catalogSelection)
|
|
1016
1219
|
? options.workspaceFacts ?? await collectWorkspaceFacts(context.workspace, { signal: context.signal }) : undefined;
|
|
1017
1220
|
const nodeBaseline = { provider, model };
|
|
1018
1221
|
let routedTier;
|
|
1222
|
+
let routedPoolClass;
|
|
1223
|
+
const poolRouting = efficiency.adaptiveRouting.enabled && efficiency.adaptiveRouting.strategy === 'pool';
|
|
1224
|
+
const baselineEffort = asLevel(resolved.reasoningEffort);
|
|
1225
|
+
let effortLevel;
|
|
1226
|
+
let effortEscalated = false;
|
|
1019
1227
|
let escalations = 0;
|
|
1228
|
+
// The model a routed pair installed its thinking level on, so a later attempt whose pair names none can drop it.
|
|
1229
|
+
let poolLevelled;
|
|
1020
1230
|
let previousAttemptReason;
|
|
1021
1231
|
let escalationPending = false;
|
|
1022
1232
|
let escalationFailed = false;
|
|
@@ -1037,8 +1247,11 @@ export async function executeAgentNode(node, options) {
|
|
|
1037
1247
|
fallbackAttempt = true;
|
|
1038
1248
|
const liveNodeId = `${node.id}${subagentId ? '/' + configured.id : ''}${fallbackAttempt ? '#fallback' : ''}`;
|
|
1039
1249
|
const liveModel = await options.getLiveModel?.(liveNodeId, provider, model, context.signal);
|
|
1250
|
+
liveResolved = undefined;
|
|
1040
1251
|
const liveSelected = liveModel !== undefined;
|
|
1041
|
-
if (liveModel
|
|
1252
|
+
if (liveModel?.sessionModel)
|
|
1253
|
+
sessionModel = { provider: liveModel.provider, model: liveModel.model };
|
|
1254
|
+
if (liveModel && (liveModel.provider !== provider || liveModel.model !== model || liveModel.selectionRevision !== undefined)) {
|
|
1042
1255
|
provider = liveModel.provider;
|
|
1043
1256
|
model = liveModel.model;
|
|
1044
1257
|
resolved = liveModel;
|
|
@@ -1093,18 +1306,20 @@ export async function executeAgentNode(node, options) {
|
|
|
1093
1306
|
const spendRepoRoom = (chars) => { repoBudget -= chars; repoPolicyRoom -= chars; };
|
|
1094
1307
|
let committedChars = 0;
|
|
1095
1308
|
if (depth === 0 && codeLedger && codeIntel) {
|
|
1096
|
-
const historyChars = configured.contextPolicy?.history ? (options.history ?? []).reduce((sum, item) => sum + turnModelTask(item).length + JSON.stringify(item.completion).length, 0) : 0;
|
|
1309
|
+
const historyChars = configured.contextPolicy?.history ? (options.history ?? []).reduce((sum, item) => sum + turnModelTask(item).length + JSON.stringify(turnModelCompletion(item.completion)).length, 0) : 0;
|
|
1097
1310
|
const toolSchemaChars = JSON.stringify(tools.map(tool => ({ name: tool.name, description: tool.description, parameters: tool.parameters }))).length;
|
|
1098
1311
|
const contractChars = JSON.stringify({ outputSchema: configured.outputSchema, completion: configured.completion }).length;
|
|
1099
1312
|
const todoChars = JSON.stringify(todoStore.snapshot()).length;
|
|
1100
1313
|
committedChars = taskBase.length + attemptPrompt.length + nodeInstructions.length + historyChars + toolSchemaChars + contractChars + todoChars + 8_000;
|
|
1101
1314
|
repoBudget = executionLimits.maxContextChars - committedChars;
|
|
1102
|
-
repoPolicyRoom = contextChars - (committedChars - toolSchemaChars);
|
|
1315
|
+
repoPolicyRoom = contextChars - (committedChars - toolSchemaChars - nodeInstructions.length - historyChars);
|
|
1103
1316
|
}
|
|
1104
1317
|
let activeRouting;
|
|
1105
1318
|
let attemptTools = tools;
|
|
1106
1319
|
const initialPromptChars = attemptPrompt.length;
|
|
1107
1320
|
let recoverTools;
|
|
1321
|
+
let jevOmittedTools = [];
|
|
1322
|
+
const jevPromptAdditions = [];
|
|
1108
1323
|
const skillContextBudget = () => {
|
|
1109
1324
|
const pinned = [taskBase, attemptPrompt, nodeInstructions,
|
|
1110
1325
|
JSON.stringify(configured.outputSchema ?? { type: 'object' }),
|
|
@@ -1112,17 +1327,18 @@ export async function executeAgentNode(node, options) {
|
|
|
1112
1327
|
JSON.stringify(completionPolicy.mode === 'single' ? completionPolicy.outcome : completionPolicy.outcomes[0]),
|
|
1113
1328
|
JSON.stringify(todoStore.snapshot())];
|
|
1114
1329
|
const historyChars = JSON.stringify(configured.contextPolicy?.history ? (options.history ?? []).flatMap(turn => [
|
|
1115
|
-
{ role: 'user', content: turnModelTask(turn) }, { role: 'assistant', content: JSON.stringify(turn.completion) },
|
|
1330
|
+
{ role: 'user', content: turnModelTask(turn) }, { role: 'assistant', content: JSON.stringify(turnModelCompletion(turn.completion)) },
|
|
1116
1331
|
]) : []).length;
|
|
1117
1332
|
const schemaChars = JSON.stringify([...attemptTools, completionTool({ ...options, completionPolicy, outputSchema: configured.outputSchema })]
|
|
1118
1333
|
.map(({ name, description, parameters }) => ({ name, description, parameters }))).length
|
|
1119
1334
|
+ JSON.stringify((recoverTools ?? []).filter(tool => !attemptTools.includes(tool)).map(tool => tool.name)).length;
|
|
1120
1335
|
const fixedChars = JSON.stringify(pinned).length + historyChars + 8300;
|
|
1121
|
-
const policyRoom = contextChars - fixedChars;
|
|
1336
|
+
const policyRoom = contextChars - (fixedChars - JSON.stringify(nodeInstructions).length - historyChars);
|
|
1122
1337
|
const requestRoom = executionLimits.maxContextChars - fixedChars - schemaChars;
|
|
1123
1338
|
return Math.max(0, Math.min(8000, policyRoom, requestRoom));
|
|
1124
1339
|
};
|
|
1125
1340
|
let memoryBlockAdded = false;
|
|
1341
|
+
let optionalMemoryBlock = '';
|
|
1126
1342
|
let pendingMemoryApplication;
|
|
1127
1343
|
let pendingGraphApplication;
|
|
1128
1344
|
const recordDecision = (event) => {
|
|
@@ -1143,7 +1359,9 @@ export async function executeAgentNode(node, options) {
|
|
|
1143
1359
|
consumers: { answerOnly: answerOnlyTask(decisionTask),
|
|
1144
1360
|
adaptiveRouting: attempt === 1 && depth === 0 && !subagentId && !fallbackAttempt
|
|
1145
1361
|
&& configured.provider === undefined && configured.model === undefined && !options.modelPinned && !liveSelected
|
|
1146
|
-
&& hasAdaptiveAlternative(efficiency.adaptiveRouting, nodeBaseline, options.configuredModels ?? [])
|
|
1362
|
+
&& hasAdaptiveAlternative(efficiency.adaptiveRouting, { ...nodeBaseline, effort: baselineEffort }, options.configuredModels ?? [])
|
|
1363
|
+
// A node on Auto thinking needs the same three answers to pick among its model's levels.
|
|
1364
|
+
|| attempt === 1 && depth === 0 && !subagentId && wantedEffort() === 'auto' && levelsFor(provider, model, resolved?.providerType, true).length >= 2,
|
|
1147
1365
|
},
|
|
1148
1366
|
}, { runId: options.runId, nodeId: configured.id, invocationId: randomUUID(), ...(subagentId ? { subagentId } : {}) }, { codeGraph: depth === 0 && !!codeIntel?.active && repoRoom() >= 512 && codeGraphRoute(effectiveTask) === 'graph', memory: depth === 0 && (options.decisionPreflight?.memory ?? (configured.agentRole !== 'orchestrator' && !!options.memory?.activeFor(options.runId) && options.memory.automaticRetrieval)) }, signal, event => {
|
|
1149
1367
|
if (signal.aborted)
|
|
@@ -1170,7 +1388,8 @@ export async function executeAgentNode(node, options) {
|
|
|
1170
1388
|
});
|
|
1171
1389
|
else {
|
|
1172
1390
|
const shadow = preflight(context.runControl ? AbortSignal.any([context.signal, context.runControl.signal]) : context.signal);
|
|
1173
|
-
|
|
1391
|
+
if (hasRunTelemetry(telemetry))
|
|
1392
|
+
(telemetry.pendingDecisions ??= []).push(shadow.catch(() => undefined));
|
|
1174
1393
|
void shadow.catch(() => undefined);
|
|
1175
1394
|
}
|
|
1176
1395
|
}
|
|
@@ -1186,12 +1405,73 @@ export async function executeAgentNode(node, options) {
|
|
|
1186
1405
|
if (efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId && explicitFallbackRetry) {
|
|
1187
1406
|
await emitEfficiency('efficiency.routing.decided', { tier: undefined, reason: 'pinned', evidence: 'pinned', applied: false, attempt });
|
|
1188
1407
|
}
|
|
1189
|
-
|
|
1408
|
+
const previousPoolEffort = poolEffort;
|
|
1409
|
+
if (efficiency.adaptiveRouting.enabled)
|
|
1410
|
+
poolEffort = undefined;
|
|
1411
|
+
if (poolRouting && depth === 0 && !subagentId && !explicitFallbackRetry) {
|
|
1412
|
+
// Pool routing: the task's class sets the score a pair must reach, and subscription usage chooses among the
|
|
1413
|
+
// pairs that reach it. Shadow mode records the decision and leaves the attempt as it was.
|
|
1414
|
+
const shadow = efficiency.adaptiveRouting.mode === 'shadow';
|
|
1415
|
+
const decision = decidePoolModel({
|
|
1416
|
+
task: effectiveTask, routing: efficiency.adaptiveRouting, baseline: { ...nodeBaseline, effort: baselineEffort },
|
|
1417
|
+
node: { provider: configured.provider, model: configured.model }, modelPinned: options.modelPinned === true || liveSelected,
|
|
1418
|
+
hints: activeRouting?.decisions, configured: options.configuredModels ?? [], levels: poolLevels, quota: await readQuota(context.signal),
|
|
1419
|
+
previous: attempt > 1 && routedPoolClass ? { poolClass: routedPoolClass, reason: previousAttemptReason, escalations } : undefined,
|
|
1420
|
+
});
|
|
1421
|
+
let applied = false;
|
|
1422
|
+
let unresolved = false;
|
|
1423
|
+
let served = false;
|
|
1424
|
+
if (decision.target && !shadow) {
|
|
1425
|
+
const target = decision.target;
|
|
1426
|
+
if (provider === target.provider && model === target.model) {
|
|
1427
|
+
applied = decision.applied;
|
|
1428
|
+
served = true;
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
try {
|
|
1432
|
+
const routed = await resolve(target.provider, target.model);
|
|
1433
|
+
if (routed) {
|
|
1434
|
+
provider = target.provider;
|
|
1435
|
+
model = target.model;
|
|
1436
|
+
resolved = routed;
|
|
1437
|
+
applied = true;
|
|
1438
|
+
served = true;
|
|
1439
|
+
const routedWindow = routed.contextWindow;
|
|
1440
|
+
executionLimits.maxContextChars = routedWindow !== undefined && Number.isSafeInteger(routedWindow) && routedWindow > 0 ? Math.min(contextCharCeiling, routedWindow * 3) : contextCharCeiling;
|
|
1441
|
+
if (depth === 0 && codeLedger && codeIntel)
|
|
1442
|
+
repoBudget = executionLimits.maxContextChars - committedChars;
|
|
1443
|
+
await emit('agent.model.changed', { provider, model, ...(routedWindow === undefined ? {} : { contextWindow: routedWindow }), poolClass: decision.poolClass });
|
|
1444
|
+
}
|
|
1445
|
+
else
|
|
1446
|
+
unresolved = true;
|
|
1447
|
+
}
|
|
1448
|
+
catch {
|
|
1449
|
+
unresolved = true;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
// The level is applied with the node's other level rules below, once per attempt.
|
|
1453
|
+
if (served)
|
|
1454
|
+
poolEffort = target.effort;
|
|
1455
|
+
}
|
|
1456
|
+
if (served)
|
|
1457
|
+
routedPoolClass = decision.poolClass;
|
|
1458
|
+
if (decision.reason === 'escalated' && served)
|
|
1459
|
+
escalations++;
|
|
1460
|
+
if (escalationPending) {
|
|
1461
|
+
escalationPending = false;
|
|
1462
|
+
if (!(decision.reason === 'escalated' && served))
|
|
1463
|
+
escalationFailed = true;
|
|
1464
|
+
}
|
|
1465
|
+
await emitEfficiency('efficiency.routing.decided', { strategy: 'pool', poolClass: decision.poolClass, reason: unresolved ? 'unconfigured' : decision.reason, evidence: decision.evidence, applied, served, attempt,
|
|
1466
|
+
candidates: decision.candidates, blocked: decision.blocked, ...(decision.standing === undefined ? {} : { standing: decision.standing }),
|
|
1467
|
+
...(shadow ? { shadow: true, ...(decision.target ? { would: decision.target } : {}) } : {}) });
|
|
1468
|
+
}
|
|
1469
|
+
if (efficiency.adaptiveRouting.enabled && !poolRouting && depth === 0 && !subagentId && !explicitFallbackRetry) {
|
|
1190
1470
|
const decision = decideModelTier({
|
|
1191
1471
|
task: effectiveTask, routing: efficiency.adaptiveRouting, baseline: nodeBaseline,
|
|
1192
1472
|
node: { provider: configured.provider, model: configured.model }, modelPinned: options.modelPinned === true || liveSelected,
|
|
1193
1473
|
hints: activeRouting?.decisions, configured: options.configuredModels ?? [],
|
|
1194
|
-
previous: attempt > 1 && routedTier ? { tier: routedTier, reason: previousAttemptReason, escalations } : undefined,
|
|
1474
|
+
previous: attempt > 1 && routedTier ? { tier: routedTier, reason: previousAttemptReason, escalations } : undefined, levels: poolLevels,
|
|
1195
1475
|
});
|
|
1196
1476
|
let applied = false;
|
|
1197
1477
|
let unresolved = false;
|
|
@@ -1226,9 +1506,13 @@ export async function executeAgentNode(node, options) {
|
|
|
1226
1506
|
}
|
|
1227
1507
|
}
|
|
1228
1508
|
}
|
|
1229
|
-
|
|
1509
|
+
// The tier's thinking level is applied with the node's other level rules below, as a pool pair's is.
|
|
1510
|
+
if (served) {
|
|
1230
1511
|
routedTier = decision.tier;
|
|
1231
|
-
|
|
1512
|
+
poolEffort = asLevel(decision.target?.effort);
|
|
1513
|
+
}
|
|
1514
|
+
// A tier that keeps the model and changes only its thinking level is an escalation too.
|
|
1515
|
+
if (decision.reason === 'escalated' && (applied || (served && configured.reasoningEffort === undefined && poolEffort !== previousPoolEffort)))
|
|
1232
1516
|
escalations++;
|
|
1233
1517
|
if (escalationPending) {
|
|
1234
1518
|
escalationPending = false;
|
|
@@ -1237,6 +1521,77 @@ export async function executeAgentNode(node, options) {
|
|
|
1237
1521
|
}
|
|
1238
1522
|
await emitEfficiency('efficiency.routing.decided', { tier: decision.tier, reason: unresolved ? 'unconfigured' : decision.reason, evidence: decision.evidence, applied, served, attempt });
|
|
1239
1523
|
}
|
|
1524
|
+
if (poolLevelled && poolEffort === undefined && poolLevelled.provider === provider && poolLevelled.model === model) {
|
|
1525
|
+
// This attempt names no level, so it runs at the saved one, not at the level an earlier pair left in force.
|
|
1526
|
+
try {
|
|
1527
|
+
const saved = await resolve(provider, model);
|
|
1528
|
+
if (saved)
|
|
1529
|
+
resolved = saved;
|
|
1530
|
+
}
|
|
1531
|
+
catch {
|
|
1532
|
+
context.signal.throwIfAborted();
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
if (poolEffort === undefined)
|
|
1536
|
+
poolLevelled = undefined;
|
|
1537
|
+
{
|
|
1538
|
+
// The thinking level is settled once per attempt, before the first request, and held for the whole attempt:
|
|
1539
|
+
// a change between requests makes the provider re-read the conversation uncached.
|
|
1540
|
+
const wanted = wantedEffort();
|
|
1541
|
+
const current = asLevel(resolved.reasoningEffort);
|
|
1542
|
+
const enabled = levelsFor(provider, model, resolved.providerType, false);
|
|
1543
|
+
if (wanted === undefined) {
|
|
1544
|
+
// The saved level is the session's or the provider's. A level switched off for this model is never sent.
|
|
1545
|
+
const allowed = current === undefined || enabled.length === 0 ? current : nearestEnabled(enabled, current);
|
|
1546
|
+
activeEffort = current;
|
|
1547
|
+
if (allowed !== undefined && allowed !== current) {
|
|
1548
|
+
try {
|
|
1549
|
+
const levelled = await resolve(provider, model, allowed);
|
|
1550
|
+
if (levelled) {
|
|
1551
|
+
resolved = levelled;
|
|
1552
|
+
activeEffort = allowed;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
catch {
|
|
1556
|
+
context.signal.throwIfAborted();
|
|
1557
|
+
}
|
|
1558
|
+
await emitEfficiency('efficiency.effort.decided', { mode: 'fixed', wanted: current, level: allowed, evidence: 'fixed', applied: activeEffort === allowed, attempt, ...(subagentId ? { subagentId } : {}) });
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
else {
|
|
1562
|
+
// Auto chooses among its own list; when that list is empty (every widely accepted level of an undetected
|
|
1563
|
+
// model was switched off) it chooses among everything still enabled, so a switched-off level is never kept.
|
|
1564
|
+
const forAuto = wanted === 'auto' ? levelsFor(provider, model, resolved.providerType, true) : [];
|
|
1565
|
+
const levels = forAuto.length > 0 ? forAuto : enabled;
|
|
1566
|
+
const decision = wanted === 'auto'
|
|
1567
|
+
// The task as the user wrote it, which is also what Jev was asked about.
|
|
1568
|
+
? decideEffort({ task: decisionTask, levels, hints: depth === 0 && !subagentId ? activeRouting?.decisions : undefined, fallback: current,
|
|
1569
|
+
previous: attempt > 1 && effortLevel !== undefined ? { level: effortLevel, reason: previousAttemptReason } : undefined })
|
|
1570
|
+
: { level: nearestEnabled(levels, wanted), evidence: 'fixed' };
|
|
1571
|
+
let inForce = current;
|
|
1572
|
+
if (decision.level !== undefined && decision.level !== current) {
|
|
1573
|
+
try {
|
|
1574
|
+
const levelled = await resolve(provider, model, decision.level);
|
|
1575
|
+
if (levelled) {
|
|
1576
|
+
resolved = levelled;
|
|
1577
|
+
inForce = decision.level;
|
|
1578
|
+
if (configured.reasoningEffort === undefined && poolEffort !== undefined)
|
|
1579
|
+
poolLevelled = { provider, model };
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
catch {
|
|
1583
|
+
context.signal.throwIfAborted();
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
effortLevel = wanted === 'auto' ? decision.level : undefined;
|
|
1587
|
+
activeEffort = inForce;
|
|
1588
|
+
if (wanted === 'auto' || decision.level !== wanted) {
|
|
1589
|
+
await emitEfficiency('efficiency.effort.decided', { mode: wanted === 'auto' ? 'auto' : 'fixed', ...(wanted === 'auto' ? {} : { wanted }),
|
|
1590
|
+
...(decision.level === undefined ? {} : { level: decision.level }), evidence: decision.evidence, applied: decision.level !== undefined && inForce === decision.level, attempt,
|
|
1591
|
+
...(subagentId ? { subagentId } : {}) });
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1240
1595
|
const inheritedConversation = depth === 0 && configured.contextPolicy?.conversation !== 'isolate' && configured.contextPolicy?.skillInheritance !== 'none'
|
|
1241
1596
|
&& options.previousConversation?.provider === provider && options.previousConversation.model === model ? options.previousConversation : undefined;
|
|
1242
1597
|
const historicalToolNames = [...new Set((inheritedConversation?.messages ?? []).flatMap(message => (message.toolCalls ?? []).map(call => call.name)))];
|
|
@@ -1266,6 +1621,7 @@ export async function executeAgentNode(node, options) {
|
|
|
1266
1621
|
}
|
|
1267
1622
|
}
|
|
1268
1623
|
const omitted = recoverTools.filter(tool => !attemptTools.includes(tool));
|
|
1624
|
+
jevOmittedTools = omitted;
|
|
1269
1625
|
const selectedRole = DecisionPolicy.choice(decisions, 'delegation_role');
|
|
1270
1626
|
const role = (policy.roles ?? []).find(item => item.id === selectedRole);
|
|
1271
1627
|
const explicitOtherRole = (policy.roles ?? []).some(item => item.id !== selectedRole
|
|
@@ -1273,24 +1629,27 @@ export async function executeAgentNode(node, options) {
|
|
|
1273
1629
|
if (role && !explicitOtherRole && DecisionPolicy.boolean(decisions, 'needs_delegation') === true) {
|
|
1274
1630
|
attemptTools = attemptTools.map(tool => tool.name !== 'spawn_subagent' ? tool : {
|
|
1275
1631
|
...tool,
|
|
1276
|
-
description: 'Run the selected configured role on a bounded task. Use restore_tools for spawn_subagent if another configured role is needed. Role contract: '
|
|
1632
|
+
description: 'Run the selected configured role on a bounded task. Use restore_tools for spawn_subagent if another configured role is needed. ' + ((policy.freeform ?? 'off') === 'off' ? '' : 'Omit role to run a general subagent instead. ') + 'Role contract: '
|
|
1277
1633
|
+ JSON.stringify({ id: role.id, name: role.name, instruction: role.instruction, inputSchema: role.inputSchema, outputSchema: role.outputSchema }),
|
|
1278
1634
|
parameters: { ...tool.parameters, properties: { ...tool.parameters.properties, role: { type: 'string', enum: [role.id] } } },
|
|
1279
1635
|
});
|
|
1280
1636
|
}
|
|
1281
1637
|
const guidance = decisionExecutionGuidance(decisions, tools.some(tool => tool.name === 'spawn_subagent') ? (policy.roles ?? []).map(role => role.id) : []);
|
|
1282
1638
|
if (guidance)
|
|
1283
|
-
|
|
1639
|
+
jevPromptAdditions.push(`\n\n${guidance}`);
|
|
1284
1640
|
if (omitted.length)
|
|
1285
|
-
|
|
1641
|
+
jevPromptAdditions.push(`\n\nSome already-permitted tool schemas were omitted to reduce context: ${JSON.stringify(omitted.map(tool => tool.name))}. If task evidence requires one, call restore_tools with its name in the names array, then call the restored tool normally. Restoration never grants new permissions or bypasses approvals.`);
|
|
1642
|
+
attemptPrompt += jevPromptAdditions.join('');
|
|
1286
1643
|
const skillBudget = skillContextBudget();
|
|
1287
1644
|
let skillBlock = '';
|
|
1288
1645
|
const selectedSkill = options.decisionManager?.skillRoutingEnabled
|
|
1289
1646
|
? skills.find(skill => !skill.unavailable && skill.id === DecisionPolicy.choice(decisions, 'skill_role')) : undefined;
|
|
1290
1647
|
if (selectedSkill && attemptTools.some(tool => tool.name === 'Skill')) {
|
|
1291
1648
|
const selected = `\nRuntime selected skill: ${JSON.stringify(selectedSkill.id)}. Load this reference lazily with Skill using ${JSON.stringify({ skill: selectedSkill.id })} before applying it, subject to explicit user instructions and required plan publication.`;
|
|
1292
|
-
if (JSON.stringify(selected).length <= skillBudget)
|
|
1649
|
+
if (JSON.stringify(selected).length <= skillBudget) {
|
|
1293
1650
|
skillBlock = selected;
|
|
1651
|
+
jevPromptAdditions.push(selected);
|
|
1652
|
+
}
|
|
1294
1653
|
}
|
|
1295
1654
|
if (skills.length) {
|
|
1296
1655
|
const entries = skillCatalogText(efficiency.catalogSelection ? Math.max(0, skillBudget - JSON.stringify(skillBlock).length - 96) : skillBudget);
|
|
@@ -1332,8 +1691,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1332
1691
|
if (depth === 0 && permissionMode(bounded) === 'plan')
|
|
1333
1692
|
attemptPrompt += `\n\n${PLAN_MODE_INSTRUCTIONS}`;
|
|
1334
1693
|
if (efficiency.catalogSelection && depth === 0) {
|
|
1335
|
-
const
|
|
1336
|
-
codeGraphAvailable: !!codeIntel?.active, memoryAvailable: !!options.memory?.activeFor(options.runId) }
|
|
1694
|
+
const selectionInput = { tools: attemptTools, task: effectiveTask, facts, explicitTools: configured.tools, historicalToolNames,
|
|
1695
|
+
codeGraphAvailable: !!codeIntel?.active, memoryAvailable: !!options.memory?.activeFor(options.runId) };
|
|
1696
|
+
const selection = selectToolCatalog(selectionInput);
|
|
1697
|
+
if (jevOmittedTools.length) {
|
|
1698
|
+
// A schema that local catalog selection would also omit cannot be credited to Jev.
|
|
1699
|
+
const baseline = selectToolCatalog({ ...selectionInput, tools: [...attemptTools, ...jevOmittedTools] });
|
|
1700
|
+
jevOmittedTools = jevOmittedTools.filter(tool => baseline.tools.includes(tool));
|
|
1701
|
+
}
|
|
1337
1702
|
const note = `\n\nSome already-permitted tool schemas were omitted for this task: ${JSON.stringify(selection.omitted.map(tool => tool.name))}. If task evidence requires one, call restore_tools with its name in the names array, then call the restored tool normally. Restoration never grants new permissions or bypasses approvals.`;
|
|
1338
1703
|
const saved = selection.schemaCharsBefore - selection.schemaCharsAfter;
|
|
1339
1704
|
const applied = selection.omitted.length > 0 && saved > note.length + RESTORE_TOOL_SCHEMA_CHARS;
|
|
@@ -1396,7 +1761,10 @@ export async function executeAgentNode(node, options) {
|
|
|
1396
1761
|
memoryBlock = '';
|
|
1397
1762
|
}
|
|
1398
1763
|
if (memoryBlock) {
|
|
1399
|
-
|
|
1764
|
+
if (orchestrator)
|
|
1765
|
+
taskBase += `\n\n${memoryBlock}`;
|
|
1766
|
+
else
|
|
1767
|
+
optionalMemoryBlock = memoryBlock;
|
|
1400
1768
|
spendRepoRoom(memoryBlock.length + 2);
|
|
1401
1769
|
memoryBlockAdded = true;
|
|
1402
1770
|
}
|
|
@@ -1483,8 +1851,15 @@ export async function executeAgentNode(node, options) {
|
|
|
1483
1851
|
efficiency: configured.tools && options.efficiency?.toolMenuRouting
|
|
1484
1852
|
? { ...options.efficiency, toolMenuRouting: { ...options.efficiency.toolMenuRouting, pinnedTools: [...new Set([...(options.efficiency.toolMenuRouting.pinnedTools ?? []), ...configured.tools.map(canonicalToolName)])] } }
|
|
1485
1853
|
: options.efficiency,
|
|
1486
|
-
getLiveModel: options.getLiveModel ? (_id, currentProvider, currentModel, signal
|
|
1854
|
+
getLiveModel: options.getLiveModel ? async (_id, currentProvider, currentModel, signal, appliedRevision, hints) => {
|
|
1855
|
+
const live = await options.getLiveModel(liveNodeId, currentProvider, currentModel, signal, appliedRevision, hints);
|
|
1856
|
+
if (live)
|
|
1857
|
+
liveResolved = live;
|
|
1858
|
+
return live;
|
|
1859
|
+
} : undefined,
|
|
1487
1860
|
adapter: resolved.adapter, contextWindow: resolved.contextWindow, tools: attemptTools, recoverTools: engineRecoverTools, decisionTask,
|
|
1861
|
+
telemetry: options.telemetry,
|
|
1862
|
+
jevToolRouting: jevOmittedTools.length ? { omittedTools: applyToolProfile(jevOmittedTools, options.toolProfile), promptAdditions: jevPromptAdditions } : undefined,
|
|
1488
1863
|
telemetryIdentity: { providerType: resolved.providerType, baseUrl: resolved.baseUrl, role: subagentId ? 'subagent' : orchestrator ? 'orchestrator' : 'agent' }, decisionHints: activeRouting?.decisions, budget, artifactStore: store,
|
|
1489
1864
|
previousConversation: depth === 0 && configured.contextPolicy?.conversation !== 'isolate' && configured.contextPolicy?.skillInheritance !== 'none' && options.previousConversation?.provider === provider && options.previousConversation.model === model ? options.previousConversation : undefined,
|
|
1490
1865
|
onConversationCheckpoint: depth === 0 && options.onConversationCheckpoint ? (messages, state, conversation) => options.onConversationCheckpoint(messages, { ...state, ...(orchestrator ? { orchestratorIntake: {
|
|
@@ -1529,7 +1904,9 @@ export async function executeAgentNode(node, options) {
|
|
|
1529
1904
|
: depth === 0 && policy.enabled ? () => backgroundGuard() ?? (inheritedSkills.length || promptSkills.length ? missingSkillError() : undefined)
|
|
1530
1905
|
: inheritedSkills.length || promptSkills.length ? () => missingSkillError() : undefined, completionPolicy, outputSchema: configured.outputSchema,
|
|
1531
1906
|
history: configured.contextPolicy?.history ? options.history : [],
|
|
1532
|
-
|
|
1907
|
+
// Intake may rely on injected repository research to satisfy its clarification gate.
|
|
1908
|
+
task: orchestrator && attemptRepoBlock ? `${taskBase}\n\n${attemptRepoBlock}` : taskBase,
|
|
1909
|
+
optionalContext: orchestrator ? undefined : { memory: optionalMemoryBlock, repository: attemptRepoBlock },
|
|
1533
1910
|
onUsage: (usage, origin) => {
|
|
1534
1911
|
options.onUsage?.(usage, origin);
|
|
1535
1912
|
},
|
|
@@ -1537,13 +1914,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1537
1914
|
if (result.telemetry) {
|
|
1538
1915
|
recordAttempt(result.telemetry, attempt > 1);
|
|
1539
1916
|
mergeRunTelemetry(telemetry, result.telemetry);
|
|
1540
|
-
result
|
|
1917
|
+
bindRunTelemetry(result, telemetry);
|
|
1541
1918
|
}
|
|
1542
1919
|
previousAttemptReason = result.reason;
|
|
1543
1920
|
previousMutations = result.mutations;
|
|
1544
1921
|
const tiers = efficiency.adaptiveRouting.tiers ?? {};
|
|
1545
1922
|
const higherTier = routedTier === 'economy' ? tiers.balanced ?? tiers.premium : routedTier === 'balanced' ? tiers.premium : undefined;
|
|
1546
|
-
const escalate = efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId
|
|
1923
|
+
const escalate = efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId
|
|
1924
|
+
&& (poolRouting ? routedPoolClass !== undefined && routedPoolClass !== 'escalated' : routedTier !== undefined && higherTier !== undefined) && !escalationFailed
|
|
1547
1925
|
&& escalations < efficiency.adaptiveRouting.maxEscalations && result.status === 'exhausted'
|
|
1548
1926
|
&& ['repeatedToolFailure', 'maxIterations'].includes(result.reason ?? '') && !context.signal.aborted
|
|
1549
1927
|
&& (options.budget === undefined || options.budget.maxToolCalls === undefined || options.budget.toolCalls < options.budget.maxToolCalls);
|
|
@@ -1552,7 +1930,17 @@ export async function executeAgentNode(node, options) {
|
|
|
1552
1930
|
if (attempt === attempts)
|
|
1553
1931
|
attempts = attempt + 1;
|
|
1554
1932
|
}
|
|
1555
|
-
|
|
1933
|
+
// A node on Auto thinking that ran out of steps gets one more attempt a level higher, when there is one.
|
|
1934
|
+
const effortLevels = effortLevel === undefined ? [] : levelsFor(provider, model, resolved.providerType, true);
|
|
1935
|
+
const raiseEffort = !escalate && !effortEscalated && depth === 0 && !subagentId && effortLevel !== undefined && result.status === 'exhausted'
|
|
1936
|
+
&& EFFORT_ESCALATION_REASONS.has(result.reason ?? '') && effortLevels.indexOf(effortLevel) < effortLevels.length - 1 && !context.signal.aborted
|
|
1937
|
+
&& (options.budget === undefined || options.budget.maxToolCalls === undefined || options.budget.toolCalls < options.budget.maxToolCalls);
|
|
1938
|
+
if (raiseEffort) {
|
|
1939
|
+
effortEscalated = true;
|
|
1940
|
+
if (attempt === attempts)
|
|
1941
|
+
attempts = attempt + 1;
|
|
1942
|
+
}
|
|
1943
|
+
if (!escalate && !raiseEffort && (result.status !== 'infrastructure_error' || result.providerRequestFailed || attempt === attempts))
|
|
1556
1944
|
break;
|
|
1557
1945
|
await emit('agent.retry', { attempt, reason: result.reason, ...(escalate ? { escalation: true, tier: routedTier } : {}) });
|
|
1558
1946
|
if (configured.retry?.fallback) {
|