Member Junction
    Preparing search index...

    Implementation of the Flow Agent Type pattern.

    This agent type enables deterministic workflow execution where agents follow predefined paths through a graph of steps. Key features:

    • Graph-based workflow definition
    • Conditional path evaluation using safe boolean expressions
    • Support for Actions, Sub-Agents, and Prompts as step types
    • Deterministic execution with optional AI-driven decision points

    FlowAgentType

    // Flow agents execute steps based on graph structure
    const flowAgent = new FlowAgentType();
    const nextStep = await flowAgent.DetermineNextStep(promptResult, payload);

    // Steps are determined by evaluating path conditions
    // Path: "payload.status == 'approved' && payload.amount < 1000"
    // Leads to: "Auto-Approve" step

    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 SupportsNativeToolCalls(): boolean

      Whether this agent type can read a native tool call back as a step (plan §8.1).

      BaseAgent declares an agent's Actions as native tools ONLY when this is true. Declaring them to a type that cannot consume the call is not harmless: the model answers with a tool call and no text, the type's DetermineNextStep parses the empty text, and the turn becomes a Retry — a run that would have worked on the envelope path fails because tools were offered. That is exactly the failure a catalog-wide DefaultToNativeToolCalling would have produced on every Flow agent with Actions.

      Defaults to false. A type opts in by overriding this AND by honouring the nativeToolBindings argument of DetermineNextStep; the two go together, and LoopAgentType is the only type that does both today.

      Returns boolean

    Methods

    • Flow agents apply ActionOutputMapping after each iteration

      Type Parameters

      • P

      Parameters

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

      Returns P

    • 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

    • Compiles the flow and hands it to the task-graph dispatcher (C1.3).

      This is the whole of a Flow agent's execution now. The agent does not walk its own graph; it compiles its persisted steps and paths into a TaskGraphSpec and returns a Tasks step, which BaseAgent.executeTasksStep submits and detaches from. Everything after that — claiming, conditions, exclusive choice, skip cascade, retry, failure semantics — belongs to the dispatcher, which is the point: one traversal engine, one set of rules, one place a bug can be fixed. The in-run walker below is retained as the differential suite's oracle and is unreachable at runtime (see refuseInRunFlowExecution).

      Compile failures are authoring failures, and are reported as such. A flow with no starting step or a loop in it is something the user can fix in the editor, so the message names the step and the problem rather than reporting an internal error.

      Type Parameters

      • P = any
      • ATS = any

      Parameters

      Returns Promise<BaseAgentNextStep<P>>

      The Tasks step carrying the compiled graph

      2.76.0

    • Removes a markdown code fence WRAPPING an entire response, if one is present.

      Models fenced their JSON long before this existed — the retry feedback in LoopAgentType already tells them not to — but a retry costs a whole turn to recover something we already received intact. Observed with an external harness: the response was perfectly valid {"taskComplete": true, ...} inside a ```json fence, rejected by JSON.parse, and the identical answer came back on the retry. Half the latency and half the cost of that run bought nothing.

      It strips ONLY the first line and the trailing fence, never anything interior. A response's own payload frequently contains fenced code — the case that prompted this had ```haskell blocks inside its message string — so a global strip would corrupt exactly the responses it was meant to rescue.

      The stripped text is only used if it PARSES. On failure the original is returned untouched, so the outcome is either "an unparseable response became parseable" or "no change" — never a previously-good response turned bad. Deterministic, no model call, microseconds.

      Parameters

      • raw: string

      Returns string