@rowan-agent/agent 0.13.1 → 0.13.3

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/index.d.ts CHANGED
@@ -82,6 +82,7 @@ type ExecutionState = {
82
82
  attempt: number;
83
83
  metrics: LoopMetrics;
84
84
  status: "idle" | "running" | "suspended" | "completed" | "aborted" | "failed";
85
+ initialPhasePayload?: JsonValue;
85
86
  continuation?: ExecutionContinuationState;
86
87
  runInteractions?: RunInteractionState;
87
88
  phaseInteractions?: RunInteractionState;
@@ -1209,6 +1210,7 @@ type RunRecord = Readonly<{
1209
1210
  messageRevision: number;
1210
1211
  }>;
1211
1212
  metadata?: Metadata;
1213
+ phasePayload?: JsonValue;
1212
1214
  pinnedConfigToken?: ConfigToken;
1213
1215
  checkpoint?: ExecutionCheckpoint;
1214
1216
  currentPhaseId?: string;
@@ -1265,6 +1267,8 @@ type RunSnapshotBase = Readonly<{
1265
1267
  revision: number;
1266
1268
  input: UserInput;
1267
1269
  metadata?: Metadata;
1270
+ /** Effective entry Phase payload the Run started with (defaults filled). */
1271
+ phasePayload?: JsonValue;
1268
1272
  messageCount: number;
1269
1273
  toolCallCount: number;
1270
1274
  currentPhaseId?: string;
@@ -1371,6 +1375,8 @@ interface OwnedStore {
1371
1375
  agentId: AgentId;
1372
1376
  input: UserInput;
1373
1377
  metadata?: Metadata;
1378
+ phasePayload?: JsonValue;
1379
+ pinnedConfigToken?: ConfigToken;
1374
1380
  idempotencyKey: string;
1375
1381
  }): Promise<RunRecord>;
1376
1382
  claimRun(input: {
@@ -1549,6 +1555,7 @@ interface AgentRuntime$1 {
1549
1555
  start(agentId: AgentId, input: UserInput, options: {
1550
1556
  idempotencyKey: string;
1551
1557
  metadata?: Metadata;
1558
+ phasePayload?: JsonValue;
1552
1559
  }): Promise<AgentRun>;
1553
1560
  run(runId: RunId): AgentRun;
1554
1561
  contextStatus(agentId: AgentId, options?: {
@@ -2185,6 +2192,7 @@ declare class AgentRuntime implements AgentRuntime$1 {
2185
2192
  start(agentId: AgentId, input: UserInput, options: {
2186
2193
  idempotencyKey: string;
2187
2194
  metadata?: Metadata;
2195
+ phasePayload?: JsonValue;
2188
2196
  }): Promise<AgentRun>;
2189
2197
  run(runId: RunId): AgentRun;
2190
2198
  listAgents(input?: {
@@ -2320,6 +2328,8 @@ declare class InMemoryStore implements DurableStore {
2320
2328
  agentId: AgentId;
2321
2329
  input: UserInput;
2322
2330
  metadata?: Metadata;
2331
+ phasePayload?: JsonValue;
2332
+ pinnedConfigToken?: ConfigToken;
2323
2333
  idempotencyKey: string;
2324
2334
  }): RunRecord;
2325
2335
  claimRun(lease: OwnerLease, input: {
@@ -2523,6 +2533,8 @@ declare class SqliteStore implements DurableStore {
2523
2533
  agentId: AgentId;
2524
2534
  input: UserInput;
2525
2535
  metadata?: Metadata;
2536
+ phasePayload?: JsonValue;
2537
+ pinnedConfigToken?: ConfigToken;
2526
2538
  idempotencyKey: string;
2527
2539
  }): Promise<RunRecord>;
2528
2540
  claimRun(lease: OwnerLease, input: {
package/dist/index.js CHANGED
@@ -2609,8 +2609,8 @@ async function runPhaseLoop(config, state, registry) {
2609
2609
  if (resumingSuspendedRun) {
2610
2610
  state.status = "running";
2611
2611
  }
2612
- const initialPayload = !resumingSuspendedRun ? config.execution.runMetadata?.phasePayload : void 0;
2613
- let previousPayload = resumingSuspendedRun ? state.continuation?.previousPayload : initialPayload;
2612
+ const initialPayload = Object.hasOwn(state, "initialPhasePayload") ? state.initialPhasePayload : config.execution.runMetadata?.phasePayload;
2613
+ let previousPayload = resumingSuspendedRun ? state.continuation && Object.hasOwn(state.continuation, "previousPayload") ? state.continuation.previousPayload : state.initialPhasePayload : initialPayload;
2614
2614
  let previousPhaseMsgId = resumingSuspendedRun ? state.continuation?.previousPhaseMessageId : void 0;
2615
2615
  let previousPhaseInputMsgId;
2616
2616
  let previousResults = resumingSuspendedRun ? state.continuation?.previousResults?.map((result) => ({ ...result })) ?? [] : [];
@@ -2793,6 +2793,7 @@ async function runPhaseLoop(config, state, registry) {
2793
2793
  }
2794
2794
  const runtime = { phase, config, state, execution, messageManager, registry, context: phaseContext };
2795
2795
  let output = await executePhase(runtime);
2796
+ delete state.initialPhasePayload;
2796
2797
  let modelRouteDecision = resolveModelRouteDecision(output.toolCalls, registry);
2797
2798
  let routeDecision = modelRouteDecision;
2798
2799
  if (routeDecision) applyFirstDecision(routeDecision, output);
@@ -3331,7 +3332,8 @@ function encodeExecutionCheckpoint(state) {
3331
3332
  attempt: state.attempt,
3332
3333
  metrics,
3333
3334
  ...continuation ? { continuation } : {},
3334
- ...runInteractions === void 0 ? {} : { runInteractions }
3335
+ ...runInteractions === void 0 ? {} : { runInteractions },
3336
+ ...state.initialPhasePayload === void 0 ? {} : { initialPhasePayload: state.initialPhasePayload }
3335
3337
  };
3336
3338
  assertJsonValue(data, "execution checkpoint");
3337
3339
  return {
@@ -3358,6 +3360,7 @@ function decodeExecutionCheckpoint(checkpoint) {
3358
3360
  phaseTransitions: checkpoint.data.metrics.phaseTransitions.map((transition) => ({ ...transition }))
3359
3361
  },
3360
3362
  status: "suspended",
3363
+ ...checkpoint.data.initialPhasePayload === void 0 ? {} : { initialPhasePayload: checkpoint.data.initialPhasePayload },
3361
3364
  ...checkpoint.data.continuation ? {
3362
3365
  continuation: {
3363
3366
  ...checkpoint.data.continuation,
@@ -3393,7 +3396,8 @@ async function executeOnce(input) {
3393
3396
  currentPhase: "",
3394
3397
  attempt: 0,
3395
3398
  status: "running",
3396
- metrics: createMetrics()
3399
+ metrics: createMetrics(),
3400
+ ...input.initialPhasePayload === void 0 ? {} : { initialPhasePayload: input.initialPhasePayload }
3397
3401
  };
3398
3402
  if (input.interactionAnswers) {
3399
3403
  const existing = state.runInteractions ?? state.phaseInteractions;
@@ -3488,6 +3492,7 @@ function isRecord2(value) {
3488
3492
  function isCheckpointData(value) {
3489
3493
  if (!isRecord2(value) || typeof value.currentPhase !== "string" || !Number.isInteger(value.attempt)) return false;
3490
3494
  if (!isMetrics(value.metrics)) return false;
3495
+ if (value.initialPhasePayload !== void 0 && !isJsonValue(value.initialPhasePayload)) return false;
3491
3496
  if (value.continuation !== void 0 && !isContinuation(value.continuation)) return false;
3492
3497
  if (value.runInteractions !== void 0 && !isRunInteractionState(value.runInteractions)) return false;
3493
3498
  if (value.phaseInteractions !== void 0 && !isRunInteractionState(value.phaseInteractions)) return false;
@@ -3753,10 +3758,16 @@ function encodeIdempotencyScope(storeIncarnation, scope) {
3753
3758
  if (typeof storeIncarnation !== "string" || storeIncarnation.length === 0) throw new TypeError("storeIncarnation must be non-empty");
3754
3759
  return canonicalJson([storeIncarnation, ...scope]);
3755
3760
  }
3756
- function canonicalStartRunRequest(input, metadata) {
3761
+ function canonicalStartRunRequest(input, metadata, phasePayload, pinnedConfigToken) {
3757
3762
  const normalized = normalizeUserInput(input);
3758
3763
  if (metadata !== void 0) assertUtf8ByteLimit(canonicalJson(metadata), METADATA_JSON_BYTES, "run.metadata");
3759
- return canonicalJson({ input: normalized, ...metadata === void 0 ? {} : { metadata } });
3764
+ if (phasePayload !== void 0) assertUtf8ByteLimit(canonicalJson(phasePayload), MESSAGE_CONTENT_JSON_BYTES, "run.phasePayload");
3765
+ return canonicalJson({
3766
+ input: normalized,
3767
+ ...metadata === void 0 ? {} : { metadata },
3768
+ ...phasePayload === void 0 ? {} : { phasePayload },
3769
+ ...pinnedConfigToken === void 0 ? {} : { pinnedConfigToken }
3770
+ });
3760
3771
  }
3761
3772
 
3762
3773
  // src/runtime/config-provider.ts
@@ -6151,7 +6162,38 @@ var AgentRuntime = class _AgentRuntime {
6151
6162
  this.assertOpen();
6152
6163
  const agent = await this.requireAgent(agentId);
6153
6164
  if (!agent.activatedAt || !agent.currentConfigToken) throw new RuntimeError("agent_not_found", { agentId });
6154
- const run = await this.owned.createRun({ agentId, input, ...options.metadata === void 0 ? {} : { metadata: options.metadata }, idempotencyKey: options.idempotencyKey });
6165
+ let phasePayload;
6166
+ let pinnedConfigToken = agent.currentConfigToken;
6167
+ if (options.phasePayload !== void 0) {
6168
+ const resolution = await this.commands.resolve({ agent, token: agent.currentConfigToken });
6169
+ if (resolution.kind !== "available") {
6170
+ throw new RuntimeError("configuration_unavailable", {
6171
+ agentId,
6172
+ retryable: resolution.kind === "deferred",
6173
+ reason: resolution.kind === "deferred" ? "Configuration is deferred." : resolution.reason
6174
+ });
6175
+ }
6176
+ const config = this.resolveConfig(resolution.config);
6177
+ const assembly = assembleRegisteredExtensions(config, this.resources.extensionRunner, {
6178
+ toolArchiveDir: this.archiveDirFor(agentId)
6179
+ });
6180
+ const entryPhaseId = normalizePhaseRegistry(assembly.context.phases).entryPhaseId;
6181
+ const phase = assembly.context.phases?.phases.get(entryPhaseId);
6182
+ phasePayload = preparePhasePayload(phase?.input, options.phasePayload);
6183
+ pinnedConfigToken = await this.commands.storeSnapshot({
6184
+ agent,
6185
+ config,
6186
+ operationId: `start-run-snapshot:${agentId}:${options.idempotencyKey}`
6187
+ });
6188
+ }
6189
+ const run = await this.owned.createRun({
6190
+ agentId,
6191
+ input,
6192
+ ...options.metadata === void 0 ? {} : { metadata: options.metadata },
6193
+ ...phasePayload === void 0 ? {} : { phasePayload },
6194
+ ...pinnedConfigToken === agent.currentConfigToken ? {} : { pinnedConfigToken },
6195
+ idempotencyKey: options.idempotencyKey
6196
+ });
6155
6197
  void this.pump();
6156
6198
  return new DurableRun(this, run.id);
6157
6199
  }
@@ -6430,6 +6472,7 @@ var AgentRuntime = class _AgentRuntime {
6430
6472
  stream,
6431
6473
  maxAttempts: config.maxAttempts,
6432
6474
  checkpoint: claim.run.checkpoint,
6475
+ ...claim.run.phasePayload === void 0 ? {} : { initialPhasePayload: claim.run.phasePayload },
6433
6476
  interactionAnswers: claim.run.interactionAnswers,
6434
6477
  signal: controller.signal,
6435
6478
  beforePhase: assembly.beforePhase,
@@ -7817,8 +7860,9 @@ var InMemoryStore = class _InMemoryStore {
7817
7860
  this.assertOwner(lease);
7818
7861
  this.requireAgent(input.agentId);
7819
7862
  const normalizedInput = normalizeUserInput(input.input);
7863
+ if (input.phasePayload !== void 0) assertJsonValue(input.phasePayload, "run.phasePayload");
7820
7864
  const scope = createIdempotencyScope("start_run", input.agentId, input.idempotencyKey);
7821
- const payload = canonicalStartRunRequest(normalizedInput, input.metadata);
7865
+ const payload = canonicalStartRunRequest(normalizedInput, input.metadata, input.phasePayload, input.pinnedConfigToken);
7822
7866
  const replay = this.replay(scope, payload);
7823
7867
  if (replay) return clone(replay);
7824
7868
  const waitingRun = isControlMetadata(input.metadata) ? void 0 : [...this.runs.values()].find((candidate) => candidate.agentId === input.agentId && candidate.state === "input_required");
@@ -7870,6 +7914,8 @@ var InMemoryStore = class _InMemoryStore {
7870
7914
  state: "queued",
7871
7915
  input: clone(normalizedInput),
7872
7916
  ...input.metadata ? { metadata: clone(input.metadata) } : {},
7917
+ ...input.phasePayload === void 0 ? {} : { phasePayload: clone(input.phasePayload) },
7918
+ ...input.pinnedConfigToken === void 0 ? {} : { pinnedConfigToken: input.pinnedConfigToken },
7873
7919
  createdAt: timestamp,
7874
7920
  updatedAt: timestamp
7875
7921
  };
@@ -8370,6 +8416,7 @@ var InMemoryStore = class _InMemoryStore {
8370
8416
  revision: run.revision,
8371
8417
  input: clone(run.input),
8372
8418
  ...run.metadata ? { metadata: clone(run.metadata) } : {},
8419
+ ...run.phasePayload === void 0 ? {} : { phasePayload: clone(run.phasePayload) },
8373
8420
  messageCount: this.messagesForRun(run.id).length,
8374
8421
  toolCallCount: [...this.toolCalls.values()].filter((toolCall) => toolCall.runId === run.id).length,
8375
8422
  ...run.currentPhaseId === void 0 ? {} : { currentPhaseId: run.currentPhaseId },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowan-agent/agent",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",