@rowan-agent/agent 0.13.0 → 0.13.2

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;
@@ -1086,7 +1087,10 @@ type ContextCompactionRecord = Readonly<{
1086
1087
  instructions?: string;
1087
1088
  createdAt: string;
1088
1089
  }>;
1089
- type ToolInvocationContext = Readonly<{
1090
+ /** Who is calling which tool, without the ability to ask or suspend. Hosts that
1091
+ * describe a call before it runs (for example to build a confirmation) only
1092
+ * have this much. */
1093
+ type ToolCallContext = Readonly<{
1090
1094
  agentId: AgentId;
1091
1095
  runId: RunId;
1092
1096
  /** Opaque JSON metadata captured from the Agent and Run records. Rowan does
@@ -1095,6 +1099,8 @@ type ToolInvocationContext = Readonly<{
1095
1099
  runMetadata?: Metadata;
1096
1100
  toolCallId: ToolCallId;
1097
1101
  reportProgress(progress: JsonValue): void;
1102
+ }>;
1103
+ type ToolInvocationContext = ToolCallContext & Readonly<{
1098
1104
  interaction: RunInteractionDriver;
1099
1105
  }>;
1100
1106
  type Tool$1 = Readonly<{
@@ -1204,6 +1210,7 @@ type RunRecord = Readonly<{
1204
1210
  messageRevision: number;
1205
1211
  }>;
1206
1212
  metadata?: Metadata;
1213
+ phasePayload?: JsonValue;
1207
1214
  pinnedConfigToken?: ConfigToken;
1208
1215
  checkpoint?: ExecutionCheckpoint;
1209
1216
  currentPhaseId?: string;
@@ -1366,6 +1373,8 @@ interface OwnedStore {
1366
1373
  agentId: AgentId;
1367
1374
  input: UserInput;
1368
1375
  metadata?: Metadata;
1376
+ phasePayload?: JsonValue;
1377
+ pinnedConfigToken?: ConfigToken;
1369
1378
  idempotencyKey: string;
1370
1379
  }): Promise<RunRecord>;
1371
1380
  claimRun(input: {
@@ -1544,6 +1553,7 @@ interface AgentRuntime$1 {
1544
1553
  start(agentId: AgentId, input: UserInput, options: {
1545
1554
  idempotencyKey: string;
1546
1555
  metadata?: Metadata;
1556
+ phasePayload?: JsonValue;
1547
1557
  }): Promise<AgentRun>;
1548
1558
  run(runId: RunId): AgentRun;
1549
1559
  contextStatus(agentId: AgentId, options?: {
@@ -2180,6 +2190,7 @@ declare class AgentRuntime implements AgentRuntime$1 {
2180
2190
  start(agentId: AgentId, input: UserInput, options: {
2181
2191
  idempotencyKey: string;
2182
2192
  metadata?: Metadata;
2193
+ phasePayload?: JsonValue;
2183
2194
  }): Promise<AgentRun>;
2184
2195
  run(runId: RunId): AgentRun;
2185
2196
  listAgents(input?: {
@@ -2315,6 +2326,8 @@ declare class InMemoryStore implements DurableStore {
2315
2326
  agentId: AgentId;
2316
2327
  input: UserInput;
2317
2328
  metadata?: Metadata;
2329
+ phasePayload?: JsonValue;
2330
+ pinnedConfigToken?: ConfigToken;
2318
2331
  idempotencyKey: string;
2319
2332
  }): RunRecord;
2320
2333
  claimRun(lease: OwnerLease, input: {
@@ -2518,6 +2531,8 @@ declare class SqliteStore implements DurableStore {
2518
2531
  agentId: AgentId;
2519
2532
  input: UserInput;
2520
2533
  metadata?: Metadata;
2534
+ phasePayload?: JsonValue;
2535
+ pinnedConfigToken?: ConfigToken;
2521
2536
  idempotencyKey: string;
2522
2537
  }): Promise<RunRecord>;
2523
2538
  claimRun(lease: OwnerLease, input: {
@@ -2846,4 +2861,4 @@ declare function parseFrontmatter<T = Record<string, unknown>>(raw: string): Fro
2846
2861
 
2847
2862
  declare function createCoreTools(input?: CoreToolContext): Tool$1[];
2848
2863
 
2849
- export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InteractionRecord, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseSettingsBadge, type PhaseSettingsContext, type PhaseSettingsControl, type PhaseSettingsDefinition, type PhaseSettingsItem, type PhaseSettingsOption, type PhaseSettingsProvider, type PhaseSettingsSection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunInteraction, RunInteractionBoundary, RunInteractionCancelledError, type RunInteractionDriver, type RunInteractionKind, type RunInteractionRequest, type RunInteractionState, type RunInteractionStatus, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool$1 as Tool, type ToolCallId, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult$1 as ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhaseSettings, loadPhases, loadSkill, loadSkills, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
2864
+ export { type AfterToolCall, type AgentConfiguration, type AgentDefinition, type AgentId, type AgentListCursor, type AgentRecord, type AgentRun, AgentRuntime, type AgentRuntimeOptions, type AgentSummary, type AnyRuntimeError, type AssistantContent, type AssistantMessage, type BeforeToolCall, COMPACT_PHASE_ID, type ConfigProvider, type ConfigPutResult, type ConfigResolution, type ConfigToken, type ConfigurationSnapshot, type ContextCandidate, type ContextCompactionRecord, type ContextStatus, type CoreToolContext, DEFAULT_PHASE_ID, type DefinitionLayer, type DurableConsumer, type DurableRunEvent, type DurableStore, type DurableToolResult, type EventCursor, type EventId, type ExecutionCheckpoint, type ExecutionId, type ExecutionToken, type ExtensionAPI, type ExtensionActivationError, type ExtensionActivationResult, type ExtensionContribution, type ExtensionDisposer, type ExtensionFactory, type ExtensionFactoryResult, ExtensionLifetimeError, type ExtensionLifetimeErrorCode, type ExtensionLoadInput, type FrontmatterResult, type HistorySeed, type HookEvent, type HookEventType, type HookHandler, InMemoryConfigProvider, InMemoryStore, type InteractionRecord, type InvocationCatalogEntry, type InvocationSource, type JsonObject, type JsonPrimitive, type JsonValue, type LoadExtensionsResult, type LoadInput, type LoadResult, type LoadedExtension, type Message, type MessageBase, type MessageCommitted, type MessageContent, type MessageDelta, type MessageId, type MessageRevised, type MessageRevisionResult, type Metadata, type OpaqueId, type Outcome, type OwnerLease, type OwnerToken, type Page, type Phase, type PhaseContext, type PhaseContribution, type PhaseExecution, type PhaseExecutionIdentity, type PhaseInput, type PhaseInvocation, type PhaseMessageManager, type PhaseOutput, type PhaseRegistry, type PhaseRegistrySelection, type PhaseSettingsBadge, type PhaseSettingsContext, type PhaseSettingsControl, type PhaseSettingsDefinition, type PhaseSettingsItem, type PhaseSettingsOption, type PhaseSettingsProvider, type PhaseSettingsSection, type PhaseState, type PhaseStatus, type PhaseStatusState, type ResolvedResourceView, type ResourceDiagnostic, type ResourceKind, type ResourceRef, ResourceRegistry, ResourceRegistryError, type ResourceRegistryErrorCode, type ResourceSourceId, type ResourceView, type RetentionResult, type RunBoundary, type RunClaim, type RunEvent, type RunFailure, type RunId, type RunInteraction, RunInteractionBoundary, RunInteractionCancelledError, type RunInteractionDriver, type RunInteractionKind, type RunInteractionRequest, type RunInteractionState, type RunInteractionStatus, type RunListCursor, type RunRecord, type RunSnapshot, type RunState, type RunStateChanged, type RunSummary, RuntimeBootstrapRegistry, RuntimeError, type RuntimeErrorCode, type RuntimeErrorDetails, RuntimeExtensionLifetime, STOP_PHASE_ID, type Skill, SqliteStore, type TextContent, type ThinkingContent, type ThinkingDelta, type Tool$1 as Tool, type ToolCallContext, type ToolCallId, type ToolCallSnapshot, type ToolCallState, type ToolContribution, type ToolDefinition, type ToolExecutionResult$1 as ToolExecutionResult, type ToolInvocationContext, type ToolMessage, type ToolMessageContent, type ToolProgress, type ToolResultContent, type ToolStateChanged, type ToolUseContent, type UserContent, type UserInput, type UserMessage, brandConfigToken, createCompactPhase, createCorePhases, createCoreTools, createDefaultPhase, createStopPhase, isConfigurationSnapshot, isRuntimeError, loadExtensionsFromPath as loadExtensions, loadPhase, loadPhaseSettings, loadPhases, loadSkill, loadSkills, parseAgentDefinition, parseFrontmatter, resolveConfigurationSnapshot };
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowan-agent/agent",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",