@tangle-network/agent-interface 0.34.0 → 0.35.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.
@@ -2124,6 +2124,7 @@ export declare const candidateExecutionEvidenceSchema: z.ZodObject<{
2124
2124
  endedAtMs: z.ZodNumber;
2125
2125
  durationMs: z.ZodNumber;
2126
2126
  }, z.core.$strict>;
2127
+ steps: z.ZodNumber;
2127
2128
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
2128
2129
  mode: z.ZodLiteral<"disabled">;
2129
2130
  }, z.core.$strict>, z.ZodObject<{
@@ -4986,6 +4987,7 @@ export declare const agentImprovementMeasuredComparisonSchema: z.ZodObject<{
4986
4987
  endedAtMs: z.ZodNumber;
4987
4988
  durationMs: z.ZodNumber;
4988
4989
  }, z.core.$strict>;
4990
+ steps: z.ZodNumber;
4989
4991
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
4990
4992
  mode: z.ZodLiteral<"disabled">;
4991
4993
  }, z.core.$strict>, z.ZodObject<{
@@ -6334,6 +6336,7 @@ export declare const agentImprovementMeasuredComparisonSchema: z.ZodObject<{
6334
6336
  endedAtMs: z.ZodNumber;
6335
6337
  durationMs: z.ZodNumber;
6336
6338
  }, z.core.$strict>;
6339
+ steps: z.ZodNumber;
6337
6340
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
6338
6341
  mode: z.ZodLiteral<"disabled">;
6339
6342
  }, z.core.$strict>, z.ZodObject<{
@@ -9226,6 +9229,7 @@ export declare const agentImprovementProposalSchema: z.ZodObject<{
9226
9229
  endedAtMs: z.ZodNumber;
9227
9230
  durationMs: z.ZodNumber;
9228
9231
  }, z.core.$strict>;
9232
+ steps: z.ZodNumber;
9229
9233
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
9230
9234
  mode: z.ZodLiteral<"disabled">;
9231
9235
  }, z.core.$strict>, z.ZodObject<{
@@ -10574,6 +10578,7 @@ export declare const agentImprovementProposalSchema: z.ZodObject<{
10574
10578
  endedAtMs: z.ZodNumber;
10575
10579
  durationMs: z.ZodNumber;
10576
10580
  }, z.core.$strict>;
10581
+ steps: z.ZodNumber;
10577
10582
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
10578
10583
  mode: z.ZodLiteral<"disabled">;
10579
10584
  }, z.core.$strict>, z.ZodObject<{
@@ -11507,6 +11512,7 @@ export declare const agentImprovementProposalSchema: z.ZodObject<{
11507
11512
  endedAtMs: z.ZodNumber;
11508
11513
  durationMs: z.ZodNumber;
11509
11514
  }, z.core.$strict>;
11515
+ steps: z.ZodNumber;
11510
11516
  resolvedModel: z.ZodObject<{
11511
11517
  requested: z.ZodString;
11512
11518
  provider: z.ZodString;
@@ -11645,6 +11651,7 @@ export declare const agentImprovementProposalSchema: z.ZodObject<{
11645
11651
  endedAtMs: z.ZodNumber;
11646
11652
  durationMs: z.ZodNumber;
11647
11653
  }, z.core.$strict>;
11654
+ steps: z.ZodNumber;
11648
11655
  resolvedModel: z.ZodObject<{
11649
11656
  requested: z.ZodString;
11650
11657
  provider: z.ZodString;
@@ -3,6 +3,7 @@ import { agentCandidateBundleSchema } from "./agent-candidate-schema.js";
3
3
  import { agentCandidateLineageSchema } from "./agent-candidate-lineage-schema.js";
4
4
  import { agentCandidateBenchmarkSuiteInputsSchema } from "./agent-candidate-task-schema.js";
5
5
  import { canonicalCandidateDigest, isCanonicalJsonValue, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
6
+ import { refineAgentExecutionWithinLimits } from "./agent-execution-limits.js";
6
7
  import { agentCandidateMaterializationReceiptSchema, agentCandidateRunReceiptSchema, } from "./agent-candidate-receipt-schema.js";
7
8
  import { agentCandidateEvaluationPolicySchema, canonicalJsonObjectSchema, createMeasuredComparisonIdentityRegistry, measuredComparisonCommonShape, refineMeasuredComparisonSummary, } from "./agent-improvement-measurement-schema.js";
8
9
  import { agentProfileImprovementMeasuredComparisonSchema, changedProfileImprovementSurfaces, } from "./agent-profile-improvement-schema.js";
@@ -112,6 +113,14 @@ export const candidateExecutionEvidenceSchema = z
112
113
  if (!valid)
113
114
  ctx.addIssue({ code: "custom", path, message });
114
115
  }
116
+ refineAgentExecutionWithinLimits(plan.material.limits, {
117
+ durationMs: evidence.receipt.timing.durationMs,
118
+ steps: evidence.receipt.steps,
119
+ usage: evidence.receipt.modelSettlement.material.usage,
120
+ }, ctx, {
121
+ pathPrefix: ["receipt"],
122
+ usagePath: ["modelSettlement", "material", "usage"],
123
+ });
115
124
  if (!isCanonicalJsonValue(evidence)) {
116
125
  ctx.addIssue({
117
126
  code: "custom",
@@ -903,6 +903,7 @@ export declare const agentCandidateRunReceiptSchema: z.ZodObject<{
903
903
  endedAtMs: z.ZodNumber;
904
904
  durationMs: z.ZodNumber;
905
905
  }, z.core.$strict>;
906
+ steps: z.ZodNumber;
906
907
  memory: z.ZodDiscriminatedUnion<[z.ZodObject<{
907
908
  mode: z.ZodLiteral<"disabled">;
908
909
  }, z.core.$strict>, z.ZodObject<{
@@ -259,6 +259,7 @@ export const agentCandidateRunReceiptSchema = z
259
259
  durationMs: z.number().int().nonnegative().safe(),
260
260
  })
261
261
  .strict(),
262
+ steps: z.number().int().nonnegative().safe(),
262
263
  memory: agentCandidateMemoryReceiptSchema,
263
264
  trace: agentCandidateTraceEvidenceSchema,
264
265
  termination: agentCandidateTerminationSchema,
@@ -658,6 +658,7 @@ export interface AgentCandidateRunReceipt {
658
658
  endedAtMs: number;
659
659
  durationMs: number;
660
660
  };
661
+ steps: number;
661
662
  memory: AgentCandidateMemoryReceipt;
662
663
  trace: AgentCandidateTraceEvidence;
663
664
  termination: AgentCandidateTermination;
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import type { AgentCandidateExecutionLimits, AgentCandidateFixedSpend } from "./agent-candidate.js";
3
+ /** The observable execution facts required to prove a frozen limit was respected. */
4
+ export interface AgentExecutionLimitObservation {
5
+ durationMs: number;
6
+ steps: number;
7
+ usage: AgentCandidateFixedSpend;
8
+ }
9
+ export declare const agentExecutionLimitObservationSchema: z.ZodObject<{
10
+ durationMs: z.ZodNumber;
11
+ steps: z.ZodNumber;
12
+ usage: z.ZodObject<{
13
+ inputTokens: z.ZodNumber;
14
+ outputTokens: z.ZodNumber;
15
+ cachedInputTokens: z.ZodNumber;
16
+ reasoningTokens: z.ZodNumber;
17
+ modelCalls: z.ZodNumber;
18
+ costUsdNanos: z.ZodNumber;
19
+ }, z.core.$strict>;
20
+ }, z.core.$strict>;
21
+ export interface RefineAgentExecutionWithinLimitsOptions {
22
+ pathPrefix?: (string | number)[];
23
+ usagePath?: (string | number)[];
24
+ }
25
+ /** Reject an execution record that cannot satisfy every limit it claims to use. */
26
+ export declare function assertAgentExecutionWithinLimits(limits: AgentCandidateExecutionLimits, observation: AgentExecutionLimitObservation): void;
27
+ /** Add schema issues instead of throwing when a receipt is parsed by Zod. */
28
+ export declare function refineAgentExecutionWithinLimits(limits: AgentCandidateExecutionLimits, observation: AgentExecutionLimitObservation, ctx: z.RefinementCtx, options?: RefineAgentExecutionWithinLimitsOptions): void;
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ import { agentCandidateExecutionLimitsSchema } from "./agent-candidate-execution-plan-schema.js";
3
+ import { agentCandidateFixedSpendSchema } from "./agent-candidate-outcome-schema.js";
4
+ export const agentExecutionLimitObservationSchema = z
5
+ .object({
6
+ durationMs: z.number().finite().nonnegative(),
7
+ steps: z.number().int().nonnegative().safe(),
8
+ usage: agentCandidateFixedSpendSchema,
9
+ })
10
+ .strict();
11
+ /** Reject an execution record that cannot satisfy every limit it claims to use. */
12
+ export function assertAgentExecutionWithinLimits(limits, observation) {
13
+ const parsedLimits = agentCandidateExecutionLimitsSchema.parse(limits);
14
+ const parsedObservation = agentExecutionLimitObservationSchema.parse(observation);
15
+ const violations = executionLimitViolations(parsedLimits, parsedObservation);
16
+ if (violations.length === 0)
17
+ return;
18
+ throw new Error(violations
19
+ .map((violation) => `execution ${violation.label} ${violation.actual} exceeds frozen limit ${violation.maximum}`)
20
+ .join("; "));
21
+ }
22
+ /** Add schema issues instead of throwing when a receipt is parsed by Zod. */
23
+ export function refineAgentExecutionWithinLimits(limits, observation, ctx, options = {}) {
24
+ const pathPrefix = options.pathPrefix ?? [];
25
+ const usagePath = options.usagePath ?? ["usage"];
26
+ for (const violation of executionLimitViolations(limits, observation)) {
27
+ const path = violation.path[0] === "usage"
28
+ ? [...pathPrefix, ...usagePath, ...violation.path.slice(1)]
29
+ : [...pathPrefix, ...violation.path];
30
+ ctx.addIssue({
31
+ code: "custom",
32
+ path,
33
+ message: `execution ${violation.label} ${violation.actual} exceeds frozen limit ${violation.maximum}`,
34
+ });
35
+ }
36
+ }
37
+ function executionLimitViolations(limits, observation) {
38
+ const checks = [
39
+ {
40
+ path: ["timing", "durationMs"],
41
+ label: "durationMs",
42
+ actual: observation.durationMs,
43
+ maximum: limits.timeoutMs,
44
+ },
45
+ {
46
+ path: ["steps"],
47
+ label: "steps",
48
+ actual: observation.steps,
49
+ maximum: limits.maxSteps,
50
+ },
51
+ {
52
+ path: ["usage", "modelCalls"],
53
+ label: "modelCalls",
54
+ actual: observation.usage.modelCalls,
55
+ maximum: limits.maxModelCalls,
56
+ },
57
+ {
58
+ path: ["usage", "inputTokens"],
59
+ label: "inputTokens",
60
+ actual: observation.usage.inputTokens,
61
+ maximum: limits.maxInputTokens,
62
+ },
63
+ {
64
+ path: ["usage", "outputTokens"],
65
+ label: "outputTokens",
66
+ actual: observation.usage.outputTokens,
67
+ maximum: limits.maxOutputTokens,
68
+ },
69
+ {
70
+ path: ["usage", "costUsdNanos"],
71
+ label: "costUsd",
72
+ actual: observation.usage.costUsdNanos / 1_000_000_000,
73
+ maximum: limits.maxCostUsd,
74
+ },
75
+ ];
76
+ return checks.filter((check) => check.actual > check.maximum);
77
+ }
@@ -395,6 +395,7 @@ export declare const agentProfileImprovementRunReceiptSchema: z.ZodObject<{
395
395
  endedAtMs: z.ZodNumber;
396
396
  durationMs: z.ZodNumber;
397
397
  }, z.core.$strict>;
398
+ steps: z.ZodNumber;
398
399
  resolvedModel: z.ZodObject<{
399
400
  requested: z.ZodString;
400
401
  provider: z.ZodString;
@@ -843,6 +844,7 @@ export declare const agentProfileImprovementMeasuredComparisonSchema: z.ZodObjec
843
844
  endedAtMs: z.ZodNumber;
844
845
  durationMs: z.ZodNumber;
845
846
  }, z.core.$strict>;
847
+ steps: z.ZodNumber;
846
848
  resolvedModel: z.ZodObject<{
847
849
  requested: z.ZodString;
848
850
  provider: z.ZodString;
@@ -981,6 +983,7 @@ export declare const agentProfileImprovementMeasuredComparisonSchema: z.ZodObjec
981
983
  endedAtMs: z.ZodNumber;
982
984
  durationMs: z.ZodNumber;
983
985
  }, z.core.$strict>;
986
+ steps: z.ZodNumber;
984
987
  resolvedModel: z.ZodObject<{
985
988
  requested: z.ZodString;
986
989
  provider: z.ZodString;
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { agentCandidateLineageSchema } from "./agent-candidate-lineage-schema.js";
3
3
  import { canonicalCandidateDigest, isCanonicalJsonValue, omitTopLevelDigest, sha256DigestSchema, } from "./agent-candidate-schema-common.js";
4
+ import { refineAgentExecutionWithinLimits } from "./agent-execution-limits.js";
4
5
  import { agentCandidateBenchmarkGraderIdentitySchema, agentCandidateExecutionLimitsSchema, agentCandidateResolvedModelSchema, } from "./agent-candidate-execution-plan-schema.js";
5
6
  import { agentCandidateBenchmarkDimensionSchema, agentCandidateFixedSpendSchema, } from "./agent-candidate-outcome-schema.js";
6
7
  import { agentCandidateEvaluationPolicySchema, createMeasuredComparisonIdentityRegistry, measuredComparisonCommonShape, refineMeasuredComparisonSummary, } from "./agent-improvement-measurement-schema.js";
@@ -310,6 +311,7 @@ export const agentProfileImprovementRunReceiptSchema = z
310
311
  .tuple([profileImprovementEvidenceSchema])
311
312
  .rest(profileImprovementEvidenceSchema),
312
313
  timing: timingSchema,
314
+ steps: z.number().int().nonnegative().safe(),
313
315
  resolvedModel: agentCandidateResolvedModelSchema,
314
316
  limits: agentCandidateExecutionLimitsSchema,
315
317
  usage: agentCandidateFixedSpendSchema,
@@ -357,6 +359,11 @@ export const agentProfileImprovementRunReceiptSchema = z
357
359
  message: "profile trace must retain at least one event for every model call",
358
360
  });
359
361
  }
362
+ refineAgentExecutionWithinLimits(receipt.limits, {
363
+ durationMs: receipt.timing.durationMs,
364
+ steps: receipt.steps,
365
+ usage: receipt.usage,
366
+ }, ctx);
360
367
  const billing = receipt.billing.map(evidenceKey);
361
368
  if (new Set(billing).size !== billing.length) {
362
369
  ctx.addIssue({
@@ -97,6 +97,7 @@ export interface AgentProfileImprovementRunReceipt {
97
97
  endedAtMs: number;
98
98
  durationMs: number;
99
99
  };
100
+ steps: number;
100
101
  resolvedModel: AgentCandidateResolvedModel;
101
102
  limits: AgentCandidateExecutionLimits;
102
103
  usage: AgentCandidateFixedSpend;
package/dist/index.d.ts CHANGED
@@ -613,11 +613,14 @@ export interface SdkProviderAdapter {
613
613
  export * from "./interaction.js";
614
614
  export * from "./agent-candidate.js";
615
615
  export * from "./agent-candidate-schema.js";
616
+ export type { Sha256Digest } from "./agent-candidate.js";
617
+ export { canonicalCandidateBytes, canonicalCandidateDigest, canonicalCandidateJson, sha256Bytes, sha256DigestSchema, sha256Utf8, } from "./agent-candidate-schema-common.js";
616
618
  export * from "./agent-candidate-promotion-schema.js";
617
619
  export { agentCandidateEvaluationPolicySchema } from "./agent-improvement-measurement-schema.js";
618
620
  export * from "./agent-improvement-source.js";
619
621
  export * from "./agent-profile-improvement.js";
620
622
  export * from "./agent-profile-improvement-schema.js";
623
+ export * from "./agent-execution-limits.js";
621
624
  export * from "./agent-profile.js";
622
625
  export * from "./certified-context.js";
623
626
  export * from "./profile-diff.js";
package/dist/index.js CHANGED
@@ -126,11 +126,13 @@ export function resolveNativeWebTools(tools) {
126
126
  export * from "./interaction.js";
127
127
  export * from "./agent-candidate.js";
128
128
  export * from "./agent-candidate-schema.js";
129
+ export { canonicalCandidateBytes, canonicalCandidateDigest, canonicalCandidateJson, sha256Bytes, sha256DigestSchema, sha256Utf8, } from "./agent-candidate-schema-common.js";
129
130
  export * from "./agent-candidate-promotion-schema.js";
130
131
  export { agentCandidateEvaluationPolicySchema } from "./agent-improvement-measurement-schema.js";
131
132
  export * from "./agent-improvement-source.js";
132
133
  export * from "./agent-profile-improvement.js";
133
134
  export * from "./agent-profile-improvement-schema.js";
135
+ export * from "./agent-execution-limits.js";
134
136
  export * from "./agent-profile.js";
135
137
  export * from "./certified-context.js";
136
138
  export * from "./profile-diff.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",