Member Junction
    Preparing search index...

    Type Alias BaseAgentNextStep<P, TContext>

    Represents the next step determination from an agent type.

    Agent types analyze the output of prompt execution and determine what should happen next in the agent workflow. This type encapsulates that decision along with any necessary context for the determined action.

    type BaseAgentNextStep<P = any, TContext = any> = {
        actionableCommands?: ActionableCommand[];
        actions?: AgentAction[];
        artifactToolCalls?: {
            artifactId: string;
            input: Record<string, unknown>;
            tool: string;
        }[];
        automaticCommands?: AutomaticCommand[];
        clientTools?: AgentClientToolInvocation[];
        confidence?: number;
        conversationToolCalls?: { input: Record<string, unknown>; tool: string }[];
        errorMessage?: string;
        expandReason?: string;
        forEach?: ForEachOperation;
        memoryWrites?: {
            note: string;
            scopeHint?: "user" | "agent";
            type: "Preference" | "Context";
        }[];
        message?: string;
        messageIndex?: number;
        newPayload?: P;
        payloadChangeRequest?: AgentPayloadChangeRequest<P>;
        pipeline?: AgentPipelineRequest;
        planDetails?: { plan: string };
        previousPayload?: P;
        priorStepResult?: any;
        promoteMediaOutputs?: MediaOutput[];
        reasoning?: string;
        responseForm?: AgentResponseForm;
        retryInstructions?: string;
        retryReason?: string;
        scratchpad?: AgentScratchpad;
        skillActivations?: AgentSkillActivationRequest[];
        step: MJAIAgentRunEntityExtended["FinalStep"];
        subAgent?: AgentSubAgentRequest<TContext>;
        subAgents?: AgentSubAgentRequest<TContext>[];
        terminate: boolean;
        terminateAfterExecution?: boolean;
        while?: WhileOperation;
    }

    Type Parameters

    • P = any

      Type of the payload value, allowing flexibility in the type of data returned

    • TContext = any

      Type of the context object used for sub-agent requests. This ensures type safety when passing context to sub-agents. Defaults to any for backward compatibility.

    Index

    Properties

    actionableCommands?: ActionableCommand[]

    Optional actionable commands shown as clickable buttons/links. Typically used after completing work to provide easy navigation to created/modified resources.

    2.116.0

    actions?: AgentAction[]

    Array of actions to execute when step is 'actions'

    artifactToolCalls?: {
        artifactId: string;
        input: Record<string, unknown>;
        tool: string;
    }[]

    Artifact tool calls from the agent's response. Each entry identifies an artifact and the tool to execute against it. Processed inline (zero turn cost) alongside payload and scratchpad changes.

    automaticCommands?: AutomaticCommand[]

    Optional automatic commands executed immediately when received. Used for refreshing data, showing notifications, and updating UI state.

    2.116.0

    Client-side tools to execute when step is 'ClientTools'. Each invocation maps to a registered ClientToolMetadata by Name.

    confidence?: number

    Optional confidence level in the decision (0.0 to 1.0)

    conversationToolCalls?: { input: Record<string, unknown>; tool: string }[]

    Conversation-history retrieval tool calls from the agent's response — page exact stored messages back in by their persisted Sequence handles, or search history. Processed inline (zero turn cost) alongside artifact tool calls; only honored when the run has a conversationId. NOTE: structural duplicate of ConversationToolCall in @memberjunction/ai-agents (CorePlus sits below Agents and cannot import from it), mirroring how artifactToolCalls duplicates ArtifactToolCall above.

    errorMessage?: string

    Error message when step is 'failed'

    expandReason?: string

    Reason for expanding the message when step is 'expand-message'

    ForEach operation details when step is 'ForEach' (v2.112+)

    memoryWrites?: {
        note: string;
        scopeHint?: "user" | "agent";
        type: "Preference" | "Context";
    }[]

    Durable memory writes from the agent's response. Each entry records a fact/preference that persists across runs as a provisional agent note. Processed inline (zero turn cost) alongside artifact tool calls; only honored when the agent has AllowMemoryWrite enabled. NOTE: structural duplicate of MemoryWriteRequest in @memberjunction/ai-agents (CorePlus sits below Agents and cannot import from it), mirroring how artifactToolCalls duplicates ArtifactToolCall above.

    message?: string

    Message to send to user when step is 'chat'

    messageIndex?: number

    Index of the message to expand when step is 'expand-message'

    newPayload?: P

    This represents the new payload after the step was executed after the payloadChangeRequest is applied.

    payloadChangeRequest?: AgentPayloadChangeRequest<P>

    Payload change request from the agent. Framework will apply these changes to the previous payload to create the new state. This approach ensures safe state mutations and prevents data loss from LLM truncation.

    A tool pipeline from the agent's response. Chains tool invocations server-side so intermediate outputs never enter the context window — only the final step's output is returned to the agent. Processed inline (zero turn cost) alongside artifact tool calls.

    planDetails?: { plan: string }

    The plan text when step is 'Plan' (Plan Mode). Presented to the human for approval/edit via the standard response-form HITL flow before the agent may execute Actions/Sub-Agents.

    previousPayload?: P

    The payload that was passed into this step execution. Useful for debugging and understanding what state the agent was working with.

    Use payloadChangeRequest instead for state mutations

    priorStepResult?: any

    Result from the prior step, useful for retry or sub-agent context

    promoteMediaOutputs?: MediaOutput[]

    Media outputs to promote to the agent's final outputs. When set, these media items will be added to the agent's mediaOutputs collection and stored in AIAgentRunMedia.

    3.1.0

    reasoning?: string

    Optional, reasoning information from the agent

    responseForm?: AgentResponseForm

    Optional response form to collect structured user input. When present, the UI will render appropriate input controls based on question types. Use for collecting information from users during agent execution.

    2.116.0

    retryInstructions?: string

    Instructions for the retry attempt, including any new context or results

    retryReason?: string

    Reason for retry when step is 'retry' (e.g., "Processing action results", "Handling error condition")

    scratchpad?: AgentScratchpad

    Scratchpad changes from the agent's response. Processed inline (zero turn cost) alongside payload changes.

    2.46.0

    skillActivations?: AgentSkillActivationRequest[]

    Skills to activate when step is 'Skill'. Each activation appends the skill's Instructions to context and enables its bundled Actions/sub-agents for the remainder of the run — it does not spawn a nested agent run.

    The determined next step:

    • 'success': The agent has completed its task successfully
    • 'failed': The agent has failed to complete its task
    • 'retry': The agent should re-run to either: a) Process new results from completed actions or sub-agents b) Retry after a failure condition c) Continue processing with updated context d) Process after expanding a compacted message (when messageIndex is set)
    • 'sub-agent': The agent should spawn a sub-agent to handle a specific task
    • 'actions': The agent should perform one or more actions using the Actions framework
    • 'chat': The agent needs to communicate with the user before proceeding
    • 'Skill' / 'Plan': non-terminal steps (like 'ClientTools') that never conclude a run, so they are NOT part of the generated MJAIAgentRun.FinalStep union below. Use an explicit 'Skill' as typeof nextStep.step / 'Plan' as typeof nextStep.step assertion at assignment/switch sites, mirroring the existing 'ClientTools' pattern.

    Note: To expand a compacted message, set step to 'Retry', set messageIndex to the message to expand, and optionally set expandReason to explain why expansion is needed. The framework will expand the message and then continue with the retry.

    Sub-agent details when step is 'sub-agent'

    Multiple sub-agents executing in parallel when step is 'sub-agent'

    terminate: boolean

    Whether to terminate the agent execution after this step

    terminateAfterExecution?: boolean

    When true, the agent should terminate after executing the current step. Used by ClientTools: the main loop needs terminate: false so it continues to dispatch the tool execution, but executeClientToolsStep checks this to decide whether to return Success or continue to another prompt.

    While operation details when step is 'While' (v2.112+)