@noetic-tools/core 5.9.0 → 5.11.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/adapters/in-memory-subprocess/manifest-persistence.js +5 -1
- package/dist/adapters/in-memory-subprocess/metadata.js +1 -0
- package/dist/adapters/in-memory-subprocess/types.d.ts +4 -0
- package/dist/adapters/in-memory-subprocess-adapter.js +2 -0
- package/dist/adapters/openrouter.d.ts +13 -3
- package/dist/adapters/openrouter.js +43 -12
- package/dist/builders/dynamic-workflow.js +2 -1
- package/dist/builders/provide-builder.d.ts +6 -5
- package/dist/builders/spawn-builder.d.ts +6 -2
- package/dist/builders/step-builders.d.ts +9 -2
- package/dist/builders/step-builders.js +30 -2
- package/dist/builders/workflow-hydrator.js +1 -0
- package/dist/harness/agent-harness.d.ts +7 -1
- package/dist/harness/agent-harness.js +1 -0
- package/dist/harness/deps/context.d.ts +1 -1
- package/dist/harness/deps/context.js +1 -1
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/harness/model-call.js +114 -18
- package/dist/index.d.ts +9 -5
- package/dist/index.js +1 -1
- package/dist/interpreter/action-deps.d.ts +1 -1
- package/dist/interpreter/action-deps.js +1 -1
- package/dist/interpreter/action-types.d.ts +1 -1
- package/dist/interpreter/child-span.d.ts +5 -4
- package/dist/interpreter/child-span.js +7 -5
- package/dist/interpreter/context-assembly.d.ts +5 -4
- package/dist/interpreter/context-assembly.js +18 -14
- package/dist/interpreter/execute-action.d.ts +25 -5
- package/dist/interpreter/execute-action.js +100 -18
- package/dist/interpreter/execute-control.js +7 -0
- package/dist/interpreter/execute-decide.js +2 -2
- package/dist/interpreter/execute.js +22 -8
- package/dist/interpreter/step-dispatcher.js +1 -0
- package/dist/observability/genai-attributes.d.ts +33 -3
- package/dist/observability/genai-attributes.js +34 -4
- package/dist/runtime/tool-approval.d.ts +25 -0
- package/dist/runtime/tool-approval.js +67 -0
- package/dist/unstable.d.ts +1 -1
- package/dist/util/detached-handle.d.ts +4 -10
- package/dist/util/detached-handle.js +14 -23
- package/package.json +3 -3
- package/schema/noetic-workflow.schema.json +25 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { frameworkCast, NoeticConfigError } from '@noetic-tools/types';
|
|
1
|
+
import { frameworkCast, NoeticConfigError, ToolChoiceMode } from '@noetic-tools/types';
|
|
2
2
|
import { serverTool } from '@openrouter/agent';
|
|
3
3
|
import { convertTools, executeToolCall, extractOutputItems, extractSystemInstruction, extractUsage, itemsToInput, resolveWireJsonSchema, sanitizeToolNameForWire, } from '../adapters/openrouter.js';
|
|
4
4
|
import { isFunctionCall } from '../interpreter/typeguards.js';
|
|
5
5
|
import { GenAI, NoeticAttr, ToolAttr } from '../observability/genai-attributes.js';
|
|
6
6
|
import { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
|
|
7
|
+
import { exportSpans } from './deps/context.js';
|
|
7
8
|
import { buildItemSchemaRegistry, createToolResultItem } from './model-schema.js';
|
|
8
9
|
const MAX_TOOL_ROUNDS = 32;
|
|
9
10
|
const MAX_RECOVERY_CONTINUATIONS = 3;
|
|
@@ -199,15 +200,18 @@ function prepareModelRequest(request, agentName) {
|
|
|
199
200
|
.filter(Boolean)
|
|
200
201
|
.join('\n\n') || undefined;
|
|
201
202
|
const broadcaster = getBroadcaster(request.ctx);
|
|
202
|
-
const
|
|
203
|
+
const allowedTools = filterAllowedTools(request) ?? [];
|
|
204
|
+
// Every request carries the full tool list, so the prompt-cache prefix is the
|
|
205
|
+
// same for every step in the tree; `toolChoice` does the narrowing. A call
|
|
206
|
+
// that may use no client tool sends none.
|
|
203
207
|
// Client (function) tools convert to SDK tool definitions; OpenRouter server
|
|
204
208
|
// tools (web_search/web_fetch) are wrapped via the SDK's `serverTool()` so
|
|
205
209
|
// its convertToolsToAPIFormat accepts them — a raw `{type}` entry crashes it.
|
|
206
210
|
// `parameters` keys stay camelCase: the SDK's outbound zod schema strips
|
|
207
211
|
// unknown keys, so snake_case would be silently dropped.
|
|
208
|
-
const clientSdkTools =
|
|
212
|
+
const clientSdkTools = request.tools && allowedTools.length > 0
|
|
209
213
|
? convertTools({
|
|
210
|
-
tools:
|
|
214
|
+
tools: request.tools,
|
|
211
215
|
})
|
|
212
216
|
: [];
|
|
213
217
|
const serverSdkTools = (request._serverTools ?? []).map((s) => serverTool(frameworkCast({
|
|
@@ -223,6 +227,13 @@ function prepareModelRequest(request, agentName) {
|
|
|
223
227
|
remaining,
|
|
224
228
|
broadcaster,
|
|
225
229
|
sdkTools: sdkTools.length > 0 ? sdkTools : undefined,
|
|
230
|
+
toolChoice: roundToolChoices({
|
|
231
|
+
request,
|
|
232
|
+
allowedTools,
|
|
233
|
+
sendsClientTools: clientSdkTools.length > 0,
|
|
234
|
+
sendsTools: sdkTools.length > 0,
|
|
235
|
+
}),
|
|
236
|
+
allowedTools,
|
|
226
237
|
emitIfAllowed(eventType, data) {
|
|
227
238
|
if (!shouldEmit(request.emit, eventType, data)) {
|
|
228
239
|
return;
|
|
@@ -236,6 +247,75 @@ function prepareModelRequest(request, agentName) {
|
|
|
236
247
|
},
|
|
237
248
|
};
|
|
238
249
|
}
|
|
250
|
+
function roundToolChoices(scope) {
|
|
251
|
+
const choice = scope.request.toolChoice ?? ToolChoiceMode.Auto;
|
|
252
|
+
return {
|
|
253
|
+
first: wireToolChoice(scope, choice),
|
|
254
|
+
rest: wireToolChoice(scope, choice === ToolChoiceMode.None ? choice : ToolChoiceMode.Auto),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Map a `toolChoice` onto the wire, inside the step's restriction.
|
|
259
|
+
* A restricted call narrows with an `allowed_tools` choice (plus the step's
|
|
260
|
+
* server tools) rather than by trimming `tools`, so the request keeps the
|
|
261
|
+
* shared cache prefix. `none` keeps the tools too, for the same reason. A call
|
|
262
|
+
* that sends no tools sends no choice.
|
|
263
|
+
*
|
|
264
|
+
* @throws NoeticConfigError `UNKNOWN_TOOL_CHOICE` when `{ tool }` names a tool
|
|
265
|
+
* this call cannot run.
|
|
266
|
+
*/
|
|
267
|
+
function wireToolChoice(scope, choice) {
|
|
268
|
+
const { request, allowedTools } = scope;
|
|
269
|
+
if (typeof choice === 'object') {
|
|
270
|
+
return forcedToolChoice(choice.tool, allowedTools);
|
|
271
|
+
}
|
|
272
|
+
if (!scope.sendsTools) {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
if (choice === ToolChoiceMode.None) {
|
|
276
|
+
return 'none';
|
|
277
|
+
}
|
|
278
|
+
if (request.allowedToolNames && scope.sendsClientTools) {
|
|
279
|
+
return allowedToolsChoice(request, allowedTools, choice);
|
|
280
|
+
}
|
|
281
|
+
return choice === ToolChoiceMode.Required ? 'required' : undefined;
|
|
282
|
+
}
|
|
283
|
+
/** Force one function tool. It must be one the call may run. */
|
|
284
|
+
function forcedToolChoice(name, allowedTools) {
|
|
285
|
+
const tool = allowedTools.find((candidate) => candidate.name === name);
|
|
286
|
+
if (!tool) {
|
|
287
|
+
const offered = allowedTools.map((t) => t.name).join(', ') || 'none';
|
|
288
|
+
throw new NoeticConfigError({
|
|
289
|
+
code: 'UNKNOWN_TOOL_CHOICE',
|
|
290
|
+
message: `toolChoice forces tool ${JSON.stringify(name)}, which this model call cannot run.`,
|
|
291
|
+
hint: `Force a tool the call offers (offered: ${offered}), or give '${name}' to the step or a context layer.`,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
type: 'function',
|
|
296
|
+
name: sanitizeToolNameForWire(tool.name),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/** Restrict the model to `allowedTools` (plus the step's server tools). */
|
|
300
|
+
function allowedToolsChoice(request, allowedTools, mode) {
|
|
301
|
+
return {
|
|
302
|
+
type: 'allowed_tools',
|
|
303
|
+
mode,
|
|
304
|
+
tools: [
|
|
305
|
+
...allowedTools.map((tool) => ({
|
|
306
|
+
type: 'function',
|
|
307
|
+
name: sanitizeToolNameForWire(tool.name),
|
|
308
|
+
})),
|
|
309
|
+
...(request._serverTools ?? []).map((spec) => ({
|
|
310
|
+
type: spec.type,
|
|
311
|
+
})),
|
|
312
|
+
],
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** Match a wire tool name against both the original and the sanitised name. */
|
|
316
|
+
function findTool(tools, wireName) {
|
|
317
|
+
return tools.find((tool) => tool.name === wireName || sanitizeToolNameForWire(tool.name) === wireName);
|
|
318
|
+
}
|
|
239
319
|
function filterAllowedTools(request) {
|
|
240
320
|
if (!request.tools) {
|
|
241
321
|
return undefined;
|
|
@@ -257,12 +337,16 @@ class CallSpanCollector {
|
|
|
257
337
|
exporter;
|
|
258
338
|
parent;
|
|
259
339
|
nodeId;
|
|
340
|
+
firstSpanAttributes;
|
|
260
341
|
spans = [];
|
|
261
|
-
constructor(harness, exporter, parent, nodeId
|
|
342
|
+
constructor(harness, exporter, parent, nodeId,
|
|
343
|
+
/** Stamped on the first model span only, then dropped. */
|
|
344
|
+
firstSpanAttributes) {
|
|
262
345
|
this.harness = harness;
|
|
263
346
|
this.exporter = exporter;
|
|
264
347
|
this.parent = parent;
|
|
265
348
|
this.nodeId = nodeId;
|
|
349
|
+
this.firstSpanAttributes = firstSpanAttributes;
|
|
266
350
|
}
|
|
267
351
|
/** Link a span back to its declared workflow node, when the call carries one. */
|
|
268
352
|
stampNode(span) {
|
|
@@ -276,6 +360,10 @@ class CallSpanCollector {
|
|
|
276
360
|
span.setAttribute(GenAI.SYSTEM, 'openrouter');
|
|
277
361
|
span.setAttribute(GenAI.REQUEST_MODEL, model);
|
|
278
362
|
this.stampNode(span);
|
|
363
|
+
for (const [key, value] of Object.entries(this.firstSpanAttributes ?? {})) {
|
|
364
|
+
span.setAttribute(key, value);
|
|
365
|
+
}
|
|
366
|
+
this.firstSpanAttributes = undefined;
|
|
279
367
|
this.spans.push(span);
|
|
280
368
|
return span;
|
|
281
369
|
}
|
|
@@ -295,10 +383,13 @@ class CallSpanCollector {
|
|
|
295
383
|
span.end();
|
|
296
384
|
}
|
|
297
385
|
/** Open and immediately close a tool-call span under the given model span. */
|
|
298
|
-
recordToolSpan(parent, toolName, needsApproval) {
|
|
386
|
+
recordToolSpan(parent, toolName, needsApproval, approval) {
|
|
299
387
|
const span = this.harness.createSpan('tool.call', parent);
|
|
300
388
|
span.setAttribute(ToolAttr.NAME, toolName);
|
|
301
389
|
span.setAttribute(ToolAttr.NEEDS_APPROVAL, needsApproval);
|
|
390
|
+
if (approval !== undefined) {
|
|
391
|
+
span.setAttribute(ToolAttr.APPROVAL, approval);
|
|
392
|
+
}
|
|
302
393
|
this.stampNode(span);
|
|
303
394
|
span.end();
|
|
304
395
|
this.spans.push(span);
|
|
@@ -308,7 +399,7 @@ class CallSpanCollector {
|
|
|
308
399
|
if (this.spans.length === 0) {
|
|
309
400
|
return;
|
|
310
401
|
}
|
|
311
|
-
await this.exporter
|
|
402
|
+
await exportSpans(this.exporter, this.spans);
|
|
312
403
|
}
|
|
313
404
|
}
|
|
314
405
|
export class AgentHarnessModelCaller {
|
|
@@ -317,7 +408,7 @@ export class AgentHarnessModelCaller {
|
|
|
317
408
|
this.opts = opts;
|
|
318
409
|
}
|
|
319
410
|
newSpanCollector(request) {
|
|
320
|
-
return new CallSpanCollector(this.opts.harness, this.opts.traceExporter, request.parentSpan ?? request.ctx?.span ?? null, request.nodeId);
|
|
411
|
+
return new CallSpanCollector(this.opts.harness, this.opts.traceExporter, request.parentSpan ?? request.ctx?.span ?? null, request.nodeId, request.spanAttributes);
|
|
321
412
|
}
|
|
322
413
|
/**
|
|
323
414
|
* Broadcast a framework-authored item so `getItemStream` carries it — tool
|
|
@@ -436,6 +527,7 @@ export class AgentHarnessModelCaller {
|
|
|
436
527
|
input: modelInput,
|
|
437
528
|
instructions: prepared.instructions,
|
|
438
529
|
tools: prepared.sdkTools,
|
|
530
|
+
toolChoice: round === 0 ? prepared.toolChoice.first : prepared.toolChoice.rest,
|
|
439
531
|
temperature: request.params?.temperature,
|
|
440
532
|
maxOutputTokens: request.params?.maxTokens,
|
|
441
533
|
topP: request.params?.topP,
|
|
@@ -541,6 +633,7 @@ export class AgentHarnessModelCaller {
|
|
|
541
633
|
await this.executeToolRound({
|
|
542
634
|
functionCalls,
|
|
543
635
|
request,
|
|
636
|
+
allowedTools: prepared.allowedTools,
|
|
544
637
|
allItems,
|
|
545
638
|
conversationInput,
|
|
546
639
|
round,
|
|
@@ -674,7 +767,7 @@ export class AgentHarnessModelCaller {
|
|
|
674
767
|
};
|
|
675
768
|
}
|
|
676
769
|
async executeToolRound(params) {
|
|
677
|
-
const { functionCalls, request, allItems, conversationInput, spans, modelSpan } = params;
|
|
770
|
+
const { functionCalls, request, allowedTools, allItems, conversationInput, spans, modelSpan } = params;
|
|
678
771
|
params.emitIfAllowed('tool_round_started', {
|
|
679
772
|
round: params.round,
|
|
680
773
|
toolCount: functionCalls.length,
|
|
@@ -692,15 +785,16 @@ export class AgentHarnessModelCaller {
|
|
|
692
785
|
if (request.signal?.aborted) {
|
|
693
786
|
break;
|
|
694
787
|
}
|
|
695
|
-
const toolForCall =
|
|
696
|
-
|
|
697
|
-
await this.executeFunctionCall({
|
|
788
|
+
const toolForCall = findTool(allowedTools, fc.name);
|
|
789
|
+
const approval = await this.executeFunctionCall({
|
|
698
790
|
fc,
|
|
699
791
|
request,
|
|
792
|
+
allowedTools,
|
|
700
793
|
allItems,
|
|
701
794
|
conversationInput,
|
|
702
795
|
emitIfAllowed: params.emitIfAllowed,
|
|
703
796
|
});
|
|
797
|
+
spans.recordToolSpan(modelSpan, fc.name, toolForCall?.needsApproval ?? false, approval);
|
|
704
798
|
}
|
|
705
799
|
params.emitIfAllowed('tool_round_completed', {
|
|
706
800
|
round: params.round,
|
|
@@ -708,7 +802,7 @@ export class AgentHarnessModelCaller {
|
|
|
708
802
|
});
|
|
709
803
|
}
|
|
710
804
|
async executeFunctionCall(params) {
|
|
711
|
-
const { fc, request, allItems, conversationInput } = params;
|
|
805
|
+
const { fc, request, allowedTools, allItems, conversationInput } = params;
|
|
712
806
|
params.emitIfAllowed('tool_call_started', {
|
|
713
807
|
name: fc.name,
|
|
714
808
|
callId: fc.callId,
|
|
@@ -721,20 +815,21 @@ export class AgentHarnessModelCaller {
|
|
|
721
815
|
this.recordMalformedToolCall({
|
|
722
816
|
fc,
|
|
723
817
|
request,
|
|
818
|
+
allowedTools,
|
|
724
819
|
allItems,
|
|
725
820
|
conversationInput,
|
|
726
821
|
emitIfAllowed: params.emitIfAllowed,
|
|
727
822
|
});
|
|
728
|
-
return;
|
|
823
|
+
return undefined;
|
|
729
824
|
}
|
|
730
825
|
if (!request.tools) {
|
|
731
826
|
throw new Error(`executeFunctionCall invoked without tools on CallModelRequest (tool name: ${fc.name}).`);
|
|
732
827
|
}
|
|
733
|
-
const toolForCall =
|
|
828
|
+
const toolForCall = findTool(allowedTools, fc.name);
|
|
734
829
|
const toolResult = await executeToolCall({
|
|
735
830
|
toolName: fc.name,
|
|
736
831
|
args: parsedArgs,
|
|
737
|
-
tools:
|
|
832
|
+
tools: allowedTools,
|
|
738
833
|
context: request.ctx,
|
|
739
834
|
harness: this.opts.harness,
|
|
740
835
|
layers: request.layers,
|
|
@@ -766,11 +861,12 @@ export class AgentHarnessModelCaller {
|
|
|
766
861
|
error: toolResult.error === true,
|
|
767
862
|
output: toolResult.output,
|
|
768
863
|
});
|
|
864
|
+
return toolResult.approval;
|
|
769
865
|
}
|
|
770
866
|
recordMalformedToolCall(params) {
|
|
771
|
-
const { fc, request, allItems, conversationInput } = params;
|
|
867
|
+
const { fc, request, allowedTools, allItems, conversationInput } = params;
|
|
772
868
|
const errorOutput = `Error: malformed JSON in tool arguments: ${fc.arguments}`;
|
|
773
|
-
const toolForCall =
|
|
869
|
+
const toolForCall = findTool(allowedTools, fc.name);
|
|
774
870
|
// Owner-scoped result validation (see executeFunctionCall).
|
|
775
871
|
const outputItem = createToolResultItem({
|
|
776
872
|
output: errorOutput,
|
package/dist/index.d.ts
CHANGED
|
@@ -31,8 +31,12 @@ export type { LoopConfig } from './builders/loop-builder.js';
|
|
|
31
31
|
/** @public */
|
|
32
32
|
export { loop } from './builders/loop-builder.js';
|
|
33
33
|
/** @public */
|
|
34
|
+
export type { WithContextOpts } from './builders/provide-builder.js';
|
|
35
|
+
/** @public */
|
|
34
36
|
export { withContext } from './builders/provide-builder.js';
|
|
35
37
|
/** @public */
|
|
38
|
+
export type { SpawnOpts } from './builders/spawn-builder.js';
|
|
39
|
+
/** @public */
|
|
36
40
|
export { spawn } from './builders/spawn-builder.js';
|
|
37
41
|
/** @public */
|
|
38
42
|
export type { CallModelOpts, InvokeToolOpts, RunCodeOpts } from './builders/step-builders.js';
|
|
@@ -115,9 +119,9 @@ export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDo
|
|
|
115
119
|
export type { Channel, ChannelHandle, ExternalChannel } from '@noetic-tools/types';
|
|
116
120
|
/** @public */
|
|
117
121
|
/** @public */
|
|
118
|
-
export type { InferSchemaInput, InferSchemaOutput, InputSchemaConfig, LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, RoundUsage, SchemaValidationFailure, SchemaValidationResult, SchemaValidationSuccess, ServerToolSpec, StandardJSONSchemaV1, StandardSchemaV1, StepMeta, TokenUsage, Tool, ToolContextDeclaration, UsageCharge, } from '@noetic-tools/types';
|
|
122
|
+
export type { InferSchemaInput, InferSchemaOutput, InputSchemaConfig, LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, RoundUsage, SchemaValidationFailure, SchemaValidationResult, SchemaValidationSuccess, ServerToolSpec, StandardJSONSchemaV1, StandardSchemaV1, StepMeta, TokenUsage, Tool, ToolChoice, ToolContextDeclaration, UsageCharge, } from '@noetic-tools/types';
|
|
119
123
|
/** @public */
|
|
120
|
-
export { isServerToolSpec, isStandardJsonSchema, isZodSchema, ServiceTier, standardIssuesToZodError, validateSchema, } from '@noetic-tools/types';
|
|
124
|
+
export { isServerToolSpec, isStandardJsonSchema, isZodSchema, ServiceTier, standardIssuesToZodError, ToolChoiceMode, validateSchema, } from '@noetic-tools/types';
|
|
121
125
|
/** @public */
|
|
122
126
|
/** @public */
|
|
123
127
|
/** @public */
|
|
@@ -139,11 +143,11 @@ export type { NoeticError } from '@noetic-tools/types';
|
|
|
139
143
|
/** @public */
|
|
140
144
|
export type { ContentPart, DeveloperMessageExtensionItem, ExecuteInput, ExtendedItem, ExtensionItem, FileSearchItem, FunctionCallItem, FunctionCallOutputItem, ImageGenerationItem, InferExtendedItem, InputContentPart, InputFilePart, InputImagePart, InputMessageItem, InputTextPart, Item, ItemBase, ItemSchemaExtensions, MessageItem, OutputItem, OutputTextPart, ReasoningItem, ReasoningTextPart, RefusalPart, ServerToolItem, SummaryTextPart, WebSearchItem, } from '@noetic-tools/types';
|
|
141
145
|
/** @public */
|
|
142
|
-
export type { BudgetConfig, CompleteParams, ContextConfig, ContextData, ContextLayer, ContextLayerHooks, DisposeParams, InferContext, InferContextShape, InitParams, InitResult, LayerDataDecl, LayerFunctionDecl, LayerPlacement, LayerProvides, LayerTimeouts, ProjectionPolicy, RecallParams, RecallResult, RenderDeltaParams, ReturnParams, ReturnResult, ScopedStorage, SpawnParams, SpawnResult, StorageAdapter, StoreParams, StoreResult, } from '@noetic-tools/context';
|
|
146
|
+
export type { BudgetConfig, CompleteParams, ContextConfig, ContextData, ContextLayer, ContextLayerHooks, DisposeParams, InferContext, InferContextShape, InitParams, InitResult, LayerDataDecl, LayerFunctionDecl, LayerPlacement, LayerProvides, LayerTimeouts, ParentUpdateParams, ParentUpdateResult, ProjectionPolicy, RecallParams, RecallResult, RenderDeltaParams, ReturnParams, ReturnResult, ScopedStorage, SpawnParams, SpawnResult, StorageAdapter, StoreParams, StoreResult, } from '@noetic-tools/context';
|
|
143
147
|
/** @public */
|
|
144
148
|
export { Slot } from '@noetic-tools/context';
|
|
145
149
|
/** @public */
|
|
146
|
-
export type { ContextScope, ExecutionContext, ExecutionOutcome, LayerCallModelRequest, } from '@noetic-tools/types';
|
|
150
|
+
export type { ContextScope, ExecutionContext, ExecutionOutcome, ExecutionSpan, LayerCallModelRequest, } from '@noetic-tools/types';
|
|
147
151
|
/** @public */
|
|
148
152
|
export type { LayerTraceSpan, Span, TraceExporter } from '@noetic-tools/types';
|
|
149
153
|
/** @public */
|
|
@@ -151,7 +155,7 @@ export type { FrameworkStreamEvent, HarnessResponse, SdkStreamEvent, StreamEvent
|
|
|
151
155
|
/** @public */
|
|
152
156
|
export type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, ContextCacheConfig, ContextCacheStore, ContextEpoch, DeliveryMode, ExecuteOptions, HarnessJudgmentContract, HarnessStatus, ItemSchemaConfig, ReanchorReason, RecallLayerOutput, SessionScope, SessionUsage, } from '@noetic-tools/types';
|
|
153
157
|
/** @public */
|
|
154
|
-
export type { AfterModelCallParams, AfterModelCallResult, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, } from '@noetic-tools/types';
|
|
158
|
+
export type { AfterModelCallParams, AfterModelCallResult, ApproveToolCallParams, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, ToolApprover, } from '@noetic-tools/types';
|
|
155
159
|
/** @public */
|
|
156
160
|
export { LedgerEntryKind, SteeringAction } from '@noetic-tools/types';
|
|
157
161
|
/** @public */
|
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ export { defaultItemSchemaRegistry, ItemSchema, ItemSchemaRegistry } from '@noet
|
|
|
90
90
|
/** @public */
|
|
91
91
|
export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, } from './schemas/workflow.js';
|
|
92
92
|
/** @public */
|
|
93
|
-
export { isServerToolSpec, isStandardJsonSchema, isZodSchema, ServiceTier, standardIssuesToZodError, validateSchema, } from '@noetic-tools/types';
|
|
93
|
+
export { isServerToolSpec, isStandardJsonSchema, isZodSchema, ServiceTier, standardIssuesToZodError, ToolChoiceMode, validateSchema, } from '@noetic-tools/types';
|
|
94
94
|
/** @public */
|
|
95
95
|
export { getToolCwd, setToolCwd, snapshotCwdState } from './runtime/cwd-helpers.js';
|
|
96
96
|
/** @public */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { LayerServeInfo, LayerStateStore } from '@noetic-tools/context';
|
|
2
|
-
export { allocateBudgets, assembleView, churnFor, churnRate, commitLayerUsage, computeLayerUsage, contextToExecCtx, createContextCacheStore, DECISION_PROJECTION, DEFAULT_PROJECTION, lineageKey, noteCacheOutcome, openEpoch, pin, pinKey, reanchorReason, resolveCacheConfig, resolveLayerTools, returnLayers, spawnLayers, } from '@noetic-tools/context';
|
|
2
|
+
export { allocateBudgets, assembleView, churnFor, churnRate, commitLayerUsage, computeLayerUsage, contextToExecCtx, createContextCacheStore, DECISION_PROJECTION, DEFAULT_PROJECTION, disposeLayers, exportSpans, initLayers, lineageKey, noteCacheOutcome, openEpoch, pin, pinKey, reanchorReason, resolveCacheConfig, resolveLayerTools, returnLayers, spawnLayers, unpinLayers, } from '@noetic-tools/context';
|
|
3
3
|
export type { ItemSchemaRegistry } from '@noetic-tools/types';
|
|
4
4
|
export { defaultItemSchemaRegistry } from '@noetic-tools/types';
|
|
5
5
|
export { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { allocateBudgets, assembleView, churnFor, churnRate, commitLayerUsage, computeLayerUsage, contextToExecCtx, createContextCacheStore, DECISION_PROJECTION, DEFAULT_PROJECTION, lineageKey, noteCacheOutcome, openEpoch, pin, pinKey, reanchorReason, resolveCacheConfig, resolveLayerTools, returnLayers, spawnLayers, } from '@noetic-tools/context';
|
|
1
|
+
export { allocateBudgets, assembleView, churnFor, churnRate, commitLayerUsage, computeLayerUsage, contextToExecCtx, createContextCacheStore, DECISION_PROJECTION, DEFAULT_PROJECTION, disposeLayers, exportSpans, initLayers, lineageKey, noteCacheOutcome, openEpoch, pin, pinKey, reanchorReason, resolveCacheConfig, resolveLayerTools, returnLayers, spawnLayers, unpinLayers, } from '@noetic-tools/context';
|
|
2
2
|
export { defaultItemSchemaRegistry } from '@noetic-tools/types';
|
|
3
3
|
export { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
|
|
4
4
|
export { ContextImpl, laneBase } from '../runtime/context-impl.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export type { ContextConfig, ContextData, ContextLayer, ExecutionContext, } from '@noetic-tools/context';
|
|
2
|
-
export type { AgentHarnessContract, CallModelRequest, Context, ContextRerenderRequest, ExecuteStepFn, FunctionCallItem, InputMessageItem, Item, LLMResponse, ProjectionPolicy, RecallLayerOutput, RetryPolicy, ServerToolSpec, StepCallModel, StepDecide, StepInvokeTool, StepMeta, StepRunCode, StepSpawn, StepWithContext, Tool, } from '@noetic-tools/types';
|
|
2
|
+
export type { AgentHarnessContract, CallModelRequest, Context, ContextRerenderRequest, ExecuteStepFn, FunctionCallItem, InputMessageItem, Item, LLMResponse, ProjectionPolicy, RecallLayerOutput, RetryPolicy, ServerToolSpec, StepCallModel, StepDecide, StepInvokeTool, StepMeta, StepRunCode, StepSpawn, StepWithContext, StorageAdapter, Tool, } from '@noetic-tools/types';
|
|
3
3
|
export { isServerToolSpec, SteeringAction } from '@noetic-tools/types';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Spans
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Spans that steps open under `ctx.span`: child contexts (`spawn` children and
|
|
3
|
+
* `inParallel` paths) and direct `invokeTool` calls. A child context carries
|
|
4
|
+
* its own span, so events its steps add to `ctx.span` (e.g. `loop.verdict`)
|
|
5
|
+
* and the model/tool spans they open nest under the child rather than being
|
|
6
|
+
* lost to a no-op span.
|
|
6
7
|
*/
|
|
7
8
|
import type { Context, Span } from '@noetic-tools/types';
|
|
8
9
|
/** Opens a span named `name` under `parent.span`, stamped with the owning step id. */
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Spans
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Spans that steps open under `ctx.span`: child contexts (`spawn` children and
|
|
3
|
+
* `inParallel` paths) and direct `invokeTool` calls. A child context carries
|
|
4
|
+
* its own span, so events its steps add to `ctx.span` (e.g. `loop.verdict`)
|
|
5
|
+
* and the model/tool spans they open nest under the child rather than being
|
|
6
|
+
* lost to a no-op span.
|
|
6
7
|
*/
|
|
8
|
+
import { exportSpans } from '@noetic-tools/context';
|
|
7
9
|
import { isNoeticError } from '@noetic-tools/types';
|
|
8
10
|
import { NoeticAttr } from '../observability/genai-attributes.js';
|
|
9
11
|
/** Opens a span named `name` under `parent.span`, stamped with the owning step id. */
|
|
@@ -45,7 +47,7 @@ function markFailed(span, error) {
|
|
|
45
47
|
}
|
|
46
48
|
async function closeChildSpan(parent, span) {
|
|
47
49
|
span.end();
|
|
48
|
-
await parent.harness.traceExporter
|
|
50
|
+
await exportSpans(parent.harness.traceExporter, [
|
|
49
51
|
span,
|
|
50
52
|
]);
|
|
51
53
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextCacheConfig, ContextCacheStore, ContextLayer, EpochUsage, ExecutionContext, Item, ProjectionPolicy, RecallLayerOutput
|
|
1
|
+
import type { ContextCacheConfig, ContextCacheStore, ContextLayer, EpochUsage, ExecutionContext, Item, ProjectionPolicy, RecallLayerOutput } from '@noetic-tools/types';
|
|
2
2
|
import type { LayerServeInfo } from './action-deps.js';
|
|
3
3
|
/** What the layer bands contributed to one assembly, and how the epoch fared. */
|
|
4
4
|
export interface BandedView {
|
|
@@ -41,10 +41,11 @@ interface PrepareBandedViewParams {
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function prepareBandedView(params: PrepareBandedViewParams): Promise<BandedView>;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* can be traced back to the layer that keeps
|
|
44
|
+
* How the view was banded, as span attributes for the step's first `llm.call`
|
|
45
|
+
* span, so a slow or expensive run can be traced back to the layer that keeps
|
|
46
|
+
* invalidating the prefix. `undefined` when anchoring is off.
|
|
46
47
|
*/
|
|
47
|
-
export declare function
|
|
48
|
+
export declare function anchoringAttributes(view: BandedView): Record<string, string | number | boolean> | undefined;
|
|
48
49
|
/** Tokens the prompt prefix was expected to have cached — what `noteCacheOutcome` judges against. */
|
|
49
50
|
export declare function expectedCachedTokens(systemPromptItems: ReadonlyArray<Item>, view: BandedView): number;
|
|
50
51
|
export {};
|
|
@@ -76,24 +76,27 @@ export async function prepareBandedView(params) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
80
|
-
* can be traced back to the layer that keeps
|
|
79
|
+
* How the view was banded, as span attributes for the step's first `llm.call`
|
|
80
|
+
* span, so a slow or expensive run can be traced back to the layer that keeps
|
|
81
|
+
* invalidating the prefix. `undefined` when anchoring is off.
|
|
81
82
|
*/
|
|
82
|
-
export function
|
|
83
|
-
if (!
|
|
84
|
-
return;
|
|
83
|
+
export function anchoringAttributes(view) {
|
|
84
|
+
if (!view.epoch) {
|
|
85
|
+
return undefined;
|
|
85
86
|
}
|
|
86
87
|
const { epoch } = view;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
const attributes = {
|
|
89
|
+
[NoeticAttr.CONTEXT_EPOCH_ID]: epoch.id,
|
|
90
|
+
[NoeticAttr.CONTEXT_EPOCH_AGE]: epoch.age,
|
|
91
|
+
[NoeticAttr.CONTEXT_ANCHOR_TOKENS]: epoch.anchorTokens,
|
|
92
|
+
[NoeticAttr.CONTEXT_LIVE_TOKENS]: epoch.liveTokens,
|
|
93
|
+
[NoeticAttr.CONTEXT_DELTA_TOKENS]: epoch.deltaTokens,
|
|
94
|
+
};
|
|
92
95
|
if (epoch.reanchorReason) {
|
|
93
|
-
|
|
96
|
+
attributes[NoeticAttr.CONTEXT_REANCHOR_REASON] = epoch.reanchorReason;
|
|
94
97
|
}
|
|
95
98
|
if (view.serveInfo.size === 0) {
|
|
96
|
-
return;
|
|
99
|
+
return attributes;
|
|
97
100
|
}
|
|
98
101
|
const placements = [];
|
|
99
102
|
const churn = [];
|
|
@@ -111,8 +114,9 @@ export function stampAnchoringAttributes(span, view) {
|
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
116
|
// Span attributes hold only scalars, so structured values travel as JSON.
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
attributes[NoeticAttr.CONTEXT_LAYER_PLACEMENTS] = JSON.stringify(placements);
|
|
118
|
+
attributes[NoeticAttr.CONTEXT_LAYER_CHURN] = JSON.stringify(churn);
|
|
119
|
+
return attributes;
|
|
116
120
|
}
|
|
117
121
|
/** Tokens the prompt prefix was expected to have cached — what `noteCacheOutcome` judges against. */
|
|
118
122
|
export function expectedCachedTokens(systemPromptItems, view) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Action step handlers: run, llm, spawn, provide, tool.
|
|
3
3
|
*/
|
|
4
4
|
import type { ItemSchemaRegistry, LayerStateStore } from './action-deps.js';
|
|
5
|
-
import type { AgentHarnessContract, Context, ContextLayer, ExecuteStepFn, StepCallModel, StepInvokeTool, StepRunCode, StepSpawn, StepWithContext } from './action-types.js';
|
|
5
|
+
import type { AgentHarnessContract, Context, ContextLayer, ExecuteStepFn, StepCallModel, StepInvokeTool, StepRunCode, StepSpawn, StepWithContext, StorageAdapter } from './action-types.js';
|
|
6
6
|
export declare function executeRunCode<TContext, I, O>(step: StepRunCode<TContext, I, O>, input: I, ctx: Context<TContext>): Promise<O>;
|
|
7
7
|
/**
|
|
8
8
|
* Resolves a `Lazy<T>` step field. If the value is a function, it is invoked
|
|
@@ -19,14 +19,34 @@ export interface ExecuteSpawnOpts {
|
|
|
19
19
|
layerStore?: LayerStateStore;
|
|
20
20
|
parentLayers?: ContextLayer[];
|
|
21
21
|
itemSchemas?: ItemSchemaRegistry;
|
|
22
|
+
/** Id for the child context; generated when absent. */
|
|
23
|
+
childId?: string;
|
|
22
24
|
}
|
|
23
25
|
export declare function executeSpawn<TContext, I, O>(step: StepSpawn<TContext, I, O>, input: I, ctx: Context<TContext>, executeStep: ExecuteStepFn, opts?: ExecuteSpawnOpts): Promise<O>;
|
|
26
|
+
export interface ExecuteWithContextOpts {
|
|
27
|
+
/** Store holding layer state; without it the provided layers are not initialized or disposed. */
|
|
28
|
+
layerStore?: LayerStateStore;
|
|
29
|
+
/** Backing storage for layer `init`; without it `init` is skipped, as at the harness root. */
|
|
30
|
+
storage?: StorageAdapter;
|
|
31
|
+
}
|
|
24
32
|
/**
|
|
25
|
-
* Executes a
|
|
26
|
-
* without creating an isolated child context.
|
|
33
|
+
* Executes a withContext step by attaching context layers to the current
|
|
34
|
+
* context without creating an isolated child context.
|
|
27
35
|
*
|
|
28
|
-
* Unlike spawn,
|
|
36
|
+
* Unlike spawn, withContext does not create a new itemLog or clone state.
|
|
29
37
|
* Events flow through to the parent in real-time.
|
|
38
|
+
*
|
|
39
|
+
* Layers whose ids the parent does not already have are scoped to the
|
|
40
|
+
* boundary: their `init` runs on entry, and on exit their `dispose` runs,
|
|
41
|
+
* their state is dropped, and their prompt-cache pins are removed so their
|
|
42
|
+
* output does not replay into later model calls. A provided layer that
|
|
43
|
+
* overrides a parent layer of the same id shares that id's state slot, so it
|
|
44
|
+
* is neither initialized nor disposed here.
|
|
45
|
+
*/
|
|
46
|
+
export declare function executeWithContext<TContext, I, O>(step: StepWithContext<TContext, I, O>, input: I, ctx: Context<TContext>, executeStep: ExecuteStepFn, opts?: ExecuteWithContextOpts): Promise<O>;
|
|
47
|
+
/**
|
|
48
|
+
* Runs an `invokeTool` step inside a `tool.call` span under `ctx.span`. The span
|
|
49
|
+
* covers validation, the steering gate, and execution, so a denied or failing
|
|
50
|
+
* call is traced with its error.
|
|
30
51
|
*/
|
|
31
|
-
export declare function executeWithContext<TContext, I, O>(step: StepWithContext<TContext, I, O>, input: I, ctx: Context<TContext>, executeStep: ExecuteStepFn): Promise<O>;
|
|
32
52
|
export declare function executeInvokeTool<TContext, I, O>(step: StepInvokeTool<TContext, I, O>, input: I, ctx: Context<TContext>, harness: AgentHarnessContract, layers?: ContextLayer[]): Promise<O>;
|