@noetic-tools/core 5.14.1 → 5.15.1
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/builders/spawn-builder.d.ts +7 -0
- package/dist/builders/spawn-builder.js +2 -0
- package/dist/builders/workflow-hydrator.js +1 -0
- package/dist/harness/agent-harness.d.ts +2 -1
- package/dist/harness/agent-harness.js +32 -17
- package/dist/harness/deps/context.d.ts +1 -1
- package/dist/harness/deps/context.js +1 -1
- package/dist/harness/deps/runtime.d.ts +2 -1
- package/dist/harness/deps/runtime.js +1 -0
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/harness/model-call.d.ts +12 -12
- package/dist/harness/model-call.js +191 -116
- package/dist/harness/model-rounds.d.ts +1 -1
- package/dist/harness/model-rounds.js +1 -1
- package/dist/harness/steer-inbox.d.ts +51 -0
- package/dist/harness/steer-inbox.js +149 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/interpreter/action-deps.d.ts +2 -0
- package/dist/interpreter/action-deps.js +1 -0
- package/dist/interpreter/action-types.d.ts +1 -1
- package/dist/interpreter/execute-action.js +44 -1
- package/dist/runtime/durable/step-ledger.js +80 -15
- package/dist/runtime/message-queue.d.ts +15 -1
- package/dist/runtime/message-queue.js +54 -0
- package/dist/runtime/session-runner.d.ts +3 -0
- package/dist/runtime/session-runner.js +18 -29
- package/package.json +3 -3
- package/schema/noetic-workflow.schema.json +7 -0
|
@@ -10,6 +10,12 @@ export interface SpawnOpts<TContext = ContextData, I = unknown, O = unknown> ext
|
|
|
10
10
|
child: Step<TContext, I, O>;
|
|
11
11
|
context?: ContextConfig | ContextLayer[];
|
|
12
12
|
timeout?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the child takes steers sent to the session while it runs.
|
|
15
|
+
* `'hold'` (default) keeps them queued until control returns to the parent;
|
|
16
|
+
* `'forward'` lets the child's model calls apply them.
|
|
17
|
+
*/
|
|
18
|
+
steers?: 'forward' | 'hold';
|
|
13
19
|
/**
|
|
14
20
|
* Optional per-step subprocess adapter override. The interpreter routes
|
|
15
21
|
* this spawn through the given adapter instead of the harness default.
|
|
@@ -25,6 +31,7 @@ export interface SpawnOpts<TContext = ContextData, I = unknown, O = unknown> ext
|
|
|
25
31
|
* @param opts.child - Step to execute in the isolated child context.
|
|
26
32
|
* @param opts.context - Optional context config or layers for the child context (replaces parent layers entirely).
|
|
27
33
|
* @param opts.timeout - Optional execution timeout in ms; the child is aborted if it exceeds this.
|
|
34
|
+
* @param opts.steers - `'forward'` lets the child apply steers sent while it runs; default `'hold'`.
|
|
28
35
|
* @param opts.subprocess - Optional per-step subprocess adapter override.
|
|
29
36
|
* @returns A `StepSpawn` step. The spawn step and its `child` step are both
|
|
30
37
|
* auto-registered in the shared step registry so the subprocess adapter
|
|
@@ -10,6 +10,7 @@ import { getDefaultRegistrar } from '../types/step-registrar.js';
|
|
|
10
10
|
* @param opts.child - Step to execute in the isolated child context.
|
|
11
11
|
* @param opts.context - Optional context config or layers for the child context (replaces parent layers entirely).
|
|
12
12
|
* @param opts.timeout - Optional execution timeout in ms; the child is aborted if it exceeds this.
|
|
13
|
+
* @param opts.steers - `'forward'` lets the child apply steers sent while it runs; default `'hold'`.
|
|
13
14
|
* @param opts.subprocess - Optional per-step subprocess adapter override.
|
|
14
15
|
* @returns A `StepSpawn` step. The spawn step and its `child` step are both
|
|
15
16
|
* auto-registered in the shared step registry so the subprocess adapter
|
|
@@ -38,6 +39,7 @@ export function spawn(opts) {
|
|
|
38
39
|
child: opts.child,
|
|
39
40
|
context: opts.context,
|
|
40
41
|
timeout: opts.timeout,
|
|
42
|
+
steers: opts.steers,
|
|
41
43
|
subprocess: opts.subprocess,
|
|
42
44
|
durable: opts.durable,
|
|
43
45
|
replayKey: opts.replayKey,
|
|
@@ -4,7 +4,7 @@ import type { LayerStateStore, RecallCache } from './deps/context.js';
|
|
|
4
4
|
import type { DetachedSpawnOverrides } from './deps/interpreter.js';
|
|
5
5
|
import type { CheckpointStore, EventBroadcaster, RestoreCheckpointOptions, StepLedgerRetention, StepLedgerStore } from './deps/runtime.js';
|
|
6
6
|
import { ChannelStore } from './deps/runtime.js';
|
|
7
|
-
import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, LLMResponse, LlmProviderConfig, ProjectionPolicy, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, Step, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
|
|
7
|
+
import type { AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, LLMResponse, LlmProviderConfig, OnSteerParams, ProjectionPolicy, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StorageAdapter, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
|
|
8
8
|
export { createStreamIdleWatchdog } from './model-call.js';
|
|
9
9
|
/**
|
|
10
10
|
* Storage-scoped environment configuration for `AgentHarness`.
|
|
@@ -502,6 +502,7 @@ export declare class AgentHarness<TParams extends Record<string, unknown> = Reco
|
|
|
502
502
|
setLayerState<T>(executionId: string, layerId: string, state: T): void;
|
|
503
503
|
beforeToolCall(layers: ContextLayer[], toolName: string, toolArgs: unknown, ctx: Context, callId?: string): Promise<SteeringDecision>;
|
|
504
504
|
afterModelCall(layers: ContextLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
|
|
505
|
+
onSteer(layers: ContextLayer[], params: Pick<OnSteerParams, 'steer' | 'point' | 'action' | 'pendingCalls'>, ctx: Context): Promise<SteerVerdict>;
|
|
505
506
|
/** Record `hook` as running on `ctx` until it settles (see `runningHooks`). */
|
|
506
507
|
private trackHook;
|
|
507
508
|
projectHistory(layers: ContextLayer[], items: ReadonlyArray<Item>, ctx: Context): Promise<ReadonlyArray<Item>>;
|
|
@@ -5,9 +5,9 @@ import { NoopExporter } from '../observability/trace-exporter.js';
|
|
|
5
5
|
import { AcpSessionStore } from '../runtime/acp-session-store.js';
|
|
6
6
|
import { callDecide } from './decide-call.js';
|
|
7
7
|
import { createInMemoryFsAdapter, createInMemoryShellAdapter, createInMemorySubprocessAdapter, OpenRouter, OpenRouterSdk, } from './deps/adapters.js';
|
|
8
|
-
import { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, initLayers, notifyDecision, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from './deps/context.js';
|
|
8
|
+
import { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from './deps/context.js';
|
|
9
9
|
import { collectAllTools, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, someStep, } from './deps/interpreter.js';
|
|
10
|
-
import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createCheckpointStore, createInMemoryStorage, createSessionStore, createStepLedgerStore, filterReasoningStream, filterTextStream, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, warnToConsole, } from './deps/runtime.js';
|
|
10
|
+
import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createCheckpointStore, createInMemoryStorage, createSessionStore, createStepLedgerStore, filterReasoningStream, filterTextStream, INTERRUPT_REASON, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, warnToConsole, } from './deps/runtime.js';
|
|
11
11
|
import { SteeringAction } from './deps/types.js';
|
|
12
12
|
import { AgentHarnessModelCaller, noLlmProviderError } from './model-call.js';
|
|
13
13
|
import { ThreadRecord } from './thread-record.js';
|
|
@@ -414,10 +414,10 @@ export class AgentHarness {
|
|
|
414
414
|
if (deliveryMode === 'interrupt' && session.runner.getStatus().kind === 'generating') {
|
|
415
415
|
session.runner.queue.prepend(message);
|
|
416
416
|
// Abort kicks the runner via queue subscription after the in-flight turn settles.
|
|
417
|
-
void session.runner.abort(
|
|
417
|
+
void session.runner.abort(INTERRUPT_REASON);
|
|
418
418
|
return Promise.resolve();
|
|
419
419
|
}
|
|
420
|
-
session.runner.
|
|
420
|
+
session.runner.enqueue(message);
|
|
421
421
|
return Promise.resolve();
|
|
422
422
|
}
|
|
423
423
|
getAgentResponse(scope) {
|
|
@@ -491,6 +491,16 @@ export class AgentHarness {
|
|
|
491
491
|
return existing;
|
|
492
492
|
}
|
|
493
493
|
const record = this.threadRecord(threadId);
|
|
494
|
+
// Save a turn's items as the thread's history for the next turn.
|
|
495
|
+
const keepHistory = async (ctx) => {
|
|
496
|
+
if (record) {
|
|
497
|
+
await record.end(ctx, ctx.itemLog.items);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
session.accumulatedItems = [
|
|
501
|
+
...ctx.itemLog.items,
|
|
502
|
+
];
|
|
503
|
+
};
|
|
494
504
|
const session = {
|
|
495
505
|
accumulatedItems: [],
|
|
496
506
|
record,
|
|
@@ -525,10 +535,7 @@ export class AgentHarness {
|
|
|
525
535
|
extraContextLayers: perTurnOptions.extraContextLayers,
|
|
526
536
|
_broadcaster: session.runner.broadcaster,
|
|
527
537
|
});
|
|
528
|
-
|
|
529
|
-
ext._sessionQueue = session.runner.queue;
|
|
530
|
-
ext._sessionBetweenRounds = true;
|
|
531
|
-
ext._sessionRunnerAgentName = this.config.name;
|
|
538
|
+
frameworkCast(ctx)._sessionQueue = session.runner.queue;
|
|
532
539
|
if (this.agentGraph || this.harnessTools.length > 0) {
|
|
533
540
|
const stepTools = this.agentGraph ? collectAllTools(this.agentGraph) : [];
|
|
534
541
|
this.setUnifiedTools(ctx, [
|
|
@@ -558,15 +565,15 @@ export class AgentHarness {
|
|
|
558
565
|
once: true,
|
|
559
566
|
});
|
|
560
567
|
}
|
|
561
|
-
const result = await this.initAndRun(this.agentGraph, '', ctx)
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
const result = await this.initAndRun(this.agentGraph, '', ctx).catch(async (error) => {
|
|
569
|
+
// An interrupted turn restarts from what it finished, so the
|
|
570
|
+
// interrupting message lands after the work it interrupted.
|
|
571
|
+
if (ctx.abortReason === INTERRUPT_REASON) {
|
|
572
|
+
await keepHistory(ctx);
|
|
573
|
+
}
|
|
574
|
+
throw error;
|
|
575
|
+
});
|
|
576
|
+
await keepHistory(ctx);
|
|
570
577
|
return result;
|
|
571
578
|
},
|
|
572
579
|
// Stored totals are the session's usage; the runner only mirrors them.
|
|
@@ -1261,6 +1268,14 @@ export class AgentHarness {
|
|
|
1261
1268
|
store: this.layerStateStore,
|
|
1262
1269
|
}));
|
|
1263
1270
|
}
|
|
1271
|
+
async onSteer(layers, params, ctx) {
|
|
1272
|
+
return this.trackHook(ctx, onSteerLayers({
|
|
1273
|
+
layers,
|
|
1274
|
+
...params,
|
|
1275
|
+
ctx: this.toExecCtx(ctx),
|
|
1276
|
+
store: this.layerStateStore,
|
|
1277
|
+
}));
|
|
1278
|
+
}
|
|
1264
1279
|
/** Record `hook` as running on `ctx` until it settles (see `runningHooks`). */
|
|
1265
1280
|
trackHook(ctx, hook) {
|
|
1266
1281
|
let running = this.runningHooks.get(ctx);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { LayerStateStore, RecallCache } from '@noetic-tools/context';
|
|
2
|
-
export { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, exportSpans, initLayers, notifyDecision, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from '@noetic-tools/context';
|
|
2
|
+
export { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, exportSpans, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from '@noetic-tools/context';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, exportSpans, initLayers, notifyDecision, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from '@noetic-tools/context';
|
|
1
|
+
export { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, exportSpans, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from '@noetic-tools/context';
|
|
@@ -12,7 +12,8 @@ export type { StepLedgerEntry, StepLedgerRetention, StepLedgerStore, } from '../
|
|
|
12
12
|
export { createStepLedgerStore, resolveStepLedgerRetention, StepLedger, } from '../../runtime/durable/step-ledger.js';
|
|
13
13
|
export type { EventBroadcaster } from '../../runtime/event-broadcaster.js';
|
|
14
14
|
export { createInMemoryStorage } from '../../runtime/in-memory-storage.js';
|
|
15
|
-
export type { QueuedMessage } from '../../runtime/message-queue.js';
|
|
15
|
+
export type { QueuedMessage, SessionCtxExtension } from '../../runtime/message-queue.js';
|
|
16
|
+
export { INTERRUPT_REASON } from '../../runtime/message-queue.js';
|
|
16
17
|
export type { TurnUsage } from '../../runtime/session-runner.js';
|
|
17
18
|
export { SessionRunner } from '../../runtime/session-runner.js';
|
|
18
19
|
export { buildItemStream, filterReasoningStream, filterTextStream, } from '../../runtime/session-streams.js';
|
|
@@ -6,5 +6,6 @@ export { captureCheckpoint, clearCheckpoint, restoreFromCheckpoint, } from '../.
|
|
|
6
6
|
export { createSessionStore } from '../../runtime/durable/session-store.js';
|
|
7
7
|
export { createStepLedgerStore, resolveStepLedgerRetention, StepLedger, } from '../../runtime/durable/step-ledger.js';
|
|
8
8
|
export { createInMemoryStorage } from '../../runtime/in-memory-storage.js';
|
|
9
|
+
export { INTERRUPT_REASON } from '../../runtime/message-queue.js';
|
|
9
10
|
export { SessionRunner } from '../../runtime/session-runner.js';
|
|
10
11
|
export { buildItemStream, filterReasoningStream, filterTextStream, } from '../../runtime/session-streams.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, ExecutionContext, ProjectionPolicy, StorageAdapter, } from '@noetic-tools/context';
|
|
2
|
-
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, } from '@noetic-tools/types';
|
|
2
|
+
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, Channel, ChannelHandle, Context, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeliveryMode, DetachedHandle, ExecuteInput, ExecuteOptions, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, RecallLayerOutput, RecallOptions, SessionScope, SessionUsage, ShellAdapter, Span, SteeringDecision, SteerVerdict, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, } from '@noetic-tools/types';
|
|
3
3
|
export { SteeringAction } from '@noetic-tools/types';
|
|
4
4
|
export type { ZodType } from 'zod';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AgentHarnessContract, CallModelRequest, ItemSchemaRegistry, LLMResponse, TraceExporter } from '@noetic-tools/types';
|
|
2
2
|
import { NoeticConfigError } from '@noetic-tools/types';
|
|
3
3
|
import type { OpenRouter } from '@openrouter/agent';
|
|
4
|
-
import type { MessageQueue } from '../runtime/message-queue.js';
|
|
5
4
|
interface StreamIdleWatchdog {
|
|
6
5
|
/** Bump the deadline because a stream event just arrived. */
|
|
7
6
|
reset: () => void;
|
|
@@ -17,13 +16,6 @@ export declare function noLlmProviderError(): NoeticConfigError;
|
|
|
17
16
|
* `.stop()` in a `finally`. `onTimeout` runs before the abort so observers can
|
|
18
17
|
* emit a framework event with the original cause. Exported only for unit tests. */
|
|
19
18
|
export declare function createStreamIdleWatchdog(timeoutMs: number, controller: AbortController, onTimeout?: () => void): StreamIdleWatchdog;
|
|
20
|
-
/** @internal Context carries the session queue reference so callModel can
|
|
21
|
-
* inject between-rounds messages into the current tool-round loop. */
|
|
22
|
-
export interface SessionCtxExtension {
|
|
23
|
-
_sessionQueue?: MessageQueue;
|
|
24
|
-
_sessionBetweenRounds?: boolean;
|
|
25
|
-
_sessionRunnerAgentName?: string;
|
|
26
|
-
}
|
|
27
19
|
interface AgentHarnessModelCallerOpts {
|
|
28
20
|
agentName: string;
|
|
29
21
|
itemSchemas: ItemSchemaRegistry;
|
|
@@ -48,14 +40,22 @@ export declare class AgentHarnessModelCaller {
|
|
|
48
40
|
private requireModelClient;
|
|
49
41
|
callModel(request: CallModelRequest): Promise<LLMResponse>;
|
|
50
42
|
private runModelLoop;
|
|
51
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Offer queued steers before a model call and add the applied ones to the
|
|
45
|
+
* conversation. They join `allItems` rather than the log so the log keeps
|
|
46
|
+
* them in the order the model saw them.
|
|
47
|
+
*/
|
|
48
|
+
private applySteers;
|
|
49
|
+
private parseRoundItems;
|
|
50
|
+
/** Run the round's function calls. Returns `false` when there were none to run. */
|
|
51
|
+
private runToolRound;
|
|
52
52
|
private handleModelRecovery;
|
|
53
53
|
private handleEmptyOutputRecovery;
|
|
54
54
|
private executeToolRound;
|
|
55
55
|
private executeFunctionCall;
|
|
56
|
-
private
|
|
56
|
+
private recordSkippedToolCall;
|
|
57
|
+
/** Answer a call that never ran, so every call in the history has an output. */
|
|
58
|
+
private recordUnrunToolCall;
|
|
57
59
|
private handleToolRoundLimit;
|
|
58
|
-
/** @internal Drain only messages tagged `between-rounds` from the queue. */
|
|
59
|
-
private drainBetweenRoundsMessages;
|
|
60
60
|
}
|
|
61
61
|
export {};
|