Skip to content

AgentForceWorkflow


AgentForceWorkflow Workflow Class Multi-Agent

Technical documentation for the AgentForceWorkflow class structure and API.

/**
* Represents a workflow instance within the AgentForce framework.
* This class provides the core functionality for creating and managing workflows.
*
* @class AgentForceWorkflow
*/
import {
prompt,
dispatcher,
registerAgent,
sharedStore,
sequence,
parallel,
onSuccess,
onFail,
iterate,
run,
loop,
debug,
} from "./workflow/mod";
import type { WorkflowConfig, AgentForceLogger } from "./types";
import type { AgentForceAgent } from "./agent";
import { defaultLogger } from "./logger";
constructor(config: WorkflowConfig)

Parameters:

  • config: WorkflowConfig - Configuration object containing workflow initialization settings

Description: Constructs the AgentForceWorkflow class with the provided configuration. Initializes the workflow’s name and logger from the config object.

private name: string;
private logger: AgentForceLogger;
protected userPrompt: string = "";
protected dispatcherAgent: AgentForceAgent | null = null;
protected agents: { name: string, agent: AgentForceAgent, outputs: AgentOutput[], tools: string[] }[] = [];
protected executionPlan: ExecutionStep[] = [];
protected agentToolRegistry: Map<string, string[]> = new Map(); // Maps agent name to tool names
protected internalSharedStore: Map<string, any> = new Map();
protected getUserPrompt(): string
protected getDispatcher(): AgentForceAgent | null
protected setUserPrompt(prompt: string): void
protected setDispatcher(agent: AgentForceAgent): void
protected setSharedStoreItem(key: string, value: any): void
protected pushAgent(name: string, agent: AgentForceAgent, outputs: AgentOutput[], tools: string[]): void
public getName(): string
public getLogger(): AgentForceLogger
public getSharedStoreItem(key: string): any

Returns AgentForceWorkflow instance for method chaining:

prompt(userPrompt: string): AgentForceWorkflow
dispatcher(agent: AgentForceAgent): AgentForceWorkflow
registerAgent(agent: AgentForceAgent): AgentForceWorkflow
sharedStore(key: string, value: any): AgentForceWorkflow
sequence(agents: AgentForceAgent[]): AgentForceWorkflow
parallel(agents: AgentForceAgent[]): AgentForceWorkflow
onSuccess(agent: AgentForceAgent): AgentForceWorkflow
onFail(agent: AgentForceAgent): AgentForceWorkflow
iterate(items: any[] | string, agent: AgentForceAgent): AgentForceWorkflow
debug(): AgentForceWorkflow

Execute the workflow and return results (ends the chain):

run(): Promise<any>
loop(delayInMs?: number): void

All public methods are bound to their respective implementations from the ./workflow/mod module:

// Chainable methods
public prompt: (userPrompt: string) => AgentForceWorkflow = prompt.bind(this);
public dispatcher: (agent: AgentForceAgent) => AgentForceWorkflow = dispatcher.bind(this);
public registerAgent: (agent: AgentForceAgent) => AgentForceWorkflow = registerAgent.bind(this);
public sharedStore: (key: string, value: any) => AgentForceWorkflow = sharedStore.bind(this);
public sequence: (agents: AgentForceAgent[]) => AgentForceWorkflow = sequence.bind(this);
public parallel: (agents: AgentForceAgent[]) => AgentForceWorkflow = parallel.bind(this);
public onSuccess: (agent: AgentForceAgent) => AgentForceWorkflow = onSuccess.bind(this);
public onFail: (agent: AgentForceAgent) => AgentForceWorkflow = onFail.bind(this);
public iterate: (items: any[] | string, agent: AgentForceAgent) => AgentForceWorkflow = iterate.bind(this);
public debug: () => AgentForceWorkflow = debug.bind(this);
// Execute methods
public run: () => Promise<any> = run.bind(this);
public loop: (delayInMs?: number) => void = loop.bind(this);