Member Junction
    Preparing search index...

    Class BaseAgentTypeAbstract

    Abstract base class for agent type implementations.

    Agent types define reusable execution patterns that control how agents behave. Each agent type is associated with a system prompt that guides the LLM's output format and decision-making process. Common agent type patterns include:

    • Loop: Continues executing until a goal is achieved
    • SinglePass: Executes once and returns a result
    • DecisionTree: Makes branching decisions based on conditions
    • Pipeline: Executes a series of steps in sequence

    The agent type's system prompt should be designed to produce output that can be parsed by the DetermineNextStep method to decide what happens next in the agent's execution flow.

    BaseAgentType

    export class LoopAgentType extends BaseAgentType {
    public async DetermineNextStep(): Promise<BaseAgentNextStep> {
    // Parse LLM output to determine if goal is achieved
    const goalAchieved = // ... parsing logic

    return {
    step: goalAchieved ? 'success' : 'action',
    payload: result
    };
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _jsonValidator: JSONValidator = ...

    JSON validator instance for cleaning and validating responses

    CURRENT_PAYLOAD_PLACEHOLDER: "_CURRENT_PAYLOAD" = '_CURRENT_PAYLOAD'

    Common placeholder for current payload injection

    Accessors

    • get InjectLoopResultsAsMessage(): boolean

      Determines if loop results should be injected as a temporary user message before the next prompt execution (for LLM reasoning).

      Default: true (most agent types benefit from seeing loop results) Flow agents override to false (deterministic path navigation, no LLM)

      Returns boolean

      true to inject results as message, false to skip

      2.112.0

    • get RequiresAgentLevelPrompts(): boolean

      Indicates whether this agent type requires agent-level prompts (AI Agent Prompts relationship).

      Some agent types (like Flow) use step-level prompts exclusively and don't need agent-level prompts. Other agent types (like Loop) require agent-level prompts for their main reasoning loop.

      Default: true (most agent types require agent-level prompts)

      Returns boolean

      True if agent-level prompts are required, false if optional

      2.113.0

    Methods

    • Called after each loop iteration completes to process results.

      Flow agents use this to apply ActionOutputMapping and update payload. Loop agents typically don't need this (just collect results).

      Type Parameters

      • P

      Parameters

      • iterationResult: {
            actionResults?: ActionResult[];
            currentPayload: P;
            index: number;
            item: any;
            itemVariable: string;
            loopContext: any;
            subAgentResult?: any;
        }

        Results from this iteration

      Returns P

      Modified payload or null for default behavior (just collect result)

      2.112.0

    • Called before each loop iteration to prepare parameters and payload.

      Loop agents use this to resolve template variables ("item.email"). Flow agents typically don't need this (params already resolved).

      Type Parameters

      • P

      Parameters

      • context: {
            actionParams: Record<string, unknown>;
            index: number;
            item: any;
            itemVariable: string;
            loopType: "ForEach" | "While";
            payload: P;
            subAgentRequest?: {
                message: string;
                name: string;
                templateParameters?: Record<string, string>;
            };
        }

        Current iteration context

      Returns {
          actionParams?: Record<string, unknown>;
          payload?: P;
          subAgentRequest?: {
              message: string;
              name: string;
              templateParameters?: Record<string, string>;
          };
      }

      Modified context or null for default behavior

      2.112.0

    • Protected

      Creates a standardized next step object with common defaults

      Type Parameters

      • P

        The payload type

      Parameters

      • step:
            | "Actions"
            | "Chat"
            | "Failed"
            | "ForEach"
            | "Retry"
            | "Sub-Agent"
            | "Success"
            | "While"

        The step type

      • options: Partial<BaseAgentNextStep<P>> = {}

        Additional options to merge

      Returns BaseAgentNextStep<P>

      The next step object

    • Determines the initial step when no previous decision exists.

      This method allows agent types to customize how they begin execution. For example:

      • Loop agents might execute a prompt to determine initial actions
      • Flow agents might look up their starting step from configuration
      • Pipeline agents might execute the first step in their sequence

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      • params: ExecuteAgentParams<P>

        The full execution parameters including agent, payload, and context

      • payload: P
      • agentTypeState: ATS

      Returns Promise<BaseAgentNextStep<P>>

      The initial step, or null to use default behavior (prompt execution)

      2.76.0

    • Analyzes the output from prompt execution to determine the next step.

      This method is called after the hierarchical prompts have been executed and should parse the LLM's response to determine what the agent should do next. The implementation depends on the specific agent type's logic and the format of output expected from its system prompt.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      • promptResult: AIPromptRunResult<unknown>

        Result from prompt execution (null for non-prompt steps)

      • params: ExecuteAgentParams<any, P>

        The full execution parameters including agent and context

      • payload: P
      • agentTypeState: ATS

      Returns Promise<BaseAgentNextStep<P>>

      The determined next step and optional return value

      public async DetermineNextStep(): Promise<BaseAgentNextStep> {
      // Implementation might parse JSON output from LLM
      const response = JSON.parse(this.lastExecutionResult);

      if (response.taskComplete) {
      return { step: 'success', payload: response.payload };
      } else if (response.needsSubAgent) {
      return { step: 'subagent', payload: response.subAgentConfig };
      } else {
      return { step: 'action', payload: response.nextAction };
      }
      }
    • Provides agent-type-specific guidance for configuration errors related to missing prompts. This allows each agent type to give contextual help based on its architecture.

      Default implementation provides generic guidance. Agent types should override to provide specific instructions relevant to their configuration requirements.

      Returns string

      Configuration guidance specific to this agent type

      2.113.0

    • Allows agent types to provide a custom prompt for a specific step. This is used by agent types that need to override the default prompt selection logic (e.g., Flow agents that use different prompts for different steps).

      The base implementation should return the default prompt from configuration. Agent types can override this to provide custom prompt selection logic.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      Returns Promise<MJAIPromptEntityExtended>

      A prompt entity to use (either custom or config.childPrompt)

      2.76.0

    • Determines how to handle Success or Failed steps when no explicit termination is requested.

      This allows agent types to control their own fallback behavior:

      • Loop agents use default behavior (return null) to process results with their main prompt
      • Flow agents should terminate instead of falling back to prompts (return terminate step)
      • Pipeline agents might want to move to the next stage

      Default implementation returns null, which causes base-agent to fall back to prompt execution if prompts are configured. Agent types can override this to provide custom behavior.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      Returns Promise<BaseAgentNextStep<P>>

      Custom step to execute, or null for default behavior

      2.113.0

    • This method allows each agent type to initialize its agent-run-specific state package as required. Not all agent types require this and are able to live off just the current payload or other properties passed to them to DetermineNextStep(), but some require more complex internal state tracking.

      Type Parameters

      • ATS = any
      • P = any

      Parameters

      Returns Promise<ATS>

      the fully initialized initial agent-type state

    • The agent type is responsible for injecting a payload into the prompt. This can be done by updating the system prompt by replacing a special non-Nunjucks placeholder, or by adding extra messages to the prompt.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      • payload: P

        The payload to inject

      • agentTypeState: ATS
      • prompt: AIPromptParams

        The prompt parameters to update

      • agentInfo: { agentId: string; agentRunId?: string }

        Agent identification info including agent ID and run ID

      Returns Promise<void>

    • Post-processes the result of action execution.

      This method is called by BaseAgent after action(s) have been executed. Agent types can override this method to perform custom processing of action results, such as mapping output parameters to the payload or storing results in agent-specific context.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      • actionResults: ActionResult[]

        The results from action execution

      • actions: AgentAction[]

        The actions that were executed

      • currentPayload: P

        The current payload

      • agentTypeState: ATS
      • currentStep: BaseAgentNextStep<P>

        The current step being executed

      Returns Promise<AgentPayloadChangeRequest<P>>

      Optional payload change request

      2.76.0

    • Post-processes the result of sub-agent execution.

      This method is called by BaseAgent after a sub-agent has been executed. Agent types can override this method to perform custom processing of sub-agent results, such as extracting specific data from the sub-agent's payload or updating context.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      • subAgentResult: any

        The result from sub-agent execution

      • subAgentRequest: AgentSubAgentRequest

        The sub-agent request that was executed

      • currentPayload: P

        The current payload

      • agentTypeState: ATS
      • currentStep: BaseAgentNextStep<P>

        The current step being executed

      Returns Promise<AgentPayloadChangeRequest<P>>

      Optional payload change request

      2.76.0

    • Pre-processes an action step before execution.

      This method is called by BaseAgent before action(s) are executed. Agent types can override this method to perform custom pre-processing, such as mapping payload values to action input parameters or modifying action configurations.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      Returns Promise<void>

      Actions are modified in place

      2.76.0

    • Pre-processes a retry step to allow agent types to customize retry behavior.

      This method is called when the previous step returned 'Retry' as the next step. Agent types can override this to provide custom behavior instead of the default prompt execution. This is particularly useful for:

      • Flow agents that need to evaluate paths after action execution
      • State machine agents that need to transition based on results
      • Pipeline agents that need to move to the next stage

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      Returns Promise<BaseAgentNextStep<P>>

      Custom next step, or null to use default retry behavior (prompt execution)

      2.76.0

    • Protected

      Instantiates an agent type class using a specific driver class name.

      This method is used when an individual agent has its own DriverClass override, allowing for specialized implementations per agent instance.

      Parameters

      • driverClass: string

        The driver class name to instantiate

      Returns Promise<BaseAgentType>

      Instance of the agent type class

    • Protected

      Instantiates the appropriate agent type class based on the agent type entity.

      This method uses the MemberJunction class factory to dynamically instantiate agent type classes. It uses the DriverClass field. If DriverClass is not specified it throws an error.

      Parameters

      Returns Promise<BaseAgentType>

      Instance of the agent type class

      // For an agent type with DriverClass "LoopAgentType"
      const agentTypeInstance = await this.getAgentTypeInstance(loopAgentType);

      @protected
    • Helper method that retrieves an instance of the agent type based on the provided agent type entity.

      This method uses the ClassFactory to create an instance of the agent type class specified in the DriverClass field of the agent type entity. If the DriverClass is not specified, it throws an error.

      Parameters

      Returns Promise<BaseAgentType>

      An instance of the agent type class

      GetAgentTypeInstance

      If the agent type does not have a DriverClass specified or if instantiation fails