import type * as ElevenLabs from "../../../api/index"; import type { Tool } from "../tools/Tool"; import { type ConditionInput } from "./Condition"; import { type WorkflowIssue } from "./errors"; import { type EdgeOrigin, type WhenOptions, WorkflowBranch, WorkflowChain, WorkflowNode } from "./WorkflowNode"; export interface WorkflowOptions { /** Stop the conversation from re-entering a subagent it already visited. */ preventSubagentLoops?: boolean; } export interface BuildOptions { /** Called for each non-fatal problem, such as a node that can't be reached from the start. */ onWarning?: (issue: WorkflowIssue) => void; /** * The id of each `Tool` object the workflow references, by tool name. `agents.push()` passes these after * creating the tools. Every `Tool` object needs one. */ toolIds?: Record; } /** * An agent workflow, written as code. The workflow itself is the start node: calling a verb on it branches * from the start. * * @example * const wf = new Workflow(); * const triage = wf.converse("triage", "Find out what the caller needs"); * const lookup = triage.when("Caller gave an order number").tool("lookup_order", ["tool_123"]); * lookup.onSuccess().converse("resolve", "Explain the order status").end(); * lookup.onFailure().transfer("human", Destination.phone("+15551234567")); * * await client.conversationalAi.agents.update(agentId, { workflow: wf.build() }); */ export declare class Workflow extends WorkflowChain { constructor(options?: WorkflowOptions); /** * Loads the workflow of an existing agent so it can be edited. Accepts the result of `agents.get()` or its * `workflow` field. Node ids, editor positions and edge order are kept. */ static fromAgent(agent: ElevenLabs.GetAgentResponseModel | ElevenLabs.AgentWorkflowResponseModel): Workflow; /** * Loads a workflow stored as API-format JSON (snake_case), for example from `toJSONString()` or a CLI * `agent_configs/*.json` file. Accepts a JSON string or a parsed object, holding either the workflow itself or * a whole agent config with a `workflow` key. Tool ids found in `toolsById` are swapped for those `Tool` objects, * so the loaded workflow refers to them as a built one would; other ids stay as they are. */ static fromJSON(json: string | object, options?: { toolsById?: Map; }): Workflow; /** The id of the start node: `"start_node"`, the id the API requires, or whatever a loaded workflow uses. */ get startId(): string; /** Opens a branch from the start node that is followed when `condition` holds. A string is an LLM condition. */ when(condition: ConditionInput, options?: WhenOptions): WorkflowBranch; /** A handle to an existing node, for editing it or going to it. */ node(id: string): WorkflowNode; /** The `Tool` objects the workflow's nodes reference, in the order they were first used. */ tools(): Tool[]; /** Ids of every node, in the order they were added. */ get nodeIds(): string[]; /** Removes a node and every edge to or from it. */ remove(id: string): this; /** * Splices new nodes into the edge from `sourceId` to `targetId`. `insert` receives a branch carrying that * edge's forward condition and returns the last new node, which is then connected to `targetId`. Returns that * node, or `undefined` if there is no such edge (the callback isn't called) or the callback returned nothing; * `build()` reports both. If the edge also has a backward condition, splitting it can't preserve the reverse * route, so it is rejected with `cannot_insert_bidirectional` and the callback isn't called — remove the * backward condition first. * * @example * const verify = wf.insertBetween("identify", "lookup_order", (from) => from.converse("verify", "Verify the caller")); * verify?.when("Caller can't verify").end({ id: "unverified" }); */ insertBetween(sourceId: string, targetId: string, insert: (from: WorkflowBranch) => WorkflowNode | undefined): WorkflowNode | undefined; /** * Validates the workflow and returns it in the shape `agents.create()` and `agents.update()` accept. * * @throws {WorkflowValidationError} listing every problem, if the workflow is invalid */ build(options?: BuildOptions): ElevenLabs.AgentWorkflowRequestModel; /** * The workflow in API format (snake_case keys, sorted at every level), for storing as config. Validates like * `build()`, and takes the same `toolIds`. Also what `JSON.stringify(workflow)` uses, which passes a key string * instead of options. */ toJSON(options?: BuildOptions | string): Record; /** * `toJSON()` as a string with 2-space indentation and a trailing newline: the canonical file format. Takes the * same `toolIds`. */ toJSONString(options?: BuildOptions): string; /** @internal */ protected _origin(): EdgeOrigin; }