@tangle-network/agent-runtime 0.36.0 → 0.38.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/dist/agent.d.ts +3 -3
- package/dist/analyst-loop.d.ts +2 -2
- package/dist/analyst-loop.js +3 -257
- package/dist/analyst-loop.js.map +1 -1
- package/dist/{chunk-NYGEI3NV.js → chunk-M65QJD35.js} +5 -211
- package/dist/chunk-M65QJD35.js.map +1 -0
- package/dist/{chunk-HSX6PFZR.js → chunk-V6GURW4W.js} +209 -1
- package/dist/chunk-V6GURW4W.js.map +1 -0
- package/dist/chunk-VOX6Z3II.js +90 -0
- package/dist/chunk-VOX6Z3II.js.map +1 -0
- package/dist/chunk-XBUG326M.js +261 -0
- package/dist/chunk-XBUG326M.js.map +1 -0
- package/dist/{chunk-7ZECSZ3C.js → chunk-Z523NPJK.js} +59 -2
- package/dist/chunk-Z523NPJK.js.map +1 -0
- package/dist/dynamic-DeOPeeAw.d.ts +106 -0
- package/dist/{improvement-adapter-CaZxFxTd.d.ts → improvement-adapter-BC4HhuAR.d.ts} +1 -1
- package/dist/improvement.d.ts +6 -130
- package/dist/improvement.js +4 -85
- package/dist/improvement.js.map +1 -1
- package/dist/index.d.ts +148 -3
- package/dist/index.js +109 -2
- package/dist/index.js.map +1 -1
- package/dist/loops.d.ts +5 -107
- package/dist/mcp/bin.js +4 -3
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +6 -440
- package/dist/mcp/index.js +7 -62
- package/dist/mcp/index.js.map +1 -1
- package/dist/optimize-prompt-cmH9wZdH.d.ts +129 -0
- package/dist/otel-export-CNmeg_7B.d.ts +627 -0
- package/dist/profiles.d.ts +1 -2
- package/dist/{types-DrXVR2Fu.d.ts → types-CmkQl8qE.d.ts} +137 -3
- package/dist/{types-D_MXrmJP.d.ts → types-p8dWBIXL.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-7ZECSZ3C.js.map +0 -1
- package/dist/chunk-HSX6PFZR.js.map +0 -1
- package/dist/chunk-NYGEI3NV.js.map +0 -1
- package/dist/otel-export-xgf4J6bo.d.ts +0 -191
- package/dist/runtime-run-B8VIiOhI.d.ts +0 -137
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,16 @@ import { AgentEvalError, KnowledgeReadinessReport, RunRecord, ControlEvalResult,
|
|
|
2
2
|
export { AgentEvalError, AgentEvalErrorCode, ConfigError, ControlBudget, ControlDecision, ControlEvalResult, ControlRunResult, ControlStep, DataAcquisitionPlan, JudgeError, KnowledgeReadinessReport, KnowledgeRequirement, NotFoundError, RunRecord, ValidationError } from '@tangle-network/agent-eval';
|
|
3
3
|
import { a as AgentBackendInput, b as AgentExecutionBackend, O as OpenAIChatTool, c as OpenAIChatToolChoice, d as AgentBackendContext, R as RuntimeStreamEvent, K as KnowledgeReadinessDecision, e as RunAgentTaskOptions, f as AgentTaskRunResult, g as RunAgentTaskStreamOptions, h as AgentRuntimeEvent, i as AgentTaskStatus, j as RuntimeSessionStore, k as RuntimeSession } from './types-CsCCryln.js';
|
|
4
4
|
export { l as AgentAdapter, m as AgentKnowledgeProvider, n as AgentRuntimeEventSink, o as AgentTaskContext, A as AgentTaskSpec, B as BackendErrorDetail } from './types-CsCCryln.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { Scenario } from '@tangle-network/agent-eval/campaign';
|
|
6
|
+
import { R as RunAnalystLoopOpts, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
|
|
7
|
+
import { O as OptimizePromptOptions, b as OptimizePromptResult } from './optimize-prompt-cmH9wZdH.js';
|
|
8
|
+
import { T as TopologyPlanner, D as DynamicDecision } from './dynamic-DeOPeeAw.js';
|
|
9
|
+
import { L as LoopSandboxClient, O as OutputAdapter, V as Validator, A as AgentRunSpec, b as LoopResult } from './types-CmkQl8qE.js';
|
|
10
|
+
export { R as RuntimeRunHandle, p as RuntimeRunPersistenceAdapter, q as RuntimeRunRow, s as startRuntimeRun } from './types-CmkQl8qE.js';
|
|
11
|
+
import { d as DelegateCodeArgs, t as CoderReviewer, u as CoderWinnerSelection, A as FactCandidate, w as CreateKbGateOptions } from './otel-export-CNmeg_7B.js';
|
|
12
|
+
export { U as EvalRunEvent, V as EvalRunGeneration, W as EvalRunsExportConfig, X as EvalRunsExportResult, Y as INTELLIGENCE_WIRE_VERSION, Z as OtelAttribute, _ as OtelExportConfig, O as OtelExporter, $ as OtelSpan, a0 as buildLoopOtelSpans, a1 as createOtelExporter, a2 as exportEvalRuns, a3 as loopEventToOtelSpan, Q as mcpToolsForRuntimeMcp, T as mcpToolsForRuntimeMcpSubset } from './otel-export-CNmeg_7B.js';
|
|
13
|
+
import { CoderOutput } from './profiles.js';
|
|
14
|
+
import '@tangle-network/sandbox';
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* @stable
|
|
@@ -1007,6 +1015,143 @@ declare class PlannerError extends AgentEvalError {
|
|
|
1007
1015
|
});
|
|
1008
1016
|
}
|
|
1009
1017
|
|
|
1018
|
+
/**
|
|
1019
|
+
* @experimental
|
|
1020
|
+
*
|
|
1021
|
+
* `runDelegatedLoop` — the configured delegated loop-runner.
|
|
1022
|
+
*
|
|
1023
|
+
* One typed entrypoint a worker agent (or a scheduled routine) calls to run a
|
|
1024
|
+
* disciplined loop in a chosen MODE, over agent-runtime's hardened engines:
|
|
1025
|
+
*
|
|
1026
|
+
* code → build-in-a-loop via the coder delegate (no-op + secret floor,
|
|
1027
|
+
* optional reviewer gate, winner-selection)
|
|
1028
|
+
* review → code mode with a REQUIRED reviewer (the gate is the point)
|
|
1029
|
+
* research → research-in-a-loop with valid-only KB growth (createKbGate)
|
|
1030
|
+
* audit → analyze trace/run data → findings (runAnalystLoop, caller-wired)
|
|
1031
|
+
* self-improve → identity-gated prompt optimization (optimizePrompt, caller-wired)
|
|
1032
|
+
* dynamic → agent-authored topology (runLoop + createDynamicDriver)
|
|
1033
|
+
*
|
|
1034
|
+
* It is intentionally a thin façade: the value is that EVERY product reuses the
|
|
1035
|
+
* one hardened engine instead of forking delegation logic. The dispatcher owns
|
|
1036
|
+
* mode routing, timing, fail-loud on an unregistered mode, and a uniform result
|
|
1037
|
+
* shape; each mode's engine is a pre-configured runner in the registry (build it
|
|
1038
|
+
* with the factories below, or inject your own / a stub).
|
|
1039
|
+
*/
|
|
1040
|
+
|
|
1041
|
+
/** @experimental */
|
|
1042
|
+
type DelegatedLoopMode = 'code' | 'review' | 'research' | 'audit' | 'self-improve' | 'dynamic';
|
|
1043
|
+
/** @experimental A pre-configured loop for one mode. Returns the mode's raw
|
|
1044
|
+
* output; the dispatcher wraps it in a {@link DelegatedLoopResult}. */
|
|
1045
|
+
type DelegatedLoopRunner<T = unknown> = (signal: AbortSignal) => Promise<T>;
|
|
1046
|
+
/** @experimental Mode → configured runner. Partial: only register the modes a
|
|
1047
|
+
* given product/routine actually uses. */
|
|
1048
|
+
type DelegatedLoopRegistry = Partial<Record<DelegatedLoopMode, DelegatedLoopRunner>>;
|
|
1049
|
+
/** @experimental Uniform result — never throws from a registered runner; a
|
|
1050
|
+
* thrown engine becomes `{ ok: false, error }` so a routine can record + move on. */
|
|
1051
|
+
interface DelegatedLoopResult<T = unknown> {
|
|
1052
|
+
mode: DelegatedLoopMode;
|
|
1053
|
+
ok: boolean;
|
|
1054
|
+
output?: T;
|
|
1055
|
+
error?: string;
|
|
1056
|
+
durationMs: number;
|
|
1057
|
+
}
|
|
1058
|
+
/** @experimental */
|
|
1059
|
+
interface RunDelegatedLoopOptions {
|
|
1060
|
+
signal?: AbortSignal;
|
|
1061
|
+
/** Clock override for deterministic tests. */
|
|
1062
|
+
now?: () => number;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* @experimental
|
|
1066
|
+
*
|
|
1067
|
+
* Dispatch a configured loop by mode. Fails loud (throws `ConfigError`) when no
|
|
1068
|
+
* runner is registered for the mode — a routine pointed at an unwired mode is a
|
|
1069
|
+
* config bug, not a silent no-op. A runner that throws is captured as
|
|
1070
|
+
* `{ ok: false }` so unattended runs record the failure rather than crash.
|
|
1071
|
+
*/
|
|
1072
|
+
declare function runDelegatedLoop<T = unknown>(mode: DelegatedLoopMode, registry: DelegatedLoopRegistry, options?: RunDelegatedLoopOptions): Promise<DelegatedLoopResult<T>>;
|
|
1073
|
+
/** @experimental Options for the default `code`/`review` runner. */
|
|
1074
|
+
interface CoderLoopRunnerOptions {
|
|
1075
|
+
sandboxClient: LoopSandboxClient;
|
|
1076
|
+
/** What to build — the delegate args (goal, repoRoot, variants, config, …). */
|
|
1077
|
+
args: DelegateCodeArgs;
|
|
1078
|
+
/** Adversarial reviewer. REQUIRED for `review` mode (see `reviewLoopRunner`). */
|
|
1079
|
+
reviewer?: CoderReviewer;
|
|
1080
|
+
/** Winner-selection strategy. Default `highest-score`. */
|
|
1081
|
+
winnerSelection?: CoderWinnerSelection;
|
|
1082
|
+
/** Harnesses for `variants > 1` fanout. */
|
|
1083
|
+
fanoutHarnesses?: string[];
|
|
1084
|
+
}
|
|
1085
|
+
/** @experimental Build a `code`-mode runner over the hardened coder delegate. */
|
|
1086
|
+
declare function coderLoopRunner(options: CoderLoopRunnerOptions): DelegatedLoopRunner<CoderOutput>;
|
|
1087
|
+
/**
|
|
1088
|
+
* @experimental
|
|
1089
|
+
*
|
|
1090
|
+
* `review` mode = `code` with a REQUIRED reviewer. The gate is the whole point,
|
|
1091
|
+
* so the type forces a reviewer (a "review loop" with no reviewer is a code loop).
|
|
1092
|
+
*/
|
|
1093
|
+
declare function reviewLoopRunner(options: CoderLoopRunnerOptions & {
|
|
1094
|
+
reviewer: CoderReviewer;
|
|
1095
|
+
}): DelegatedLoopRunner<CoderOutput>;
|
|
1096
|
+
/** @experimental Options for the default `dynamic` runner. */
|
|
1097
|
+
interface DynamicLoopRunnerOptions<Task, Output> {
|
|
1098
|
+
sandboxClient: LoopSandboxClient;
|
|
1099
|
+
/** The agent-authored topology planner (e.g. `createSandboxPlanner(...)`). */
|
|
1100
|
+
planner: TopologyPlanner<Task, Output>;
|
|
1101
|
+
task: Task;
|
|
1102
|
+
output: OutputAdapter<Output>;
|
|
1103
|
+
validator?: Validator<Output>;
|
|
1104
|
+
/** Exactly one of `agentRun` / `agentRuns` (runLoop validates). */
|
|
1105
|
+
agentRun?: AgentRunSpec<Task>;
|
|
1106
|
+
agentRuns?: AgentRunSpec<Task>[];
|
|
1107
|
+
maxIterations?: number;
|
|
1108
|
+
maxFanout?: number;
|
|
1109
|
+
}
|
|
1110
|
+
/** @experimental `dynamic` mode — agent-authored topology over `runLoop`. */
|
|
1111
|
+
declare function dynamicLoopRunner<Task, Output>(o: DynamicLoopRunnerOptions<Task, Output>): DelegatedLoopRunner<LoopResult<Task, Output, DynamicDecision>>;
|
|
1112
|
+
/** @experimental A fact rejected at the KB gate — surfaced, never dropped. */
|
|
1113
|
+
interface VetoedFact {
|
|
1114
|
+
candidate: FactCandidate;
|
|
1115
|
+
vetoedBy?: string;
|
|
1116
|
+
reason?: string;
|
|
1117
|
+
}
|
|
1118
|
+
/** @experimental */
|
|
1119
|
+
interface ResearchLoopResult {
|
|
1120
|
+
/** Facts that passed the fail-closed gate — safe to write to the KB. */
|
|
1121
|
+
accepted: FactCandidate[];
|
|
1122
|
+
/** Facts the gate vetoed in the final round — escalate, do not silently drop. */
|
|
1123
|
+
vetoed: VetoedFact[];
|
|
1124
|
+
/** Research rounds actually run. */
|
|
1125
|
+
rounds: number;
|
|
1126
|
+
}
|
|
1127
|
+
/** @experimental Options for the default `research` runner. */
|
|
1128
|
+
interface ResearchLoopRunnerOptions {
|
|
1129
|
+
/**
|
|
1130
|
+
* The research engine (the consumer's web/doc searcher + extractor). Called
|
|
1131
|
+
* each round with the prior round's vetoes so it can re-research the gaps.
|
|
1132
|
+
* Returns fact candidates carrying their grounding (`verbatimPassage` +
|
|
1133
|
+
* `sourceText`).
|
|
1134
|
+
*/
|
|
1135
|
+
research: (round: number, vetoed: VetoedFact[]) => Promise<FactCandidate[]>;
|
|
1136
|
+
/** Gate config (extra judges, self-artifact kinds, …). The floor is always on. */
|
|
1137
|
+
gate?: CreateKbGateOptions;
|
|
1138
|
+
/** Max research rounds (correct-on-veto remediation). Default 1. */
|
|
1139
|
+
maxRounds?: number;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* @experimental `research` mode — research-in-a-loop with valid-only KB growth.
|
|
1143
|
+
*
|
|
1144
|
+
* Each round: research → gate every candidate (fail-closed; passage MUST be in
|
|
1145
|
+
* the source) → accept the clean ones → re-research the vetoed ones next round,
|
|
1146
|
+
* up to `maxRounds`. Vetoed facts in the final round are RETURNED (escalate,
|
|
1147
|
+
* never silently dropped) so the caller audits vs retries.
|
|
1148
|
+
*/
|
|
1149
|
+
declare function researchLoopRunner(o: ResearchLoopRunnerOptions): DelegatedLoopRunner<ResearchLoopResult>;
|
|
1150
|
+
/** @experimental `self-improve` mode — identity-gated prompt optimization. */
|
|
1151
|
+
declare function selfImproveLoopRunner<TScenario extends Scenario, TArtifact>(options: OptimizePromptOptions<TScenario, TArtifact>): DelegatedLoopRunner<OptimizePromptResult<TArtifact, TScenario>>;
|
|
1152
|
+
/** @experimental `audit` mode — analyst loop over captured trace/run data. */
|
|
1153
|
+
declare function auditLoopRunner<TProposal = unknown, TEdit = unknown>(options: RunAnalystLoopOpts): DelegatedLoopRunner<RunAnalystLoopResult<TProposal, TEdit>>;
|
|
1154
|
+
|
|
1010
1155
|
/**
|
|
1011
1156
|
* @stable
|
|
1012
1157
|
*
|
|
@@ -1288,4 +1433,4 @@ declare function readinessServerSentEvent(report: KnowledgeReadinessReport, opti
|
|
|
1288
1433
|
/** @stable */
|
|
1289
1434
|
declare function runtimeStreamServerSentEvent(event: RuntimeStreamEvent, options?: RuntimeTelemetryOptions & ServerSentEventOptions): string;
|
|
1290
1435
|
|
|
1291
|
-
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult, AgentTaskStatus, type AuthSource, type BackendCallPolicy, BackendTransportError, type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type CircuitBreakerConfig, CircuitBreakerState, CircuitOpenError, type Conversation, type ConversationDriveState, type ConversationJournal, type ConversationJournalEntry, type ConversationParticipant, type ConversationPolicy, type ConversationResult, type ConversationStreamEvent, type ConversationTurn, type D1DatabaseLike, type D1StmtLike, DEFAULT_MAX_DEPTH, DEFAULT_ROUTER_BASE_URL, DeadlineExceededError, FORWARD_HEADERS, FileConversationJournal, type ForwardHeaderName, type HaltContext, type HaltPredicate, type HaltReason, type HaltSignal, InMemoryConversationJournal, InMemoryRuntimeSessionStore, type ModelInfo, OpenAIChatTool, OpenAIChatToolChoice, PlannerError, type PropagatedHeaders, type ResolvedChatModel, type RetryBackoff, type RetryableErrorPredicate, type RouterEnv, type RunChatTurnInput, type RunConversationOptions, type RuntimeEventCollector, RuntimeRunStateError, RuntimeSessionStore, RuntimeStreamEvent, type RuntimeStreamEventCollector, type RuntimeTelemetryOptions, type SanitizedKnowledgeReadinessReport, type SqlAdapter, SqlConversationJournal, type TurnOrder, applyRunRecordDefaults, buildForwardHeaders, cleanModelId, computeBackoff, createConversationBackend, createIterableBackend, createOpenAICompatibleBackend, createRuntimeEventCollector, createRuntimeStreamEventCollector, createSandboxPromptBackend, d1ToSqlAdapter, decideKnowledgeReadiness, defaultIsRetryable, defineConversation, deriveExecutionId, getModels, handleChatTurn, isDepthExceeded, makePerAttemptSignal, readDepth, readinessServerSentEvent, resolveChatModel, resolveRouterBaseUrl, runAgentTask, runAgentTaskStream, runConversation, runConversationStream, runtimeStreamServerSentEvent, sanitizeAgentRuntimeEvent, sanitizeKnowledgeReadinessReport, sanitizeRuntimeStreamEvent, sleep, slugifySpeaker, turnId, validateChatModelId };
|
|
1436
|
+
export { AgentBackendContext, AgentBackendInput, AgentExecutionBackend, AgentRuntimeEvent, AgentTaskRunResult, AgentTaskStatus, type AuthSource, type BackendCallPolicy, BackendTransportError, type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type CircuitBreakerConfig, CircuitBreakerState, CircuitOpenError, type CoderLoopRunnerOptions, type Conversation, type ConversationDriveState, type ConversationJournal, type ConversationJournalEntry, type ConversationParticipant, type ConversationPolicy, type ConversationResult, type ConversationStreamEvent, type ConversationTurn, type D1DatabaseLike, type D1StmtLike, DEFAULT_MAX_DEPTH, DEFAULT_ROUTER_BASE_URL, DeadlineExceededError, type DelegatedLoopMode, type DelegatedLoopRegistry, type DelegatedLoopResult, type DelegatedLoopRunner, type DynamicLoopRunnerOptions, FORWARD_HEADERS, FileConversationJournal, type ForwardHeaderName, type HaltContext, type HaltPredicate, type HaltReason, type HaltSignal, InMemoryConversationJournal, InMemoryRuntimeSessionStore, type ModelInfo, OpenAIChatTool, OpenAIChatToolChoice, PlannerError, type PropagatedHeaders, type ResearchLoopResult, type ResearchLoopRunnerOptions, type ResolvedChatModel, type RetryBackoff, type RetryableErrorPredicate, type RouterEnv, type RunChatTurnInput, type RunConversationOptions, type RunDelegatedLoopOptions, type RuntimeEventCollector, RuntimeRunStateError, RuntimeSessionStore, RuntimeStreamEvent, type RuntimeStreamEventCollector, type RuntimeTelemetryOptions, type SanitizedKnowledgeReadinessReport, type SqlAdapter, SqlConversationJournal, type TurnOrder, type VetoedFact, applyRunRecordDefaults, auditLoopRunner, buildForwardHeaders, cleanModelId, coderLoopRunner, computeBackoff, createConversationBackend, createIterableBackend, createOpenAICompatibleBackend, createRuntimeEventCollector, createRuntimeStreamEventCollector, createSandboxPromptBackend, d1ToSqlAdapter, decideKnowledgeReadiness, defaultIsRetryable, defineConversation, deriveExecutionId, dynamicLoopRunner, getModels, handleChatTurn, isDepthExceeded, makePerAttemptSignal, readDepth, readinessServerSentEvent, researchLoopRunner, resolveChatModel, resolveRouterBaseUrl, reviewLoopRunner, runAgentTask, runAgentTaskStream, runConversation, runConversationStream, runDelegatedLoop, runtimeStreamServerSentEvent, sanitizeAgentRuntimeEvent, sanitizeKnowledgeReadinessReport, sanitizeRuntimeStreamEvent, selfImproveLoopRunner, sleep, slugifySpeaker, turnId, validateChatModelId };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runAnalystLoop
|
|
3
|
+
} from "./chunk-XBUG326M.js";
|
|
4
|
+
import {
|
|
5
|
+
optimizePrompt
|
|
6
|
+
} from "./chunk-VOX6Z3II.js";
|
|
1
7
|
import {
|
|
2
8
|
INTELLIGENCE_WIRE_VERSION,
|
|
3
9
|
buildLoopOtelSpans,
|
|
10
|
+
createKbGate,
|
|
4
11
|
createOtelExporter,
|
|
5
12
|
exportEvalRuns,
|
|
6
13
|
loopEventToOtelSpan,
|
|
7
14
|
mcpToolsForRuntimeMcp,
|
|
8
15
|
mcpToolsForRuntimeMcpSubset
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import
|
|
16
|
+
} from "./chunk-Z523NPJK.js";
|
|
17
|
+
import {
|
|
18
|
+
createDefaultCoderDelegate
|
|
19
|
+
} from "./chunk-V6GURW4W.js";
|
|
20
|
+
import {
|
|
21
|
+
createDynamicDriver,
|
|
22
|
+
runLoop
|
|
23
|
+
} from "./chunk-7JBDJQLO.js";
|
|
24
|
+
import "./chunk-3HMHSN22.js";
|
|
25
|
+
import "./chunk-PY6NMZYX.js";
|
|
11
26
|
import {
|
|
12
27
|
AgentEvalError,
|
|
13
28
|
BackendTransportError,
|
|
@@ -1724,6 +1739,91 @@ function deriveExecutionId(input) {
|
|
|
1724
1739
|
return `${input.projectId}:${input.sessionId}:${input.turnIndex}`;
|
|
1725
1740
|
}
|
|
1726
1741
|
|
|
1742
|
+
// src/loop-runner.ts
|
|
1743
|
+
async function runDelegatedLoop(mode, registry, options = {}) {
|
|
1744
|
+
const runner = registry[mode];
|
|
1745
|
+
if (!runner) {
|
|
1746
|
+
throw new ConfigError(
|
|
1747
|
+
`runDelegatedLoop: no runner registered for mode '${mode}' (registered: ${Object.keys(registry).join(", ") || "none"})`
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
const now = options.now ?? Date.now;
|
|
1751
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
1752
|
+
const start = now();
|
|
1753
|
+
try {
|
|
1754
|
+
const output = await runner(signal);
|
|
1755
|
+
return { mode, ok: true, output, durationMs: now() - start };
|
|
1756
|
+
} catch (err) {
|
|
1757
|
+
return {
|
|
1758
|
+
mode,
|
|
1759
|
+
ok: false,
|
|
1760
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1761
|
+
durationMs: now() - start
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
function coderLoopRunner(options) {
|
|
1766
|
+
const delegate = createDefaultCoderDelegate({
|
|
1767
|
+
sandboxClient: options.sandboxClient,
|
|
1768
|
+
...options.reviewer ? { reviewer: options.reviewer } : {},
|
|
1769
|
+
...options.winnerSelection ? { winnerSelection: options.winnerSelection } : {},
|
|
1770
|
+
...options.fanoutHarnesses ? { fanoutHarnesses: options.fanoutHarnesses } : {}
|
|
1771
|
+
});
|
|
1772
|
+
return async (signal) => {
|
|
1773
|
+
const ctx = { signal, report: () => {
|
|
1774
|
+
} };
|
|
1775
|
+
return delegate(options.args, ctx);
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
function reviewLoopRunner(options) {
|
|
1779
|
+
return coderLoopRunner(options);
|
|
1780
|
+
}
|
|
1781
|
+
function dynamicLoopRunner(o) {
|
|
1782
|
+
return async (signal) => runLoop({
|
|
1783
|
+
driver: createDynamicDriver({
|
|
1784
|
+
planner: o.planner,
|
|
1785
|
+
...o.maxIterations !== void 0 ? { maxIterations: o.maxIterations } : {},
|
|
1786
|
+
...o.maxFanout !== void 0 ? { maxFanout: o.maxFanout } : {}
|
|
1787
|
+
}),
|
|
1788
|
+
...o.agentRun ? { agentRun: o.agentRun } : {},
|
|
1789
|
+
...o.agentRuns ? { agentRuns: o.agentRuns } : {},
|
|
1790
|
+
output: o.output,
|
|
1791
|
+
...o.validator ? { validator: o.validator } : {},
|
|
1792
|
+
task: o.task,
|
|
1793
|
+
ctx: { sandboxClient: o.sandboxClient, signal },
|
|
1794
|
+
...o.maxIterations !== void 0 ? { maxIterations: o.maxIterations } : {}
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
function researchLoopRunner(o) {
|
|
1798
|
+
const gate = createKbGate(o.gate);
|
|
1799
|
+
const maxRounds = Math.max(1, Math.trunc(o.maxRounds ?? 1));
|
|
1800
|
+
return async (signal) => {
|
|
1801
|
+
const accepted = [];
|
|
1802
|
+
let vetoed = [];
|
|
1803
|
+
let rounds = 0;
|
|
1804
|
+
for (let round = 0; round < maxRounds; round += 1) {
|
|
1805
|
+
if (signal.aborted) break;
|
|
1806
|
+
rounds += 1;
|
|
1807
|
+
const candidates = await o.research(round, vetoed);
|
|
1808
|
+
if (candidates.length === 0) break;
|
|
1809
|
+
vetoed = [];
|
|
1810
|
+
for (const c of candidates) {
|
|
1811
|
+
const v = await gate(c);
|
|
1812
|
+
if (v.accepted) accepted.push(c);
|
|
1813
|
+
else vetoed.push({ candidate: c, vetoedBy: v.vetoedBy, reason: v.reason });
|
|
1814
|
+
}
|
|
1815
|
+
if (vetoed.length === 0) break;
|
|
1816
|
+
}
|
|
1817
|
+
return { accepted, vetoed, rounds };
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
function selfImproveLoopRunner(options) {
|
|
1821
|
+
return async () => optimizePrompt(options);
|
|
1822
|
+
}
|
|
1823
|
+
function auditLoopRunner(options) {
|
|
1824
|
+
return async () => runAnalystLoop(options);
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1727
1827
|
// src/model-resolution.ts
|
|
1728
1828
|
var DEFAULT_ROUTER_BASE_URL = "https://router.tangle.tools";
|
|
1729
1829
|
function resolveRouterBaseUrl(env = {}) {
|
|
@@ -2729,9 +2829,11 @@ export {
|
|
|
2729
2829
|
SqlConversationJournal,
|
|
2730
2830
|
ValidationError,
|
|
2731
2831
|
applyRunRecordDefaults,
|
|
2832
|
+
auditLoopRunner,
|
|
2732
2833
|
buildForwardHeaders,
|
|
2733
2834
|
buildLoopOtelSpans,
|
|
2734
2835
|
cleanModelId,
|
|
2836
|
+
coderLoopRunner,
|
|
2735
2837
|
computeBackoff,
|
|
2736
2838
|
createConversationBackend,
|
|
2737
2839
|
createIterableBackend,
|
|
@@ -2745,6 +2847,7 @@ export {
|
|
|
2745
2847
|
defaultIsRetryable,
|
|
2746
2848
|
defineConversation,
|
|
2747
2849
|
deriveExecutionId,
|
|
2850
|
+
dynamicLoopRunner,
|
|
2748
2851
|
exportEvalRuns,
|
|
2749
2852
|
getModels,
|
|
2750
2853
|
handleChatTurn,
|
|
@@ -2755,16 +2858,20 @@ export {
|
|
|
2755
2858
|
mcpToolsForRuntimeMcpSubset,
|
|
2756
2859
|
readDepth,
|
|
2757
2860
|
readinessServerSentEvent,
|
|
2861
|
+
researchLoopRunner,
|
|
2758
2862
|
resolveChatModel,
|
|
2759
2863
|
resolveRouterBaseUrl,
|
|
2864
|
+
reviewLoopRunner,
|
|
2760
2865
|
runAgentTask,
|
|
2761
2866
|
runAgentTaskStream,
|
|
2762
2867
|
runConversation,
|
|
2763
2868
|
runConversationStream,
|
|
2869
|
+
runDelegatedLoop,
|
|
2764
2870
|
runtimeStreamServerSentEvent,
|
|
2765
2871
|
sanitizeAgentRuntimeEvent,
|
|
2766
2872
|
sanitizeKnowledgeReadinessReport,
|
|
2767
2873
|
sanitizeRuntimeStreamEvent,
|
|
2874
|
+
selfImproveLoopRunner,
|
|
2768
2875
|
sleep2 as sleep,
|
|
2769
2876
|
slugifySpeaker,
|
|
2770
2877
|
startRuntimeRun,
|