/** * YAML Workflow Parser * Parse YAML workflow definitions into executable workflows */ import { AgentFlow, Task } from './index'; export interface YAMLWorkflowDefinition { name: string; description?: string; version?: string; steps: YAMLStepDefinition[]; metadata?: Record; } export interface YAMLStepDefinition { name: string; type: 'agent' | 'tool' | 'condition' | 'parallel' | 'loop'; agent?: string; tool?: string; input?: string | Record; output?: string; condition?: string; onError?: 'fail' | 'skip' | 'retry'; maxRetries?: number; timeout?: number; steps?: YAMLStepDefinition[]; loopCondition?: string; maxIterations?: number; } export interface ParsedWorkflow { workflow: AgentFlow; definition: YAMLWorkflowDefinition; errors: string[]; } /** * Parse YAML string into workflow definition */ export declare function parseYAMLWorkflow(yamlContent: string): YAMLWorkflowDefinition; /** * Create executable workflow from YAML definition */ export declare function createWorkflowFromYAML(definition: YAMLWorkflowDefinition, agents?: Record, tools?: Record): ParsedWorkflow; /** * Load workflow from YAML file */ export declare function loadWorkflowFromFile(filePath: string, agents?: Record, tools?: Record, options?: { basePath?: string; maxFileSizeBytes?: number; }): Promise; /** * Validate YAML workflow definition */ export declare function validateWorkflowDefinition(definition: YAMLWorkflowDefinition): string[]; import { Loop } from './loop'; import { Repeat } from './repeat'; import { If, Parallel, Route, Include, type FlowStep, type AgentLikeStep } from './patterns'; /** * Parse a YAML document into plain data (maps, arrays, scalars). * * Supports the block-YAML subset workflow files use; see {@link YamlReader}. * Python: yaml.safe_load */ export declare function parseYamlDocument(text: string): any; type ToolFn = (...args: any[]) => any; /** * Parser for YAML workflow definitions (Python parity: YAMLWorkflowParser). * * @example * ```typescript * const parser = new YAMLWorkflowParser(); * parser.registerAgent('writer', writerAgent); // or let `agents:` create real Agents * const flow = parser.parseString(` * name: review * variables: * score: 90 * steps: * - agent: writer * - if: * condition: "{{score}} > 80" * then: * - agent: writer * action: "Approve: {{previous_output}}" * `); * await flow.run('Draft'); * ``` */ export declare class YAMLWorkflowParser { /** Tool functions referenced by name from `agents..tools`. */ toolRegistry: Record; private _agents; private _callbacks; private _registeredAgents; constructor(toolRegistry?: Record | null); /** Agents from the most recent parse, keyed by their YAML id. */ get agents(): Record; /** Callbacks registered via {@link registerCallback} or declared in `callbacks:`. */ get callbacks(): Record; /** * Parse a YAML workflow file (synchronously, like Python). * @throws Error when the file does not exist. */ parseFile(filePath: string, extraVars?: Record | null): AgentFlow; /** Parse a YAML workflow string into an executable `AgentFlow`. */ parseString(yamlContent: string, extraVars?: Record | null): AgentFlow; /** Register a tool for use in workflows. */ registerTool(name: string, tool: ToolFn): void; /** Register a callback function. */ registerCallback(name: string, callback: ToolFn): void; /** * Pre-register an agent (anything with `chat()`) under a YAML id. Steps that * reference the id use it instead of constructing a new `Agent`. */ registerAgent(name: string, agent: AgentLikeStep): void; /** Accept both agents.yaml and workflow.yaml field names; return canonical data. */ normalizeYamlConfig(data: Record | null | undefined): Record; /** Python: _extract_steps_from_roles */ private extractStepsFromRoles; /** Python: _convert_roles_to_agents */ private convertRolesToAgents; parseWorkflowData(data: Record, extraVars?: Record | null): AgentFlow; private parseAgents; /** Python: _create_agent — a pre-registered agent wins over a fresh `Agent`. */ private createAgent; /** Python: _resolve_tools — unknown names are skipped. */ private resolveTools; /** Python: _parse_callbacks — names resolve to registered callbacks, else null. */ private parseCallbacks; parseSteps(stepsData: any[]): FlowStep[]; parseSingleStep(stepData: any): FlowStep | null; /** * Wrap an agent in a `Task` carrying the step's YAML options. * * Python mutates `agent._yaml_action` etc.; wrapping keeps one agent usable * in several steps with different actions. */ private agentTask; private requireAgent; /** Python: _parse_agent_step */ parseAgentStep(stepData: Record): Task; /** Python: _parse_include_step — `include: name` or `include: {recipe, input}`. */ parseIncludeStep(stepData: Record): Include; /** Python: _parse_if_step */ parseIfStep(stepData: Record): If; /** Python: _parse_route_step — values are agent ids (or lists of ids); unknown ids are dropped. */ parseRouteStep(stepData: Record): Route; /** * Python: _parse_parallel_step — a list of `{agent, action}` items. * TS extension: `parallel: {steps: [...], max_workers, on_failure}`. */ parseParallelStep(stepData: Record): Parallel; /** Python: _parse_loop_step — supports agent / step / steps / include forms. */ parseLoopStep(stepData: Record): Loop; /** Python: _parse_repeat_step — `until` string means "previous output contains". */ parseRepeatStep(stepData: Record): Repeat; /** Python: _create_condition_from_string */ private createConditionFromString; /** * Python: _parse_generic_step — a step with neither agent nor pattern. * A `tool:` from the registry is executed; otherwise running the step throws. */ parseGenericStep(stepData: Record): Task; } export {};