@standardagents/spec 0.12.8 → 0.13.0-next.c55f029

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
@@ -207,6 +207,33 @@ interface ThreadMetadata {
207
207
  /** Creation timestamp (microseconds since epoch) */
208
208
  created_at: number;
209
209
  }
210
+ /**
211
+ * Registry entry for a subagent child thread.
212
+ */
213
+ interface SubagentRegistryEntry {
214
+ /** Child thread UUID used as stable reference address */
215
+ reference: string;
216
+ /** Child agent name */
217
+ name: string;
218
+ /** Child agent title (human-readable) */
219
+ title?: string;
220
+ /** Tool description shown to the parent LLM */
221
+ description: string;
222
+ /** Whether this subagent instance is resumable */
223
+ resumable?: boolean;
224
+ /** Whether parent execution blocks on this subagent */
225
+ blocking?: boolean;
226
+ /** Optional human-readable thread name (for example from `name:` tag) */
227
+ threadName?: string;
228
+ /** Spawn group identifier used for grouping instances created together */
229
+ spawnGroupId?: string;
230
+ /** Instance creation timestamp (microseconds) */
231
+ createdAt?: number;
232
+ /** Current status (`running`, `idle`, `terminated`, or custom text) */
233
+ status: string;
234
+ /** How this child reports information back to its parent thread */
235
+ parentCommunication?: 'implicit' | 'explicit';
236
+ }
210
237
  /**
211
238
  * Options for retrieving messages.
212
239
  */
@@ -257,12 +284,35 @@ interface Message {
257
284
  depth?: number;
258
285
  /** Whether this message is silent (not shown in UI) */
259
286
  silent?: boolean;
260
- /** Custom metadata */
287
+ /**
288
+ * Custom metadata.
289
+ *
290
+ * Runtimes may attach lifecycle metadata for synthesized status messages
291
+ * (for example: `status_kind`, `subagent_event`).
292
+ */
261
293
  metadata?: Record<string, unknown>;
262
294
  /** Message processing status */
263
295
  status?: 'pending' | 'completed' | 'failed' | null;
264
296
  /** Tool execution status (for tool result messages) */
265
297
  tool_status?: 'success' | 'error' | null;
298
+ /** Subagent reference UUID associated with this message */
299
+ subagent_id?: string | null;
300
+ /** Subagent agent name projected from runtime registry (when available) */
301
+ subagent_name?: string | null;
302
+ /** Subagent agent title projected from runtime registry (when available) */
303
+ subagent_title?: string | null;
304
+ /** Subagent description projected from runtime registry (when available) */
305
+ subagent_description?: string | null;
306
+ /** Subagent status projected from runtime registry (when available) */
307
+ subagent_status?: string | null;
308
+ /** Whether the associated subagent is resumable (when available) */
309
+ subagent_resumable?: boolean | null;
310
+ /** Whether the associated subagent is blocking (when available) */
311
+ subagent_blocking?: boolean | null;
312
+ /** Optional subagent instance thread name (when available) */
313
+ subagent_thread_name?: string | null;
314
+ /** Spawn group identifier for related subagent instances (when available) */
315
+ subagent_spawn_group_id?: string | null;
266
316
  }
267
317
  /**
268
318
  * Input for injecting a new message.
@@ -277,6 +327,25 @@ interface InjectMessageInput {
277
327
  /** Custom metadata */
278
328
  metadata?: Record<string, unknown>;
279
329
  }
330
+ /**
331
+ * Input for queueing a message for delivery on the thread's next step.
332
+ *
333
+ * Role mapping follows dual_ai conventions:
334
+ * - `assistant` maps to side_a
335
+ * - `user` maps to side_b
336
+ */
337
+ interface QueueMessageInput {
338
+ /** Message role (`user` queues side_b perspective, `assistant` queues side_a perspective) */
339
+ role: 'user' | 'assistant';
340
+ /** Message content */
341
+ content: string;
342
+ /** Optional file attachments (new files or existing refs) */
343
+ attachments?: Array<ToolAttachment | AttachmentRef>;
344
+ /** Whether to hide the queued message from normal UI display */
345
+ silent?: boolean;
346
+ /** Optional structured metadata */
347
+ metadata?: Record<string, unknown>;
348
+ }
280
349
  /**
281
350
  * Updates to apply to an existing message.
282
351
  */
@@ -501,6 +570,17 @@ interface ThreadState {
501
570
  readonly userId: string | null;
502
571
  /** Thread creation timestamp (microseconds since epoch) */
503
572
  readonly createdAt: number;
573
+ /**
574
+ * Registry of subagent child instances owned by this thread.
575
+ *
576
+ * Includes both resumable and non-resumable instances.
577
+ */
578
+ readonly children: SubagentRegistryEntry[];
579
+ /**
580
+ * Termination timestamp (microseconds) if this thread has been terminated.
581
+ * Null when the thread is active.
582
+ */
583
+ readonly terminated: number | null;
504
584
  /**
505
585
  * Get messages from the thread.
506
586
  *
@@ -543,6 +623,13 @@ interface ThreadState {
543
623
  * @returns true if the message was found and deleted, false if not found
544
624
  */
545
625
  deleteMessage(messageId: string): Promise<boolean>;
626
+ /**
627
+ * Queue a message for delivery on the thread's next step.
628
+ *
629
+ * If the thread is executing, the message is delivered before the next LLM call.
630
+ * If idle, queueing forces execution by the queued side.
631
+ */
632
+ queueMessage(message: QueueMessageInput): Promise<void>;
546
633
  /**
547
634
  * Load a model definition by name.
548
635
  *
@@ -585,6 +672,64 @@ interface ThreadState {
585
672
  * @returns Array of model names that can be loaded
586
673
  */
587
674
  getModelNames(): string[];
675
+ /**
676
+ * Get a child thread by its subagent reference ID.
677
+ *
678
+ * @param referenceId - Child thread UUID
679
+ * @returns Child ThreadState or null if not found
680
+ */
681
+ getChildThread(referenceId: string): Promise<ThreadState | null>;
682
+ /**
683
+ * Get this thread's parent thread (if any).
684
+ *
685
+ * @returns Parent ThreadState, or null for top-level threads
686
+ */
687
+ getParentThread(): Promise<ThreadState | null>;
688
+ /**
689
+ * Resolve an environment value for this thread by property name.
690
+ *
691
+ * Resolution order:
692
+ * 1. Thread
693
+ * 2. User account
694
+ * 3. AgentBuilder instance
695
+ * 4. Agent definition
696
+ * 5. Prompt definition
697
+ *
698
+ * @throws If the variable is not defined in any source
699
+ */
700
+ env(propertyName: string): Promise<string>;
701
+ /**
702
+ * Set a thread-scoped environment variable.
703
+ *
704
+ * This writes to thread env storage and propagates the updated thread env
705
+ * to all active descendant threads recursively. Terminated descendants are
706
+ * not modified.
707
+ *
708
+ * @param propertyName - Environment variable name
709
+ * @param value - Environment variable value
710
+ */
711
+ setEnv(propertyName: string, value: string): Promise<void>;
712
+ /**
713
+ * Queue a silent message to this thread's parent, if one exists.
714
+ *
715
+ * This is useful for explicit child-to-parent escalation paths where tools or
716
+ * hooks decide when the parent should be notified.
717
+ *
718
+ * Implementations SHOULD tag the queued message with the current thread's
719
+ * `subagent_id` metadata so the parent can attribute the notification.
720
+ *
721
+ * @throws If the thread has no parent or the runtime does not support parent messaging
722
+ */
723
+ notifyParent(content: string): Promise<void>;
724
+ /**
725
+ * Update this thread's status in its parent registry entry.
726
+ *
727
+ * Useful for long-lived watcher/observer children that want to expose their
728
+ * current state without sending a parent message.
729
+ *
730
+ * @throws If the thread has no parent or the runtime does not support parent status updates
731
+ */
732
+ setStatus(status: string): Promise<void>;
588
733
  /**
589
734
  * Queue a tool for execution.
590
735
  *
@@ -671,6 +816,13 @@ interface ThreadState {
671
816
  * ```
672
817
  */
673
818
  runAgent(agentName: string): Promise<void>;
819
+ /**
820
+ * Soft-terminate the thread.
821
+ *
822
+ * Implementations should mark the thread as terminated, abort in-flight
823
+ * execution, and reject subsequent execution/message queue operations.
824
+ */
825
+ terminate(): Promise<void>;
674
826
  /**
675
827
  * Emit a custom event to connected clients.
676
828
  *
@@ -903,6 +1055,19 @@ interface ToolResult {
903
1055
  result?: string;
904
1056
  /** Error message if status is 'error'. */
905
1057
  error?: string;
1058
+ /**
1059
+ * Machine-readable error code for structured handling.
1060
+ *
1061
+ * Example: `subagent_env_required` indicates the client must provide
1062
+ * scoped subagent env values before execution can continue.
1063
+ */
1064
+ error_code?: string;
1065
+ /**
1066
+ * Structured error payload for machine handling.
1067
+ *
1068
+ * Implementations should keep this JSON-serializable.
1069
+ */
1070
+ error_data?: Record<string, unknown>;
906
1071
  /** Stack trace for error debugging. */
907
1072
  stack?: string;
908
1073
  /**
@@ -948,8 +1113,37 @@ type ToolArgsRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
948
1113
  */
949
1114
  type ToolArgs<D extends number = 7> = z.ZodObject<ToolArgsRawShape<D>>;
950
1115
  /**
951
- * Raw shape for tenv schema - uses same pattern as ToolArgsRawShape.
952
- * Each key is a tenv name, value is a Zod schema for validation.
1116
+ * Variable declaration type.
1117
+ *
1118
+ * - `text`: Plain string configuration value
1119
+ * - `secret`: Sensitive value that should be encrypted at rest
1120
+ */
1121
+ type VariableType = 'text' | 'secret';
1122
+ /**
1123
+ * Declares a variable required or optionally consumed by a tool or prompt.
1124
+ */
1125
+ interface VariableDefinition {
1126
+ /** Environment variable/property name */
1127
+ name: string;
1128
+ /** Value type */
1129
+ type: VariableType;
1130
+ /** Whether this variable is required to execute */
1131
+ required: boolean;
1132
+ /**
1133
+ * Whether this variable is scoped to the declarer subtree.
1134
+ *
1135
+ * Scoped variables do not inherit parent thread env values. Descendants of
1136
+ * the declarer still inherit scoped values from that declarer thread.
1137
+ *
1138
+ * @default false
1139
+ */
1140
+ scoped?: boolean;
1141
+ /** Human-readable description (empty string when not provided) */
1142
+ description: string;
1143
+ }
1144
+ /**
1145
+ * Legacy raw shape for `tenvs` schema - uses same pattern as ToolArgsRawShape.
1146
+ * Each key is an environment variable name and each value is a Zod schema.
953
1147
  *
954
1148
  * @template D - Maximum nesting depth (default: 7)
955
1149
  */
@@ -958,19 +1152,23 @@ type TenvRawShape<D extends number = 7> = Record<string, ToolArgsNode<D>>;
958
1152
  * Top-level thread environment variable schema.
959
1153
  *
960
1154
  * Defines which thread environment variables a tool requires.
961
- * Required tenvs are non-optional fields, optional tenvs use .optional().
1155
+ * Required values are non-optional fields, optional values use `.optional()`.
962
1156
  *
963
1157
  * @example
964
1158
  * ```typescript
965
1159
  * z.object({
966
- * vectorStoreId: z.string().describe('OpenAI Vector Store ID'), // Required
967
- * userLocation: z.string().optional().describe('User location'), // Optional
1160
+ * VECTOR_STORE_ID: z.string().describe('OpenAI Vector Store ID'), // Required
1161
+ * USER_LOCATION: z.string().optional().describe('User location'), // Optional
968
1162
  * })
969
1163
  * ```
970
1164
  *
971
1165
  * @template D - Maximum nesting depth (default: 7)
972
1166
  */
973
1167
  type ToolTenvs<D extends number = 7> = z.ZodObject<TenvRawShape<D>>;
1168
+ /**
1169
+ * @deprecated Use VariableDefinition[] via the `variables` property instead.
1170
+ */
1171
+ type ToolVariables = VariableDefinition[];
974
1172
  /**
975
1173
  * Tool function signature.
976
1174
  *
@@ -1058,7 +1256,14 @@ interface DefineToolOptions<State = ThreadState, Args extends ToolArgs | null =
1058
1256
  args?: Args;
1059
1257
  /** The tool implementation function. */
1060
1258
  execute: UsesAwareExecute<State, Args, Uses>;
1061
- /** Zod schema for thread environment variables the tool requires. */
1259
+ /**
1260
+ * Variable declarations required/optionally used by this tool.
1261
+ */
1262
+ variables?: VariableDefinition[];
1263
+ /**
1264
+ * @deprecated Use `variables` instead.
1265
+ * Zod schema for thread environment variables the tool requires.
1266
+ */
1062
1267
  tenvs?: Tenvs;
1063
1268
  /**
1064
1269
  * Where this tool is executed:
@@ -1126,7 +1331,12 @@ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = nul
1126
1331
  args: Args;
1127
1332
  /** The tool implementation function. */
1128
1333
  execute: UsesAwareExecute<State, Args, Uses>;
1129
- /** Zod schema for thread environment variables, or null if none. */
1334
+ /** Declared variables for this tool. */
1335
+ variables: VariableDefinition[];
1336
+ /**
1337
+ * @deprecated Use `variables` instead.
1338
+ * Zod schema for thread environment variables, or null if none.
1339
+ */
1130
1340
  tenvs: Tenvs;
1131
1341
  /**
1132
1342
  * Where this tool is executed:
@@ -1160,7 +1370,7 @@ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = nul
1160
1370
  * Tools are the primary way agents interact with external systems.
1161
1371
  * Each tool has a description (shown to the LLM), optional argument
1162
1372
  * schema (validated at runtime), an implementation function, and
1163
- * optional thread environment variable (tenv) requirements.
1373
+ * optional variable requirements.
1164
1374
  *
1165
1375
  * @example
1166
1376
  * ```typescript
@@ -1188,14 +1398,19 @@ interface ToolDefinition<State = ThreadState, Args extends ToolArgs | null = nul
1188
1398
  * },
1189
1399
  * });
1190
1400
  *
1191
- * // Tool with tenvs (thread environment variables)
1401
+ * // Tool with declared variables
1192
1402
  * export default defineTool({
1193
1403
  * description: 'Search through uploaded files',
1194
1404
  * args: z.object({ query: z.string() }),
1195
1405
  * execute: async (state, args) => ({ status: 'success', result: 'done' }),
1196
- * tenvs: z.object({
1197
- * vectorStoreId: z.string().describe('OpenAI Vector Store ID'),
1198
- * }),
1406
+ * variables: [
1407
+ * {
1408
+ * name: 'VECTOR_STORE_ID',
1409
+ * type: 'text',
1410
+ * required: true,
1411
+ * description: 'OpenAI Vector Store ID',
1412
+ * },
1413
+ * ],
1199
1414
  * });
1200
1415
  *
1201
1416
  * // Provider-executed tool (e.g., OpenAI built-in tools)
@@ -1304,7 +1519,7 @@ interface LLMProviderInterface {
1304
1519
  * Optional - providers may implement this to expose built-in tools
1305
1520
  * (e.g., OpenAI's web_search, file_search, code_interpreter).
1306
1521
  *
1307
- * These tools are defined using defineTool() with optional tenv requirements.
1522
+ * These tools are defined using defineTool() with optional variable requirements.
1308
1523
  * Tools returned here can be referenced by name in model/prompt definitions.
1309
1524
  *
1310
1525
  * @param modelId - Optional filter to get tools available for a specific model
@@ -1553,6 +1768,8 @@ interface ProviderReasoningDetail {
1553
1768
  id?: string;
1554
1769
  text?: string;
1555
1770
  data?: string;
1771
+ /** Provider-specific format identifier (e.g., "google-gemini-v1", "openai-responses-v1") */
1772
+ format?: string;
1556
1773
  }
1557
1774
  /**
1558
1775
  * Web search result from provider
@@ -2035,11 +2252,21 @@ interface PromptIncludePart {
2035
2252
  /** The name of the prompt to include */
2036
2253
  prompt: StandardAgentSpec.Prompts;
2037
2254
  }
2255
+ /**
2256
+ * An environment variable insertion part.
2257
+ *
2258
+ * Loads a thread variable by property name at interpolation time.
2259
+ */
2260
+ interface PromptEnvPart {
2261
+ type: 'env';
2262
+ /** Variable property name to resolve from thread env */
2263
+ property: string;
2264
+ }
2038
2265
  /**
2039
2266
  * A single part of a structured prompt.
2040
2267
  * Discriminated union on `type` field for TypeScript narrowing.
2041
2268
  */
2042
- type PromptPart = PromptTextPart | PromptIncludePart;
2269
+ type PromptPart = PromptTextPart | PromptIncludePart | PromptEnvPart;
2043
2270
  /**
2044
2271
  * A structured prompt is an array of prompt parts.
2045
2272
  * Provides composition with other prompts via includes.
@@ -2134,12 +2361,12 @@ interface SubpromptConfig<T extends string = StandardAgentSpec.Callables> {
2134
2361
  type ToolConfig<T extends string = string> = SubpromptConfig<T>;
2135
2362
  /**
2136
2363
  * Configuration for a tool used in a prompt.
2137
- * Allows specifying tenv values and static options for the tool.
2364
+ * Allows specifying environment values and static options for the tool.
2138
2365
  *
2139
2366
  * @example
2140
2367
  * ```typescript
2141
- * // Tool with tenv values
2142
- * { name: 'file_search', tenvs: { vectorStoreId: 'vs_abc123' } }
2368
+ * // Tool with environment values
2369
+ * { name: 'file_search', env: { VECTOR_STORE_ID: 'vs_abc123' } }
2143
2370
  *
2144
2371
  * // Tool with options
2145
2372
  * { name: 'web_search', options: { searchContextSize: 'high' } }
@@ -2151,8 +2378,11 @@ interface PromptToolConfig {
2151
2378
  */
2152
2379
  name: StandardAgentSpec.Callables;
2153
2380
  /**
2154
- * Thread environment variable values for this tool.
2155
- * These values are merged with agent and thread tenvs (prompt tenvs are lowest priority).
2381
+ * Environment variable values for this tool.
2382
+ */
2383
+ env?: Record<string, string>;
2384
+ /**
2385
+ * @deprecated Use `env` instead.
2156
2386
  */
2157
2387
  tenvs?: Record<string, unknown>;
2158
2388
  /**
@@ -2161,6 +2391,146 @@ interface PromptToolConfig {
2161
2391
  */
2162
2392
  options?: Record<string, unknown>;
2163
2393
  }
2394
+ /**
2395
+ * Configuration for invoking a `dual_ai` agent as a subagent tool.
2396
+ *
2397
+ * Subagent tools are always autonomous `dual_ai` agents and support both:
2398
+ * - Blocking vs non-blocking execution
2399
+ * - Resumable vs non-resumable lifecycles
2400
+ *
2401
+ * Non-resumable subagents behave like normal tool calls.
2402
+ * Resumable subagents are created/messaged through runtime-injected lifecycle
2403
+ * tools (for example `subagent_create` and `subagent_message`) and tracked in
2404
+ * the parent thread registry.
2405
+ *
2406
+ * @example
2407
+ * ```typescript
2408
+ * {
2409
+ * name: 'browser_agent',
2410
+ * blocking: false,
2411
+ * resumable: {
2412
+ * receives_messages: 'side_a',
2413
+ * maxInstances: 1,
2414
+ * },
2415
+ * }
2416
+ * ```
2417
+ */
2418
+ interface SubagentToolConfig<T extends string = StandardAgentSpec.Callables> {
2419
+ /**
2420
+ * Agent callable name.
2421
+ *
2422
+ * Must reference a `dual_ai` agent with `exposeAsTool: true`.
2423
+ */
2424
+ name: T;
2425
+ /**
2426
+ * Whether parent execution blocks until the subagent returns a result.
2427
+ *
2428
+ * - `true`: Parent waits for completion (tool-call style)
2429
+ * - `false`: Parent continues immediately and receives results asynchronously
2430
+ *
2431
+ * @default true
2432
+ */
2433
+ blocking?: boolean;
2434
+ /**
2435
+ * Property from tool-call arguments used as the initial message sent to the
2436
+ * subagent on invocation.
2437
+ *
2438
+ * Uses the same semantics as {@link SubpromptConfig.initUserMessageProperty}.
2439
+ */
2440
+ initUserMessageProperty?: StandardAgentSpec.SchemaFields<T>;
2441
+ /**
2442
+ * Property from tool-call arguments containing attachment path(s) that should
2443
+ * be sent to the subagent on invocation.
2444
+ *
2445
+ * Uses the same semantics as {@link SubpromptConfig.initAttachmentsProperty}.
2446
+ */
2447
+ initAttachmentsProperty?: StandardAgentSpec.SchemaFields<T>;
2448
+ /**
2449
+ * Property from tool-call arguments used to assign a human-readable name for
2450
+ * each spawned child thread instance.
2451
+ *
2452
+ * Implementations SHOULD store this as a thread tag in the form
2453
+ * `name:<value>` so UIs can render a concise per-instance title.
2454
+ */
2455
+ initAgentNameProperty?: StandardAgentSpec.SchemaFields<T>;
2456
+ /**
2457
+ * Execute this tool immediately when the prompt becomes active.
2458
+ *
2459
+ * - `true`: Execute immediately using runtime defaults.
2460
+ * - Object: Execute immediately with explicit per-instance env relationships.
2461
+ *
2462
+ * When the object form is used:
2463
+ * - `scopedEnv` names the per-instance env values copied into the child thread.
2464
+ * - `nameEnv` and `descriptionEnv` identify the only per-instance env values
2465
+ * that runtimes may expose to an internal bootstrap model when deriving
2466
+ * initial child arguments.
2467
+ *
2468
+ * Runtimes MUST NOT expose `scopedEnv` values to the model unless the same env
2469
+ * name is explicitly designated by `nameEnv` or `descriptionEnv`.
2470
+ *
2471
+ * Immediate tools run before the first LLM step for that activation.
2472
+ */
2473
+ immediate?: boolean | {
2474
+ /**
2475
+ * Scoped env name whose value may be used as the safe per-instance name
2476
+ * hint for child bootstrap.
2477
+ */
2478
+ nameEnv?: string;
2479
+ /**
2480
+ * Scoped env name whose value may be used as the safe per-instance
2481
+ * description hint for child bootstrap.
2482
+ */
2483
+ descriptionEnv?: string;
2484
+ /**
2485
+ * Scoped env names that should be copied into the child thread for each
2486
+ * immediate instance group.
2487
+ */
2488
+ scopedEnv?: string[];
2489
+ };
2490
+ /**
2491
+ * Optional branch flag env name.
2492
+ *
2493
+ * When set, this subagent is only enabled when the named env resolves to
2494
+ * `true`, `1`, or `yes` (case-insensitive).
2495
+ */
2496
+ optional?: string;
2497
+ /**
2498
+ * Resumability configuration.
2499
+ *
2500
+ * - `false` (default): Non-resumable subagent
2501
+ * - Object: Resumable subagent with message routing and instance limits
2502
+ *
2503
+ * When resumable mode is enabled, runtimes SHOULD provide a built-in create
2504
+ * and message lifecycle interface instead of exposing raw agent callables for
2505
+ * new instance creation.
2506
+ */
2507
+ resumable?: false | {
2508
+ /**
2509
+ * Which side of the child `dual_ai` conversation receives parent messages.
2510
+ *
2511
+ * - `side_a`: Messages are queued as `role: 'user'`
2512
+ * - `side_b`: Messages are queued as `role: 'assistant'`
2513
+ */
2514
+ receives_messages: 'side_a' | 'side_b';
2515
+ /**
2516
+ * Maximum concurrent instances for this subagent tool.
2517
+ *
2518
+ * When reached, implementations may remove this tool from subsequent LLM
2519
+ * requests and route new messages to existing instances.
2520
+ *
2521
+ * @default unlimited
2522
+ */
2523
+ maxInstances?: number;
2524
+ /**
2525
+ * How this child reports back to its parent.
2526
+ *
2527
+ * - `implicit` (default): Child completion is automatically queued to the parent.
2528
+ * - `explicit`: The runtime does not auto-queue child completion; tools/hooks may
2529
+ * use thread APIs such as `state.notifyParent()` when they choose to escalate.
2530
+ */
2531
+ parentCommunication?: 'implicit' | 'explicit';
2532
+ };
2533
+ }
2164
2534
  /**
2165
2535
  * Reasoning configuration for models that support extended thinking.
2166
2536
  * Applies to models like OpenAI o1/o3, Anthropic Claude with extended thinking,
@@ -2286,12 +2656,17 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
2286
2656
  * Zod schema for validating inputs when this prompt is called as a tool.
2287
2657
  */
2288
2658
  requiredSchema?: S;
2659
+ /**
2660
+ * Declared variables for this prompt.
2661
+ */
2662
+ variables?: VariableDefinition[];
2289
2663
  /**
2290
2664
  * Tools available to this prompt.
2291
2665
  * Can be:
2292
2666
  * - string: Simple tool name (custom or provider tool)
2293
2667
  * - SubpromptConfig: Sub-prompt used as a tool
2294
- * - PromptToolConfig: Tool with tenv values and/or options
2668
+ * - PromptToolConfig: Tool with environment values and/or options
2669
+ * - SubagentToolConfig: `dual_ai` subagent invocation behavior
2295
2670
  *
2296
2671
  * To enable handoffs, include ai_human agent names in this array.
2297
2672
  *
@@ -2300,23 +2675,18 @@ interface PromptDefinition<N extends string = string, S extends ToolArgs = ToolA
2300
2675
  * tools: [
2301
2676
  * 'custom_tool', // Simple tool name
2302
2677
  * { name: 'other_prompt' }, // Sub-prompt as tool
2303
- * { name: 'file_search', tenvs: { vectorStoreId: 'vs_123' } }, // Tool with tenvs
2678
+ * { name: 'file_search', env: { VECTOR_STORE_ID: 'vs_123' } }, // Tool with env values
2304
2679
  * ]
2305
2680
  * ```
2306
2681
  */
2307
- tools?: (StandardAgentSpec.Callables | SubpromptConfig | PromptToolConfig)[];
2682
+ tools?: (StandardAgentSpec.Callables | SubpromptConfig | PromptToolConfig | SubagentToolConfig)[];
2308
2683
  /**
2309
- * Thread environment variables for this prompt.
2310
- * These values are merged with agent and thread tenvs when creating a thread.
2311
- * Prompt tenvs have lowest priority (overridden by agent and thread tenvs).
2312
- *
2313
- * @example
2314
- * ```typescript
2315
- * tenvs: {
2316
- * vectorStoreId: 'vs_default_123',
2317
- * apiEndpoint: 'https://api.example.com',
2318
- * }
2319
- * ```
2684
+ * Environment values provided by this prompt.
2685
+ * Prompt values are the lowest-precedence source in runtime resolution.
2686
+ */
2687
+ env?: Record<string, string>;
2688
+ /**
2689
+ * @deprecated Use `env` instead.
2320
2690
  */
2321
2691
  tenvs?: Record<string, unknown>;
2322
2692
  /**
@@ -2814,6 +3184,40 @@ declare function defineHook<K extends HookName>(options: HookDefinitionOptions<K
2814
3184
  * - `dual_ai`: Two AI participants conversing with each other
2815
3185
  */
2816
3186
  type AgentType = 'ai_human' | 'dual_ai';
3187
+ /**
3188
+ * Configuration for a session lifecycle tool.
3189
+ *
3190
+ * Used by side-level lifecycle options (`sessionStop`, `sessionFail`, `sessionStatus`)
3191
+ * to declare:
3192
+ * - which tool controls that lifecycle action
3193
+ * - which tool-argument field should be forwarded as message text
3194
+ * - which tool-argument field contains attachment path(s) to forward
3195
+ *
3196
+ * @template Callable - Callable name type
3197
+ */
3198
+ interface SessionToolConfig<Callable extends string = StandardAgentSpec.Callables> {
3199
+ /**
3200
+ * Tool name for this session lifecycle action.
3201
+ */
3202
+ name: Callable;
3203
+ /**
3204
+ * Optional tool-argument property used as lifecycle message text.
3205
+ */
3206
+ messageProperty?: string;
3207
+ /**
3208
+ * Optional tool-argument property containing attachment path(s).
3209
+ * Supports a single path string or an array of path strings.
3210
+ */
3211
+ attachmentsProperty?: string;
3212
+ }
3213
+ /**
3214
+ * Session lifecycle tool reference.
3215
+ *
3216
+ * Can be either:
3217
+ * - a plain tool name string (legacy/simple form)
3218
+ * - a {@link SessionToolConfig} object (explicit mapping form)
3219
+ */
3220
+ type SessionToolBinding<Callable extends string = StandardAgentSpec.Callables> = Callable | SessionToolConfig<Callable>;
2817
3221
  /**
2818
3222
  * Configuration for one side of an agent conversation.
2819
3223
  *
@@ -2873,10 +3277,62 @@ interface SideConfig<Prompt extends string = StandardAgentSpec.Prompts, Callable
2873
3277
  maxSteps?: number;
2874
3278
  /**
2875
3279
  * Tool that ends the entire session when called.
2876
- * Different from stopTool - this ends the session for both sides,
3280
+ *
3281
+ * Different from stopTool: this ends the session for both sides,
2877
3282
  * not just this side's turn.
3283
+ *
3284
+ * Use object form to explicitly map message/attachment argument fields.
3285
+ *
3286
+ * In subagent runtimes, mapped message/attachments are the canonical
3287
+ * completion payload returned from child -> parent.
3288
+ */
3289
+ sessionStop?: SessionToolBinding<Callable>;
3290
+ /**
3291
+ * Tool that fails the entire session when called.
3292
+ *
3293
+ * Use this when the side cannot fulfill the request and needs to terminate
3294
+ * the session with an error outcome.
3295
+ *
3296
+ * When used inside a subagent, this failure is propagated back to the parent
3297
+ * as a terminal failure result.
3298
+ *
3299
+ * Use object form to explicitly map message/attachment argument fields.
3300
+ *
3301
+ * In subagent runtimes, mapped message/attachments are the canonical
3302
+ * failure payload returned from child -> parent.
3303
+ */
3304
+ sessionFail?: SessionToolBinding<Callable>;
3305
+ /**
3306
+ * Tool that publishes status updates to the parent thread when used as a subagent.
3307
+ *
3308
+ * When called from a `dual_ai` subagent, message text is forwarded to
3309
+ * the parent thread's subagent registry as this instance's current status.
3310
+ *
3311
+ * Use object form to explicitly map message/attachment argument fields.
3312
+ *
3313
+ * Status updates do not terminate the session.
3314
+ *
3315
+ * @example
3316
+ * ```typescript
3317
+ * sideA: {
3318
+ * prompt: 'research_worker',
3319
+ * sessionStatus: { name: 'update_status', messageProperty: 'status' },
3320
+ * }
3321
+ * ```
3322
+ */
3323
+ sessionStatus?: SessionToolBinding<Callable>;
3324
+ /**
3325
+ * @deprecated Use sessionStop instead.
2878
3326
  */
2879
3327
  endSessionTool?: Callable;
3328
+ /**
3329
+ * @deprecated Use sessionFail instead.
3330
+ */
3331
+ failSessionTool?: Callable;
3332
+ /**
3333
+ * @deprecated Use sessionStatus instead.
3334
+ */
3335
+ statusTool?: Callable;
2880
3336
  }
2881
3337
  /**
2882
3338
  * Agent definition configuration.
@@ -2969,21 +3425,12 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
2969
3425
  */
2970
3426
  icon?: string;
2971
3427
  /**
2972
- * Thread environment variables for this agent.
2973
- * These values are merged with prompt and thread tenvs when creating a thread.
2974
- *
2975
- * Merge priority (later wins):
2976
- * 1. Prompt tenvs (lowest)
2977
- * 2. Agent tenvs (this field)
2978
- * 3. Thread tenvs (highest)
2979
- *
2980
- * @example
2981
- * ```typescript
2982
- * tenvs: {
2983
- * vectorStoreId: 'vs_agent_default',
2984
- * apiEndpoint: 'https://api.example.com',
2985
- * }
2986
- * ```
3428
+ * Environment values provided by this agent.
3429
+ * Agent values are lower priority than thread/account/instance values.
3430
+ */
3431
+ env?: Record<string, string>;
3432
+ /**
3433
+ * @deprecated Use `env` instead.
2987
3434
  */
2988
3435
  tenvs?: Record<string, unknown>;
2989
3436
  /**
@@ -3052,7 +3499,7 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
3052
3499
  * label: 'Support',
3053
3500
  * prompt: 'customer_support',
3054
3501
  * stopOnResponse: true,
3055
- * endSessionTool: 'close_ticket',
3502
+ * sessionStop: 'close_ticket',
3056
3503
  * },
3057
3504
  * exposeAsTool: true,
3058
3505
  * toolDescription: 'Hand off to customer support',
@@ -3076,7 +3523,7 @@ interface AgentDefinition<N extends string = string, Prompt extends string = Sta
3076
3523
  * label: 'Con',
3077
3524
  * prompt: 'debate_con',
3078
3525
  * stopOnResponse: true,
3079
- * endSessionTool: 'conclude_debate',
3526
+ * sessionStop: 'conclude_debate',
3080
3527
  * },
3081
3528
  * });
3082
3529
  * ```
@@ -3477,8 +3924,23 @@ interface PackedExports {
3477
3924
  models: Record<string, DefinitionLoader<ModelDefinition>>;
3478
3925
  /** Hook definitions, keyed by name */
3479
3926
  hooks: Record<string, DefinitionLoader<HookSignatures[keyof HookSignatures]>>;
3927
+ /**
3928
+ * Effect definitions, keyed by name.
3929
+ *
3930
+ * Optional for backward compatibility with previously packed packages.
3931
+ */
3932
+ effects?: Record<string, DefinitionLoader<EffectDefinition<any, any>>>;
3933
+ /**
3934
+ * Thread endpoint handlers, keyed by packed route key (for example, `status.get`).
3935
+ *
3936
+ * Runtimes typically mount these under a package namespace (for example:
3937
+ * `/api/packages/:packageId/threads/:id/...`) to avoid collisions.
3938
+ *
3939
+ * Optional for backward compatibility with previously packed packages.
3940
+ */
3941
+ threadEndpoints?: Record<string, DefinitionLoader<MarkedThreadEndpoint | Controller>>;
3480
3942
  /** Package metadata */
3481
3943
  __meta: PackedMeta;
3482
3944
  }
3483
3945
 
3484
- export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type MarkedThreadEndpoint, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type NamespaceContext, type PackageSignature, type PackedExports, type PackedMeta, type PackedMetadata, type PackedNamespaceContext, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUserMessage, type ProviderWebSearchResult, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type ScheduledEffect, type SideConfig, type StructuredPrompt, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type UsesAwareExecute, type UsesConstrainedState, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, isPacked, isThreadEndpoint, isVisibleInNamespace, mapReasoningLevel, validateToolName };
3946
+ export { type AgentDefinition, type AgentType, type AttachmentRef, type ContentPart, type Controller, type ControllerContext, type ControllerReturn, type DefineToolOptions, type DefinitionLoader, type Effect, type EffectDefinition, type EmptyUsesState, type ExecutionState, type FileChunk, type FilePart, type FileRecord, type FileStats, type FileStorage, type FindResult, type GetMessagesOptions, type GlobalNamespaceContext, type GrepResult, type HookContext, type HookDefinition, type HookDefinitionOptions, type HookDefinitionResult, type HookMessage, type HookName, type HookSignatures, type HookToolCall, type HookToolResult, type ImageContent, type ImagePart, type ImageUrlPart, type InferProviderOptions, type InjectMessageInput, type InspectedRequest, type LLMMessage, type LLMProviderInterface, type MarkedThreadEndpoint, type Message, type MessageUpdates, type MessagesResult, type ModelCapabilities, type ModelDefinition, type ModelProvider, type NamespaceContext, type PackageSignature, type PackedExports, type PackedMeta, type PackedMetadata, type PackedNamespaceContext, type PromptContent, type PromptDefinition, type PromptEnvPart, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type PromptToolConfig, type ProviderAssistantMessage, type ProviderAttachment, ProviderError, type ProviderErrorCode, type ProviderFactory, type ProviderFactoryConfig, type ProviderFactoryWithOptions, type ProviderFinishReason, type ProviderGeneratedImage, type ProviderInstance, type ProviderMessage, type ProviderMessageContent, type ProviderModelInfo, type ProviderReasoningDetail, type ProviderRequest, type ProviderResponse, type ProviderStreamChunk, type ProviderSystemMessage, type ProviderTool, type ProviderToolCallPart, type ProviderToolMessage, type ProviderToolResultContent, type ProviderUsage, type ProviderUserMessage, type ProviderWebSearchResult, type QueueMessageInput, type ReadFileStreamOptions, type ReaddirResult, type ReasoningConfig, type ResolveUsesState, type ResponseSummary, type ScheduledEffect, type SessionToolBinding, type SessionToolConfig, type SideConfig, type StructuredPrompt, type SubagentRegistryEntry, type SubagentToolConfig, type SubpromptConfig, THREAD_ENDPOINT_SYMBOL, type TenvRawShape, type TextContent, type TextPart, type ThreadEndpointHandler, type ThreadMetadata, type ThreadState, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolAttachment, type ToolConfig, type ToolContent, type ToolDefinition, type ToolResult, type ToolTenvs, type ToolVariables, type UsesAwareExecute, type UsesConstrainedState, type VariableDefinition, type VariableType, type VirtualModuleLoader, type VirtualModuleRegistry, type WriteFileOptions, belongsToPackage, defineAgent, defineController, defineEffect, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, isPacked, isThreadEndpoint, isVisibleInNamespace, mapReasoningLevel, validateToolName };