@standardagents/spec 0.38.2 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1647,7 +1647,7 @@ interface ExecutionState {
1647
1647
  readonly stopped: boolean;
1648
1648
  /** Which side initiated the stop (if stopped) */
1649
1649
  readonly stoppedBy?: 'a' | 'b';
1650
- /** Message history loaded for current execution */
1650
+ /** Live chronological persisted history for the current execution */
1651
1651
  readonly messageHistory: Message[];
1652
1652
  /**
1653
1653
  * Force a specific side to play the next turn.
@@ -1873,6 +1873,12 @@ interface ThreadState {
1873
1873
  *
1874
1874
  * Creates a new message in the conversation history. This can be used
1875
1875
  * to add context, simulate user input, or insert assistant responses.
1876
+ * Runs `before_create_message` and `after_create_message`. If a
1877
+ * `before_create_message` hook throws, the returned promise rejects and
1878
+ * no message is persisted. During active execution, the persisted message
1879
+ * becomes immediately visible through `execution.messageHistory`.
1880
+ * `silent` controls client presentation only; silent messages remain
1881
+ * eligible for model context.
1876
1882
  *
1877
1883
  * @param message - The message to inject
1878
1884
  * @returns The created message
@@ -3809,6 +3815,15 @@ interface PromptToolConfig {
3809
3815
  * a non-empty human-readable `name` argument and runtimes SHOULD persist it as
3810
3816
  * a child thread display name.
3811
3817
  *
3818
+ * Lifecycle tools manage resumable relationships exclusively: runtimes MUST
3819
+ * reject a `subagent_create` invocation that targets a relationship without
3820
+ * `resumable` configuration, without creating a child, and the rejection
3821
+ * SHOULD direct the model to invoke that tool directly instead. Runtimes
3822
+ * SHOULD constrain the injected tool's target argument to the exposed names
3823
+ * of the prompt's resumable relationships. Lifecycle tool references use the
3824
+ * relationship's exposed tool `name`, never an internal agent identifier that
3825
+ * differs from it.
3826
+ *
3812
3827
  * ### Pull-based child visibility
3813
3828
  *
3814
3829
  * Whenever resumable subagent configs exist, runtimes MUST also inject a
@@ -3851,14 +3866,39 @@ interface PromptToolConfig {
3851
3866
  * },
3852
3867
  * }
3853
3868
  * ```
3869
+ *
3870
+ * @example
3871
+ * ```typescript
3872
+ * // The same agent exposed under a task-specific tool name.
3873
+ * {
3874
+ * name: 'summarize_document',
3875
+ * agent: 'document_agent',
3876
+ * blocking: true,
3877
+ * initUserMessageProperty: 'message',
3878
+ * }
3879
+ * ```
3854
3880
  */
3855
3881
  interface SubagentToolConfig<T extends string = StandardAgentSpec.Callables> {
3856
3882
  /**
3857
- * Agent callable name.
3883
+ * Exposed tool name — the name the model invokes this subagent by.
3858
3884
  *
3859
- * Must reference a `dual_ai` agent with `exposeAsTool: true`.
3885
+ * When `agent` is absent, this MUST reference a `dual_ai` agent with
3886
+ * `exposeAsTool: true` directly. When `agent` is present, this may be any
3887
+ * valid tool identifier; the runtime MUST expose the tool under this name
3888
+ * and MUST resolve invocations to the agent named by `agent`.
3860
3889
  */
3861
- name: T;
3890
+ name: T | (string & {});
3891
+ /**
3892
+ * The `dual_ai` agent this tool invokes, when the tool is exposed under a
3893
+ * name other than the agent's own. Must reference a `dual_ai` agent with
3894
+ * `exposeAsTool: true`. Defaults to `name`.
3895
+ *
3896
+ * The same agent may be exposed under different tool names by different
3897
+ * prompts. Everything model-facing — the tool schema, instance registries,
3898
+ * and subagent lifecycle tool references — uses the exposed `name`;
3899
+ * runtimes resolve the implementing agent internally as `agent ?? name`.
3900
+ */
3901
+ agent?: T;
3862
3902
  /**
3863
3903
  * Whether parent execution blocks until the subagent returns a result.
3864
3904
  *
@@ -4384,10 +4424,14 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
4384
4424
  */
4385
4425
  after_system_message: (state: State, systemMessage: string) => string | Promise<string | null | undefined> | null | undefined;
4386
4426
  /**
4387
- * Called before messages are filtered and sent to the LLM.
4427
+ * Called exactly once per model-context assembly on a stable snapshot of
4428
+ * eligible persisted history.
4388
4429
  *
4389
4430
  * Receives raw message rows from storage before any transformation.
4390
4431
  * Use for filtering, sorting, or augmenting message history.
4432
+ * The result is the request context and does not replace
4433
+ * `state.execution.messageHistory`. Messages injected while this hook runs
4434
+ * become eligible for the following context assembly.
4391
4435
  *
4392
4436
  * @param state - Thread state
4393
4437
  * @param messages - Array of messages from storage
@@ -4404,10 +4448,12 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
4404
4448
  */
4405
4449
  filter_messages: (state: State, messages: Msg[]) => Promise<Msg[]>;
4406
4450
  /**
4407
- * Called after message history is loaded and before sending to LLM.
4451
+ * Called after filtered history is transformed into provider messages and
4452
+ * before dispatch.
4408
4453
  *
4409
4454
  * Receives messages already transformed into chat completion format.
4410
- * Use for final adjustments before LLM request.
4455
+ * Use for final request-local adjustments. Messages injected while this
4456
+ * hook runs become eligible for the following context assembly.
4411
4457
  *
4412
4458
  * @param state - Thread state
4413
4459
  * @param messages - Array of LLM-formatted messages
@@ -4429,6 +4475,10 @@ interface HookSignatures<State = ThreadState, Msg = HookMessage, ToolCall = Hook
4429
4475
  * Receives the full message object before insertion. Return modified
4430
4476
  * message to transform before storage.
4431
4477
  *
4478
+ * A hook that throws during `injectMessage()` rejects the injection and
4479
+ * no message is persisted. Other runtime insertions log the failure and
4480
+ * keep the last good message.
4481
+ *
4432
4482
  * @param state - Thread state
4433
4483
  * @param message - Message to be created
4434
4484
  * @returns Modified message