Member Junction
    Preparing search index...

    Collaborator extracted from BaseAgent (WS-4.5b) responsible for step and loop dispatching utilities: action/sub-agent invocation & result markdown formatting, structural JSON/code context-crush compression, sub-agent payload cloning and input/output path mapping, ForEach/While batching & sequential result folding, and loop template interpolation ({{item.field}}).

    Index

    Constructors

    Methods

    • Applies ForEach results sequentially to build the final payload in index order.

      Parameters

      • sortedResults: {
            appliedFolds?: { mapping: string; output: Record<string, unknown> }[];
            error?: LoopIterationError;
            index: number;
            payload?: unknown;
            result?: BaseAgentNextStep;
        }[]
      • initialPayload: unknown
      • continueOnError: boolean
      • OptionalclonePayloadFn: <T>(payload: T) => T

      Returns {
          errors: LoopIterationError[];
          finalPayload: unknown;
          results: BaseAgentNextStep[];
      }

    • Applies an action output mapping fold onto a cloned copy of basePayload.

      Parameters

      • basePayload: unknown
      • output: Record<string, unknown>
      • mapping: string
      • OptionalclonePayloadFn: <T>(payload: T) => T

      Returns Record<string, unknown>

    • Applies sub-agent input mapping to prepare initial payload for a related sub-agent.

      Parameters

      • parentPayload: Record<string, unknown>
      • mappingConfig: string
      • OptionalgetPathFn: (obj: unknown, path: string) => unknown

      Returns Record<string, unknown>

    • Applies sub-agent output mapping to update the parent payload.

      Type Parameters

      • P

      Parameters

      • subAgentResult: Record<string, unknown>
      • _parentPayload: Record<string, unknown>
      • mappingConfig: string
      • OptionalgetPathFn: (obj: unknown, path: string) => unknown

      Returns AgentPayloadChangeRequest<P>

    • Creates batches of items for parallel ForEach processing with their original indices.

      Type Parameters

      • T

      Parameters

      • items: T[]
      • maxConcurrency: number

      Returns { index: number; item: T }[][]

    • AST-reduce a large code-string action-result value when the agent opted into a code language (via crushCodeLang or a subclass override) and the value clears the size threshold. Returns reduced code plus a one-line legend, or null to keep the string verbatim (crushing disabled, too small, or no net saving).

      token optimization via @memberjunction/context-crush (CodeCompressor-inspired)

      Parameters

      Returns string

    • Structurally compress a JSON action-result value when crushing is enabled for the run and the value clears the size threshold. Accepts either the JSON.stringify of an object/array param, or a raw string param that itself contains JSON (many actions stringify their payloads, e.g. run-adhoc-query's Results). Returns crushed text plus a one-line legend, or null when crushing is disabled, the value is too small, the value isn't valid JSON, or compression wouldn't actually save characters — so callers fall back to verbatim (and, for strings, to code crushing) behavior.

      token optimization via @memberjunction/context-crush (SmartCrusher-inspired)

      Parameters

      Returns string

    • Formats an array of action result summaries as compact markdown instead of pretty-printed JSON. This typically saves 60-70% of the tokens that the old JSON.stringify(actionSummaries, null, 2) approach consumed, while remaining equally parseable by LLMs.

      Format per action:

      ## ActionName ✓          (or ✗ for failure)
      **Result:** RESULT_CODE — human message
      **Output:**
      • `ParamName`: value

      AI directives are intentionally omitted here because they are surfaced as a separate high-priority message (see the caller).

      Parameters

      Returns string

    • Formats loop iteration results as markdown. Handles two distinct result shapes depending on whether the loop body executed actions or sub-agents:

      • Action iterations: priorStepResult is an ActionResultSummary[], set by executeActionsStep(). These are formatted via FormatActionResultsAsMarkdown() (or formatActionResultsFn when supplied by BaseAgent).

      • Sub-agent iterations: priorStepResult is a pre-formatted markdown string, set by the loop handlers (executeSingleForEachIteration / executeSingleWhileIteration) which call formatSubAgentResultAsMarkdown() and assign the result to priorStepResult. Since the markdown is already rendered upstream, this method simply includes it as-is.

      This two-path design means sub-agent formatting happens at assignment time (in the loop handler), while action formatting happens at render time (here). Both produce the same markdown style used by non-loop results, ensuring consistency across the codebase.

      Parameters

      Returns string

    • Formats a parameter value for display in action execution messages.

      Parameters

      • value: unknown
      • maxLength: number = 100

      Returns string

    • Formats a single output parameter value for inclusion in action result markdown. Scalars are shown inline with backtick formatting; objects and arrays use compact (single-line) JSON to avoid the indentation overhead of pretty-printed JSON.

      By default, values are not truncated — the expiration/compaction lifecycle handles context window management. Truncating at formatting time permanently discards data before the LLM ever sees it. Pass an explicit maxLength only when you have a specific reason to limit output size.

      Parameters

      Returns string

    • Formats an ExecuteAgentResult as compact markdown for inclusion in conversation messages. Extracts only the fields that are meaningful to the calling agent (success, status, error, and payload) and presents them in a concise format.

      Parameters

      Returns string

    • Extracts an array collection from a payload path or a static:[...] literal. Strips "payload." prefix if present (for LLM convenience).

      Parameters

      • payload: unknown
      • path: string
      • OptionalgetPathFn: (obj: unknown, path: string) => unknown

      Returns unknown[]

    • Prepares a context message containing parent payload data or conversation messages for a related sub-agent.

      Parameters

      • parentPayload: Record<string, unknown>
      • contextPaths: string[]
      • Optionalparams: ExecuteAgentParams
      • OptionalgetPathFn: (obj: unknown, path: string) => unknown

      Returns ChatMessage

    • Resolves multiple {{expression}} placeholders embedded within a literal string.

      Unlike the single-variable path (which can return objects/numbers), this always returns a string because the resolved values are interpolated back into surrounding text.

      Parameters

      • template: string
      • context: Record<string, unknown>
      • itemVariable: string
      • OptionalresolveValue: (val: string, ctx: Record<string, unknown>, itemVar: string) => unknown

      Returns string

    • Resolves {{variable}} templates recursively across an object's string and array properties.

      resolveValue resolves each string; resolveNested resolves each nested object. BaseAgent binds both to its protected resolveValueFromContext / resolveTemplates, so a subclass override of either still runs at every depth. Without resolveNested, nested objects recurse here with the same resolveValue.

      Parameters

      • obj: Record<string, unknown>
      • context: Record<string, unknown>
      • itemVariable: string
      • OptionalresolveValue: (val: string, ctx: Record<string, unknown>, itemVar: string) => unknown
      • OptionalresolveNested: (
            nested: Record<string, unknown>,
            ctx: Record<string, unknown>,
            itemVar: string,
        ) => Record<string, unknown>

      Returns Record<string, unknown>

    • Resolves a single string value or {{expression}} reference from a loop iteration context.

      Handles both scalar and complex object iterations in ForEach / While loops:

      • Single-variable {{expr}} can return non-string values (objects, numbers, arrays).
      • Mixed literal strings containing {{expr}} delegate to ResolveInlineTemplateExpressions and return an interpolated string.
      • Exact itemVariable match ({{user}} or {{entityName}}) returns context.item directly.

      Parameters

      • value: string
      • context: Record<string, unknown>
      • itemVariable: string
      • Optionaloptions: {
            getPath?: (obj: unknown, path: string) => unknown;
            resolveInline?: (
                template: string,
                ctx: Record<string, unknown>,
                itemVar: string,
            ) => string;
        }

      Returns unknown