@standardagents/builder 0.19.2 → 0.20.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.
Files changed (35) hide show
  1. package/dist/built-in-routes.js +340 -16
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-Do-1UE9g.js → ApiKeysView-BpWU5WS4.js} +1 -1
  4. package/dist/client/{CenteredContentView-jbhr1bjU.js → CenteredContentView-w5dIVLqh.js} +1 -1
  5. package/dist/client/{CompositionView-IaJk9O8E.js → CompositionView-Beq1ylU1.js} +1 -1
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-qy-xFdId.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-CUH5M-Rk.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-CBllbG82.js → CopyButton.vue_vue_type_script_setup_true_lang-BP_WkBf6.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-JokGQoze.js → DataTable.vue_vue_type_script_setup_true_lang-DO60JJnL.js} +1 -1
  9. package/dist/client/{JsonViewer-DlkFhEMS.js → JsonViewer-DwV4rW0b.js} +1 -1
  10. package/dist/client/{LoginView-BDpEA1ia.js → LoginView-DVEFdVrE.js} +1 -1
  11. package/dist/client/{MarketplaceView-DRnUbaWM.js → MarketplaceView-t-Eg-rnC.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-BC0ceJWj.js → Modal.vue_vue_type_script_setup_true_lang-B_xALCRj.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-CIs1Lwjp.js → ModelModal.vue_vue_type_script_setup_true_lang-BWrVi0At.js} +1 -1
  14. package/dist/client/{ModelsView-BKcPCTxf.js → ModelsView-BqdYlypS.js} +1 -1
  15. package/dist/client/{PromptEditView-CAhF5-n3.js → PromptEditView-qaOh1PaG.js} +1 -1
  16. package/dist/client/{PromptModal-kPH1G9G3.js → PromptModal-Cls1xDPx.js} +1 -1
  17. package/dist/client/{PromptsView-B8UPzw78.js → PromptsView-C-MkbK76.js} +1 -1
  18. package/dist/client/{ProvidersView-C4oc5xSk.js → ProvidersView-CZViKt33.js} +1 -1
  19. package/dist/client/{ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DQZxl-R3.js → ThreadInspectorPane.vue_vue_type_script_setup_true_lang-EygdqBZl.js} +1 -1
  20. package/dist/client/{ThreadsView-Jg5Eu2ZF.js → ThreadsView-ClvCi_SA.js} +1 -1
  21. package/dist/client/{ToolsView-DYJkLRhl.js → ToolsView-CWruw9LL.js} +1 -1
  22. package/dist/client/{UsersView-C-4OraZ9.js → UsersView-ClUhEpVK.js} +1 -1
  23. package/dist/client/{VariablesView-C904vTKK.js → VariablesView-ChQQXYrE.js} +1 -1
  24. package/dist/client/index-9-23MLMl.js +6 -0
  25. package/dist/client/index.html +1 -1
  26. package/dist/{index-Dx1js-H1.d.ts → index-Bug9ATQX.d.ts} +4 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +458 -21
  29. package/dist/index.js.map +1 -1
  30. package/dist/runtime.d.ts +22 -2
  31. package/dist/runtime.js +458 -21
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/test.d.ts +1 -1
  34. package/package.json +4 -4
  35. package/dist/client/index-Dlk9K3Tb.js +0 -6
@@ -47,9 +47,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
47
47
  ));
48
48
 
49
49
  // src/agents/types.ts
50
- var MAX_STEPS, MAX_RETRIES_PER_MODEL, TIMESTAMP_MULTIPLIER, STREAM_COOLDOWN, BACKOFF_BASE;
50
+ var SUBAGENT_INITIAL_ARGUMENTS_THREAD_PROPERTY, MAX_STEPS, MAX_RETRIES_PER_MODEL, TIMESTAMP_MULTIPLIER, STREAM_COOLDOWN, BACKOFF_BASE;
51
51
  var init_types = __esm({
52
52
  "src/agents/types.ts"() {
53
+ SUBAGENT_INITIAL_ARGUMENTS_THREAD_PROPERTY = "__agentbuilder_subagent_initial_arguments";
53
54
  MAX_STEPS = 250;
54
55
  MAX_RETRIES_PER_MODEL = 2;
55
56
  TIMESTAMP_MULTIPLIER = 1e3;
@@ -3630,9 +3631,8 @@ var init_ToolExecutor = __esm({
3630
3631
  // Pass through parent thread instance and metadata
3631
3632
  // Propagate namespace context to sub-flows for packed agent isolation
3632
3633
  namespaceContext: state.namespaceContext,
3634
+ arguments: args,
3633
3635
  context: {
3634
- ...args,
3635
- // Pass tool arguments for template interpolation
3636
3636
  // Pass parent tool config for response options
3637
3637
  __parentToolConfig: toolConfig,
3638
3638
  __parentToolName: call.function.name
@@ -3823,6 +3823,7 @@ ${errorLines.join("\n")}`);
3823
3823
  const targetAgentForCreate = createArgs?.agent;
3824
3824
  const builtinCreateMessage = createArgs?.message;
3825
3825
  const builtinCreateAttachmentValue = createArgs?.attachments;
3826
+ const builtinCreateInitialArguments = createArgs?.initialArguments ?? {};
3826
3827
  const registryAgentName = targetAgentForCreate || call.function.name;
3827
3828
  const packageId = getPackageId(state);
3828
3829
  let agentDef = null;
@@ -3921,6 +3922,20 @@ ${errorLines.join("\n")}`);
3921
3922
  args,
3922
3923
  initAttachmentsProperty
3923
3924
  );
3925
+ const initialArguments = builtinSubagentAction === "create" ? builtinCreateInitialArguments : args;
3926
+ const argumentValidationError = await this.validateSubagentArguments(
3927
+ state,
3928
+ agentDef,
3929
+ initialArguments,
3930
+ {
3931
+ agentName,
3932
+ receivesMessages,
3933
+ packageId
3934
+ }
3935
+ );
3936
+ if (argumentValidationError) {
3937
+ return argumentValidationError;
3938
+ }
3924
3939
  const existingChildren = await this.getChildrenRegistry(state);
3925
3940
  const activeInstances = existingChildren.filter(
3926
3941
  (entry) => entry.name === registryAgentName && entry.status !== "terminated"
@@ -3975,10 +3990,12 @@ ${errorLines.join("\n")}`);
3975
3990
  width: attachment.width,
3976
3991
  height: attachment.height
3977
3992
  })),
3993
+ initial_arguments: initialArguments,
3978
3994
  initial_agent_name: initialAgentName,
3979
3995
  agent_title: agentDef.title || registryAgentName,
3980
3996
  agent_description: agentDef.toolDescription || `Autonomous subagent ${agentDef.title || registryAgentName}`,
3981
- spawn_group_id: state.pendingMessageId ?? null
3997
+ spawn_group_id: state.pendingMessageId ?? null,
3998
+ arguments: initialArguments
3982
3999
  }
3983
4000
  });
3984
4001
  const requestId = pending && typeof pending.request_id === "string" ? pending.request_id : crypto.randomUUID();
@@ -4000,11 +4017,13 @@ ${errorLines.join("\n")}`);
4000
4017
  agent_name: agentName,
4001
4018
  parent: state.threadId,
4002
4019
  env: providedScopedEnv ?? void 0,
4020
+ properties: this.buildSubagentThreadProperties(initialArguments) ?? void 0,
4003
4021
  tags: initialAgentName ? [this.buildThreadNameTag(initialAgentName)] : void 0
4004
4022
  });
4005
4023
  const childThreadId = childThread.id;
4006
4024
  const durableId = state.env.AGENT_BUILDER_THREAD.idFromName(childThreadId);
4007
4025
  const stub = state.env.AGENT_BUILDER_THREAD.get(durableId);
4026
+ await this.persistSubagentArguments(stub, childThreadId, initialArguments);
4008
4027
  try {
4009
4028
  const { FlowEngine: FlowEngine2 } = await Promise.resolve().then(() => (init_FlowEngine(), FlowEngine_exports));
4010
4029
  const childState = ThreadStateImpl.fromThreadInstance(stub, {
@@ -4028,7 +4047,8 @@ ${errorLines.join("\n")}`);
4028
4047
  stub,
4029
4048
  initialMessageContent,
4030
4049
  receivesMessages,
4031
- initialMessageAttachments
4050
+ initialMessageAttachments,
4051
+ initialArguments
4032
4052
  );
4033
4053
  await this.upsertChildRegistry(state, {
4034
4054
  reference: childThreadId,
@@ -4039,6 +4059,7 @@ ${errorLines.join("\n")}`);
4039
4059
  blocking,
4040
4060
  ...resumable ? { parentCommunication } : {},
4041
4061
  status: "running",
4062
+ ...this.hasInitialArguments(initialArguments) ? { initialArguments } : {},
4042
4063
  ...initialAgentName ? { threadName: initialAgentName } : {},
4043
4064
  ...state.pendingMessageId ? { spawnGroupId: state.pendingMessageId } : {},
4044
4065
  createdAt: Date.now() * 1e3
@@ -4048,7 +4069,7 @@ ${errorLines.join("\n")}`);
4048
4069
  childThreadId,
4049
4070
  agentName,
4050
4071
  initialMessages,
4051
- {}
4072
+ initialArguments
4052
4073
  );
4053
4074
  const copiedAttachments = await this.copyAttachmentsBetweenThreads(
4054
4075
  stub,
@@ -4081,7 +4102,7 @@ ${errorLines.join("\n")}`);
4081
4102
  childThreadId,
4082
4103
  agentName,
4083
4104
  initialMessages,
4084
- {}
4105
+ initialArguments
4085
4106
  );
4086
4107
  const copiedAttachments = await this.copyAttachmentsBetweenThreads(
4087
4108
  stub,
@@ -4212,21 +4233,38 @@ ${errorLines.join("\n")}`);
4212
4233
  const message = typeof args.message === "string" ? args.message : "";
4213
4234
  const attachments = args.attachments;
4214
4235
  const name15 = typeof args.name === "string" ? args.name.trim() : "";
4236
+ const rawArguments = args.arguments;
4237
+ const initialArguments = this.isPlainRecord(rawArguments) ? rawArguments : {};
4215
4238
  if (!agent) {
4216
4239
  return {
4217
4240
  agent: "",
4218
4241
  message,
4219
4242
  attachments,
4220
4243
  name: name15,
4244
+ initialArguments,
4245
+ arguments: initialArguments,
4221
4246
  error: `${SUBAGENT_CREATE_TOOL} requires agent.`
4222
4247
  };
4223
4248
  }
4249
+ if (rawArguments !== void 0 && (typeof rawArguments !== "object" || rawArguments === null || Array.isArray(rawArguments))) {
4250
+ return {
4251
+ agent,
4252
+ message,
4253
+ attachments,
4254
+ name: name15,
4255
+ initialArguments,
4256
+ arguments: initialArguments,
4257
+ error: `${SUBAGENT_CREATE_TOOL} arguments must be an object when provided.`
4258
+ };
4259
+ }
4224
4260
  if (!message.trim()) {
4225
4261
  return {
4226
4262
  agent,
4227
4263
  message,
4228
4264
  attachments,
4229
4265
  name: name15,
4266
+ initialArguments,
4267
+ arguments: initialArguments,
4230
4268
  error: `${SUBAGENT_CREATE_TOOL} requires message.`
4231
4269
  };
4232
4270
  }
@@ -4236,6 +4274,8 @@ ${errorLines.join("\n")}`);
4236
4274
  message,
4237
4275
  attachments,
4238
4276
  name: name15,
4277
+ initialArguments,
4278
+ arguments: initialArguments,
4239
4279
  error: `${SUBAGENT_CREATE_TOOL} requires attachments (use [] when none).`
4240
4280
  };
4241
4281
  }
@@ -4245,6 +4285,8 @@ ${errorLines.join("\n")}`);
4245
4285
  message,
4246
4286
  attachments,
4247
4287
  name: name15,
4288
+ initialArguments,
4289
+ arguments: initialArguments,
4248
4290
  error: `${SUBAGENT_CREATE_TOOL} name must be a string when provided.`
4249
4291
  };
4250
4292
  }
@@ -4254,10 +4296,141 @@ ${errorLines.join("\n")}`);
4254
4296
  message,
4255
4297
  attachments,
4256
4298
  name: name15,
4299
+ initialArguments,
4300
+ arguments: initialArguments,
4257
4301
  error: `${SUBAGENT_CREATE_TOOL} requires name.`
4258
4302
  };
4259
4303
  }
4260
- return { agent, message, attachments, name: name15 };
4304
+ return {
4305
+ agent,
4306
+ message,
4307
+ attachments,
4308
+ name: name15,
4309
+ initialArguments,
4310
+ arguments: initialArguments
4311
+ };
4312
+ }
4313
+ static hasInitialArguments(args) {
4314
+ return Object.keys(args).length > 0;
4315
+ }
4316
+ static isPlainRecord(value) {
4317
+ return !!value && typeof value === "object" && !Array.isArray(value);
4318
+ }
4319
+ static buildSubagentThreadProperties(initialArguments) {
4320
+ if (!this.hasInitialArguments(initialArguments)) {
4321
+ return null;
4322
+ }
4323
+ return {
4324
+ [SUBAGENT_INITIAL_ARGUMENTS_THREAD_PROPERTY]: initialArguments
4325
+ };
4326
+ }
4327
+ static qualifyPromptNameForAgent(promptName, agentName, packageId) {
4328
+ if (!promptName) {
4329
+ return null;
4330
+ }
4331
+ if (promptName.includes("/")) {
4332
+ return promptName;
4333
+ }
4334
+ const agentPackageId = agentName.includes("/") ? agentName.split("/")[0] : packageId;
4335
+ return agentPackageId ? `${agentPackageId}/${promptName}` : promptName;
4336
+ }
4337
+ static async validateSubagentInitialArguments(state, agentName, agentDef, receivesMessages, initialArguments, packageId) {
4338
+ return this.validateSubagentArguments(state, agentDef, initialArguments, {
4339
+ agentName,
4340
+ receivesMessages,
4341
+ packageId
4342
+ });
4343
+ }
4344
+ /**
4345
+ * Validate initial subagent arguments against the prompt schema on the child
4346
+ * side that receives parent messages.
4347
+ */
4348
+ static async validateSubagentArguments(state, agentDef, args, options = {}) {
4349
+ const receivesMessages = options.receivesMessages ?? "side_a";
4350
+ const promptName = receivesMessages === "side_b" ? agentDef.sideB?.prompt : agentDef.sideA?.prompt;
4351
+ const qualifiedPromptName = this.qualifyPromptNameForAgent(
4352
+ promptName,
4353
+ options.agentName ?? agentDef?.name ?? "",
4354
+ options.packageId
4355
+ );
4356
+ if (!qualifiedPromptName) {
4357
+ return null;
4358
+ }
4359
+ try {
4360
+ const promptDef = await state.thread.instance.loadPrompt(qualifiedPromptName);
4361
+ const schema = promptDef?.requiredSchema;
4362
+ if (!schema || typeof schema.safeParse !== "function") {
4363
+ return null;
4364
+ }
4365
+ const parsed = schema.safeParse(args);
4366
+ if (parsed.success) {
4367
+ return null;
4368
+ }
4369
+ const issues = Array.isArray(
4370
+ parsed.error?.issues
4371
+ ) ? parsed.error.issues : [];
4372
+ const missing = Array.from(
4373
+ new Set(
4374
+ issues.map(
4375
+ (issue) => Array.isArray(issue.path) ? issue.path.map(String).join(".") : String(issue.path ?? "")
4376
+ ).filter((path9) => path9.length > 0)
4377
+ )
4378
+ );
4379
+ const detail = issues.map((issue) => {
4380
+ const path9 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
4381
+ const message = typeof issue.message === "string" ? issue.message : "invalid value";
4382
+ return path9 ? `${path9}: ${message}` : message;
4383
+ }).join("; ") || parsed.error.message || "invalid arguments";
4384
+ const agentLabel = agentDef.title || agentDef.name || options.agentName || qualifiedPromptName;
4385
+ return {
4386
+ status: "error",
4387
+ error: `${SUBAGENT_CREATE_TOOL} arguments for "${agentLabel}" failed validation: ${detail}.`,
4388
+ error_code: "subagent_arguments_required",
4389
+ error_data: {
4390
+ agent: agentLabel,
4391
+ required: missing
4392
+ }
4393
+ };
4394
+ } catch {
4395
+ return null;
4396
+ }
4397
+ }
4398
+ static buildSubagentInitialArgumentsMessage(initialArguments, createdAt) {
4399
+ if (!this.hasInitialArguments(initialArguments)) {
4400
+ return null;
4401
+ }
4402
+ return {
4403
+ id: crypto.randomUUID(),
4404
+ role: "system",
4405
+ content: [
4406
+ "Persistent initial arguments for this subagent thread.",
4407
+ "These values were supplied by the parent when the child was created and remain in effect for side_a and side_b.",
4408
+ "They are available as ThreadState.arguments and prompt variables by their top-level keys.",
4409
+ "",
4410
+ this.formatInitialArguments(initialArguments)
4411
+ ].join("\n"),
4412
+ silent: true,
4413
+ metadata: {
4414
+ subagentInitialArguments: true
4415
+ },
4416
+ created_at: createdAt
4417
+ };
4418
+ }
4419
+ static formatInitialArguments(initialArguments) {
4420
+ return JSON.stringify(initialArguments, null, 2);
4421
+ }
4422
+ static async persistSubagentArguments(stub, childThreadId, args) {
4423
+ if (!args || Object.keys(args).length === 0) {
4424
+ return;
4425
+ }
4426
+ if (typeof stub.setSubagentArguments !== "function") {
4427
+ return;
4428
+ }
4429
+ try {
4430
+ await stub.setSubagentArguments(childThreadId, args);
4431
+ } catch (error) {
4432
+ console.error("[ToolExecutor] Failed to persist subagent arguments:", error);
4433
+ }
4261
4434
  }
4262
4435
  static getSubpromptToolConfig(config) {
4263
4436
  if (!config || typeof config !== "object") {
@@ -4337,7 +4510,7 @@ ${errorLines.join("\n")}`);
4337
4510
  await childThread.terminateThread(reference);
4338
4511
  }
4339
4512
  }
4340
- static async buildChildInvocationMessages(state, childThread, content, receivesMessages, parentAttachments) {
4513
+ static async buildChildInvocationMessages(state, childThread, content, receivesMessages, parentAttachments, initialArguments) {
4341
4514
  const copiedAttachments = await this.copyAttachmentsBetweenThreads(
4342
4515
  state.thread.instance,
4343
4516
  childThread,
@@ -4347,6 +4520,14 @@ ${errorLines.join("\n")}`);
4347
4520
  const targetRole = receivesMessages === "side_a" ? "user" : "assistant";
4348
4521
  const baseTimestamp = Date.now() * 1e3;
4349
4522
  const messages = [];
4523
+ const initialArgumentsMessage = this.buildSubagentInitialArgumentsMessage(
4524
+ initialArguments,
4525
+ baseTimestamp
4526
+ );
4527
+ if (initialArgumentsMessage) {
4528
+ messages.push(initialArgumentsMessage);
4529
+ }
4530
+ const timestampOffset = messages.length;
4350
4531
  for (let i = 0; i < copiedAttachments.length; i++) {
4351
4532
  const attachment = copiedAttachments[i];
4352
4533
  messages.push({
@@ -4355,7 +4536,7 @@ ${errorLines.join("\n")}`);
4355
4536
  content: `Initial asset attachment path: ${attachment.path}`,
4356
4537
  attachments: JSON.stringify([attachment]),
4357
4538
  silent: true,
4358
- created_at: baseTimestamp + i
4539
+ created_at: baseTimestamp + timestampOffset + i
4359
4540
  });
4360
4541
  }
4361
4542
  messages.push({
@@ -4365,7 +4546,7 @@ ${errorLines.join("\n")}`);
4365
4546
  // Keep binary refs on the silent path messages only to avoid rendering
4366
4547
  // duplicate attachments on the visible init message.
4367
4548
  attachments: void 0,
4368
- created_at: baseTimestamp + copiedAttachments.length
4549
+ created_at: baseTimestamp + timestampOffset + copiedAttachments.length
4369
4550
  });
4370
4551
  return messages;
4371
4552
  }
@@ -5764,6 +5945,7 @@ var init_FlowEngine = __esm({
5764
5945
  },
5765
5946
  queue: stateInput.queue || [],
5766
5947
  stream,
5948
+ arguments: stateInput.arguments || {},
5767
5949
  context: stateInput.context || {},
5768
5950
  retryCount: stateInput.retryCount || 0,
5769
5951
  retryReason: stateInput.retryReason,
@@ -5800,8 +5982,44 @@ var init_FlowEngine = __esm({
5800
5982
  } else {
5801
5983
  state.rootState = state;
5802
5984
  }
5985
+ try {
5986
+ const persistedArgs = await this.loadSubagentArguments(state);
5987
+ if (persistedArgs && Object.keys(persistedArgs).length > 0) {
5988
+ state.context = { ...persistedArgs, ...state.context || {} };
5989
+ }
5990
+ } catch (error) {
5991
+ console.error(
5992
+ "[FlowEngine] Failed to hydrate persisted subagent arguments:",
5993
+ error
5994
+ );
5995
+ }
5803
5996
  return state;
5804
5997
  }
5998
+ static getPromptInterpolationContext(state) {
5999
+ return {
6000
+ ...state.context || {},
6001
+ ...state.arguments || {}
6002
+ };
6003
+ }
6004
+ /**
6005
+ * Read persisted subagent invocation arguments from execution_state.
6006
+ * Returns an empty object for top-level threads or when none were stored.
6007
+ */
6008
+ static async loadSubagentArguments(state) {
6009
+ try {
6010
+ const cursor = await state.storage.sql.exec(
6011
+ `SELECT value FROM execution_state WHERE key = 'subagent_arguments' LIMIT 1`
6012
+ );
6013
+ const raw = cursor.toArray()[0]?.value;
6014
+ if (!raw) {
6015
+ return {};
6016
+ }
6017
+ const parsed = JSON.parse(raw);
6018
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
6019
+ } catch {
6020
+ return {};
6021
+ }
6022
+ }
5805
6023
  /**
5806
6024
  * Execute a single step
5807
6025
  */
@@ -6898,6 +7116,16 @@ var init_FlowEngine = __esm({
6898
7116
  const normalized = value.replace(/\s+/g, " ").trim();
6899
7117
  return normalized.length > 0 ? normalized : null;
6900
7118
  }
7119
+ static getRegistryInitialArguments(entry) {
7120
+ const value = entry.initialArguments;
7121
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
7122
+ return null;
7123
+ }
7124
+ return Object.keys(value).length > 0 ? value : null;
7125
+ }
7126
+ static formatInitialArgumentsForPrompt(initialArguments) {
7127
+ return JSON.stringify(initialArguments, null, 2);
7128
+ }
6901
7129
  static extractSubagentIdFromMetadata(metadata) {
6902
7130
  if (!metadata) {
6903
7131
  return null;
@@ -6972,7 +7200,7 @@ var init_FlowEngine = __esm({
6972
7200
  const includePastTools = state.prompt.include_past_tools ?? true;
6973
7201
  const promptContent = await this.interpolatePrompt(
6974
7202
  state.prompt.prompt,
6975
- state.context || {},
7203
+ this.getPromptInterpolationContext(state),
6976
7204
  state
6977
7205
  );
6978
7206
  const systemPromptText = await this.runAfterSystemMessageHook(
@@ -7130,10 +7358,13 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
7130
7358
  const lines = subagentRegistry.map((entry) => {
7131
7359
  const threadName = this.getRegistryThreadName(entry) ?? fallbackNameMap.get(entry.reference) ?? null;
7132
7360
  const displayName = threadName ? `${entry.name} (${threadName})` : entry.name;
7361
+ const initialArguments = this.getRegistryInitialArguments(entry);
7362
+ const argumentsLine = initialArguments ? `
7363
+ Initial arguments: ${this.formatInitialArgumentsForPrompt(initialArguments)}` : "";
7133
7364
  return `- Reference: ${entry.reference}
7134
7365
  Name: ${displayName}
7135
7366
  Description: ${entry.description}
7136
- Status: ${entry.status}`;
7367
+ Status: ${entry.status}${argumentsLine}`;
7137
7368
  });
7138
7369
  messages.push({
7139
7370
  role: "system",
@@ -7585,13 +7816,21 @@ ${lines.join("\n\n")}`
7585
7816
  const subagentConfig = this.isSubagentToolConfig(configEntry) ? configEntry : void 0;
7586
7817
  const blocking = subagentConfig?.blocking ?? true;
7587
7818
  const resumable = !!subagentConfig?.resumable && typeof subagentConfig.resumable === "object";
7819
+ const receivesMessages = subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.receives_messages : "side_a";
7820
+ const argumentSchema = await this.resolveSubagentArgumentSchema(
7821
+ state,
7822
+ agentDef,
7823
+ receivesMessages,
7824
+ packageId
7825
+ );
7588
7826
  descriptors.push({
7589
7827
  name: toolName,
7590
7828
  title: agentDef.title || toolName,
7591
7829
  description: agentDef.toolDescription || `Run ${agentDef.title || toolName} subagent`,
7592
7830
  blocking,
7593
7831
  resumable,
7594
- maxInstances: subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.maxInstances : void 0
7832
+ maxInstances: subagentConfig?.resumable && typeof subagentConfig.resumable === "object" ? subagentConfig.resumable.maxInstances : void 0,
7833
+ argumentSchema
7595
7834
  });
7596
7835
  }
7597
7836
  return descriptors;
@@ -7613,18 +7852,86 @@ ${lines.join("\n\n")}`
7613
7852
  return null;
7614
7853
  }
7615
7854
  }
7855
+ static qualifyPromptNameForPackage(promptName, packageId) {
7856
+ if (!promptName) {
7857
+ return null;
7858
+ }
7859
+ if (promptName.includes("/") || !packageId) {
7860
+ return promptName;
7861
+ }
7862
+ return `${packageId}/${promptName}`;
7863
+ }
7864
+ static async resolveSubagentArgumentSchema(state, agentDef, receivesMessages, packageId) {
7865
+ const promptName = receivesMessages === "side_b" ? agentDef.sideB?.prompt : agentDef.sideA?.prompt;
7866
+ const qualifiedPromptName = this.qualifyPromptNameForPackage(promptName, packageId);
7867
+ if (!qualifiedPromptName) {
7868
+ return void 0;
7869
+ }
7870
+ try {
7871
+ const promptDef = await state.thread.instance.loadPrompt(qualifiedPromptName);
7872
+ if (!promptDef?.requiredSchema) {
7873
+ return void 0;
7874
+ }
7875
+ const schema = this.zodToJsonSchema(promptDef.requiredSchema);
7876
+ return schema && typeof schema === "object" && !Array.isArray(schema) ? schema : void 0;
7877
+ } catch {
7878
+ return void 0;
7879
+ }
7880
+ }
7616
7881
  static isSubagentToolConfig(configEntry) {
7617
7882
  if (typeof configEntry !== "object" || configEntry === null) {
7618
7883
  return false;
7619
7884
  }
7620
7885
  return "blocking" in configEntry || "resumable" in configEntry || "immediate" in configEntry || "optional" in configEntry || "initUserMessageProperty" in configEntry || "initAttachmentsProperty" in configEntry || "initAgentNameProperty" in configEntry;
7621
7886
  }
7887
+ static normalizeSubagentArgumentSchema(schema) {
7888
+ const normalized = schema && typeof schema === "object" && !Array.isArray(schema) ? { ...schema } : {};
7889
+ normalized.type = "object";
7890
+ if (!normalized.properties || typeof normalized.properties !== "object") {
7891
+ normalized.properties = {};
7892
+ }
7893
+ if (!("additionalProperties" in normalized)) {
7894
+ normalized.additionalProperties = false;
7895
+ }
7896
+ return normalized;
7897
+ }
7898
+ static describeSubagentArguments(schema) {
7899
+ const normalized = this.normalizeSubagentArgumentSchema(schema);
7900
+ const properties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) ? Object.keys(normalized.properties) : [];
7901
+ const required = Array.isArray(normalized.required) ? normalized.required.filter((item) => typeof item === "string") : [];
7902
+ const optional = properties.filter((name15) => !required.includes(name15));
7903
+ const parts = [];
7904
+ if (required.length > 0) {
7905
+ parts.push(`required arguments: ${required.join(", ")}`);
7906
+ }
7907
+ if (optional.length > 0) {
7908
+ parts.push(`optional arguments: ${optional.join(", ")}`);
7909
+ }
7910
+ return parts.length > 0 ? parts.join("; ") : "no extra initial arguments";
7911
+ }
7912
+ static buildSubagentArgumentsSchema(promptSubagents) {
7913
+ const variants = promptSubagents.map((entry) => ({
7914
+ ...this.normalizeSubagentArgumentSchema(entry.argumentSchema),
7915
+ title: `${entry.name} initial arguments`,
7916
+ description: `Initial arguments for ${entry.name}. These values persist for the child thread lifetime.`
7917
+ }));
7918
+ if (variants.length === 1) {
7919
+ return variants[0];
7920
+ }
7921
+ return {
7922
+ type: "object",
7923
+ description: "Agent-specific initial arguments for the selected subagent. Use the schema matching the selected agent.",
7924
+ additionalProperties: false,
7925
+ anyOf: variants
7926
+ };
7927
+ }
7622
7928
  static buildSubagentCreateTool(promptSubagents) {
7623
7929
  const agentNames = promptSubagents.map((entry) => entry.name);
7624
7930
  const descriptionLines = promptSubagents.map((entry) => {
7625
7931
  const mode = `${entry.blocking ? "blocking" : "non-blocking"}, ${entry.resumable ? "resumable" : "non-resumable"}`;
7626
7932
  const maxInstances = typeof entry.maxInstances === "number" && entry.maxInstances > 0 ? `, max instances: ${entry.maxInstances}` : "";
7627
- return `- ${entry.name}: ${entry.description} (mode: ${mode}${maxInstances})`;
7933
+ const argumentSummary = this.describeSubagentArguments(entry.argumentSchema);
7934
+ return `- ${entry.name}: ${entry.description} (mode: ${mode}${maxInstances}; ${argumentSummary})`;
7628
7935
  });
7629
7936
  return {
7630
7937
  type: "function",
@@ -7634,6 +7941,7 @@ ${lines.join("\n\n")}`
7634
7941
  "Create and run a configured resumable dual_ai subagent.",
7635
7942
  "Available resumable subagents:",
7636
7943
  ...descriptionLines,
7944
+ "Provide any required invocation arguments via `arguments`; they persist for the life of the subagent thread.",
7637
7945
  "Use subagent_message for follow-up communication with resumable instances."
7638
7946
  ].join("\n"),
7639
7947
  parameters: {
@@ -7658,8 +7966,10 @@ ${lines.join("\n\n")}`
7658
7966
  name: {
7659
7967
  type: "string",
7660
7968
  description: "Required human-readable instance name for the spawned subagent thread. Use a concise stable label that identifies this child instance."
7661
- }
7969
+ },
7970
+ arguments: this.buildSubagentArgumentsSchema(promptSubagents)
7662
7971
  },
7972
+ additionalProperties: false,
7663
7973
  required: ["agent", "message", "attachments", "name"]
7664
7974
  }
7665
7975
  }
@@ -11185,6 +11495,7 @@ function runCodeViaThreadRpc(threadInstance, threadId, source, options) {
11185
11495
  var ThreadStateImpl, ExecutionStateImpl;
11186
11496
  var init_ThreadStateImpl = __esm({
11187
11497
  "src/agents/ThreadStateImpl.ts"() {
11498
+ init_types();
11188
11499
  init_utilities();
11189
11500
  init_code_execution();
11190
11501
  ThreadStateImpl = class _ThreadStateImpl {
@@ -11232,6 +11543,19 @@ var init_ThreadStateImpl = __esm({
11232
11543
  get terminated() {
11233
11544
  return this._terminatedCache;
11234
11545
  }
11546
+ get arguments() {
11547
+ if (this._flowState) {
11548
+ return this._flowState.arguments ?? this.getMetadataArguments();
11549
+ }
11550
+ return this.getMetadataArguments();
11551
+ }
11552
+ getMetadataArguments() {
11553
+ const value = this._metadata.properties?.[SUBAGENT_INITIAL_ARGUMENTS_THREAD_PROPERTY];
11554
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
11555
+ return {};
11556
+ }
11557
+ return value;
11558
+ }
11235
11559
  /**
11236
11560
  * Get the agent configuration from the underlying FlowState.
11237
11561
  * This is for backward compatibility with hooks that access state.agentConfig.