@clearideas/agent-runtime-contracts 0.3.1 → 0.4.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/README.md CHANGED
@@ -5,6 +5,9 @@ manifests. `metadata` stores inert application data. Namespaced `extensions`
5
5
  configure behavior implemented by an application adapter. Unknown manifest
6
6
  fields fail validation.
7
7
 
8
+ Agent run manifests may declare `budget.maxTotalTokens`. Checkpoints persist
9
+ the effective limit and cumulative consumed model tokens across attempts.
10
+
8
11
  Variable keys are top-level names. Dot notation reads nested properties from
9
12
  object values. Paths cannot contain empty, `__proto__`, `prototype`, or
10
13
  `constructor` segments.
package/dist/index.d.ts CHANGED
@@ -257,7 +257,17 @@ export interface AgentRunManifest {
257
257
  runId?: string;
258
258
  variables?: AgentVariableOverride[];
259
259
  execution?: AgentRunExecution;
260
+ budget?: AgentRunBudget;
260
261
  }
262
+ export interface AgentRunBudget {
263
+ /** Cumulative reported model tokens allowed across all run attempts. */
264
+ maxTotalTokens: number;
265
+ }
266
+ export interface RunBudgetState extends AgentRunBudget {
267
+ consumedTokens: number;
268
+ }
269
+ export declare const agentRunBudgetSchema: z.ZodType<AgentRunBudget>;
270
+ export declare const runBudgetStateSchema: z.ZodType<RunBudgetState>;
261
271
  export declare const AGENT_RUN_EXECUTION_MODES: readonly ["sequential", "parallel"];
262
272
  export type AgentRunExecutionMode = (typeof AGENT_RUN_EXECUTION_MODES)[number];
263
273
  export interface AgentRunExecution {
@@ -304,6 +314,8 @@ export interface RunCheckpoint {
304
314
  activeStepArtifacts?: ArtifactRef[];
305
315
  /** Executor-owned, JSON-safe continuation data for an active nested step. */
306
316
  continuation?: JsonObject;
317
+ /** Cumulative model-token usage and the effective limit for this run. */
318
+ budget?: RunBudgetState;
307
319
  createdAt: string;
308
320
  metadata?: JsonObject;
309
321
  }
@@ -1026,6 +1038,7 @@ export declare const runCheckpointSchema: z.ZodObject<{
1026
1038
  metadata: z.ZodOptional<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
1027
1039
  }, z.core.$strict>>>;
1028
1040
  continuation: z.ZodOptional<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
1041
+ budget: z.ZodOptional<z.ZodType<RunBudgetState, unknown, z.core.$ZodTypeInternals<RunBudgetState, unknown>>>;
1029
1042
  createdAt: z.ZodISODateTime;
1030
1043
  metadata: z.ZodOptional<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
1031
1044
  }, z.core.$strict>;
package/dist/index.js CHANGED
@@ -363,7 +363,49 @@ const validateSiblingStepIds = (steps, context, path) => {
363
363
  }
364
364
  });
365
365
  };
366
- export const agentManifestSchema = z
366
+ const MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH = 128;
367
+ const MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES = 100_000;
368
+ const agentManifestStructureIssue = (input) => {
369
+ const ancestors = new WeakSet();
370
+ const stack = [{ value: input, depth: 0, exiting: false }];
371
+ let nodes = 0;
372
+ while (stack.length > 0) {
373
+ const frame = stack.pop();
374
+ if (frame.exiting) {
375
+ ancestors.delete(frame.value);
376
+ continue;
377
+ }
378
+ nodes += 1;
379
+ if (nodes > MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES) {
380
+ return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES}-node structure limit.`;
381
+ }
382
+ if (frame.depth > MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH) {
383
+ return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH}-level manifest structure depth limit.`;
384
+ }
385
+ if (frame.value == null || typeof frame.value !== "object")
386
+ continue;
387
+ if (ancestors.has(frame.value)) {
388
+ return "Agent manifest cannot contain cyclic data.";
389
+ }
390
+ const children = Array.isArray(frame.value)
391
+ ? frame.value
392
+ : Object.values(frame.value);
393
+ if (nodes + children.length > MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES) {
394
+ return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES}-node structure limit.`;
395
+ }
396
+ ancestors.add(frame.value);
397
+ stack.push({ ...frame, exiting: true });
398
+ for (let index = children.length - 1; index >= 0; index -= 1) {
399
+ stack.push({
400
+ value: children[index],
401
+ depth: frame.depth + 1,
402
+ exiting: false,
403
+ });
404
+ }
405
+ }
406
+ return undefined;
407
+ };
408
+ const agentManifestObjectSchema = z
367
409
  .object({
368
410
  schemaVersion: z.literal(AGENT_MANIFEST_SCHEMA_VERSION),
369
411
  id: z.string().optional(),
@@ -415,6 +457,20 @@ export const agentManifestSchema = z
415
457
  variableKeys.add(normalizedKey);
416
458
  });
417
459
  });
460
+ export const agentManifestSchema = z.preprocess((input, context) => {
461
+ const issue = agentManifestStructureIssue(input);
462
+ if (issue) {
463
+ context.addIssue({ code: "custom", message: issue, fatal: true });
464
+ }
465
+ return input;
466
+ }, agentManifestObjectSchema);
467
+ export const agentRunBudgetSchema = z.strictObject({
468
+ maxTotalTokens: z.number().int().positive().safe(),
469
+ });
470
+ export const runBudgetStateSchema = z.strictObject({
471
+ maxTotalTokens: z.number().int().positive().safe(),
472
+ consumedTokens: z.number().int().nonnegative().safe(),
473
+ });
418
474
  export const AGENT_RUN_EXECUTION_MODES = ["sequential", "parallel"];
419
475
  export const agentRunExecutionSchema = z.strictObject({
420
476
  mode: z.enum(AGENT_RUN_EXECUTION_MODES),
@@ -428,6 +484,7 @@ export const agentRunManifestSchema = z.strictObject({
428
484
  runId: z.string().trim().min(1).optional(),
429
485
  variables: agentVariableOverridesSchema.optional(),
430
486
  execution: agentRunExecutionSchema.optional(),
487
+ budget: agentRunBudgetSchema.optional(),
431
488
  });
432
489
  export const artifactRefSchema = z.strictObject({
433
490
  id: z.string().min(1),
@@ -574,6 +631,7 @@ export const runCheckpointSchema = z.strictObject({
574
631
  activeStepTranscript: z.array(transcriptItemSchema).optional(),
575
632
  activeStepArtifacts: z.array(artifactRefSchema).optional(),
576
633
  continuation: jsonObjectSchema.optional(),
634
+ budget: runBudgetStateSchema.optional(),
577
635
  createdAt: z.iso.datetime({ offset: true }),
578
636
  metadata: jsonObjectSchema.optional(),
579
637
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearideas/agent-runtime-contracts",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Versioned, persistence-independent contracts for Clear Ideas Agent Runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Clear Ideas Incorporated",