UNPKG

agentis

Version:

A TypeScript framework for building sophisticated multi-agent systems

99 lines (98 loc) 3.52 kB
import { ExecutionGraph, ExecutionMode } from './EnhancedToolOrchestrator'; import { ToolOutput } from './ITool'; /** * Fluent API for building tool execution graphs */ export declare class GraphBuilder { private nodes; private mode; private maxConcurrency?; constructor(); /** * Create a new node in the graph */ addNode(nodeConfig: { id: string; toolName: string; input: string | ((context: any) => string); priority?: number; dependsOn?: string[]; mode?: ExecutionMode; condition?: (results: Map<string, ToolOutput>) => boolean; transformOutput?: (output: ToolOutput, context: any) => any; retryConfig?: { maxRetries: number; delayMs: number; shouldRetry?: (error: Error, attempt: number) => boolean; }; }): GraphBuilder; /** * Add a simple tool node with no dependencies */ addTool(id: string, toolName: string, input: string, priority?: number): GraphBuilder; /** * Add a node that depends on the results of other nodes */ addDependentTool(id: string, toolName: string, inputFn: (context: any) => string, dependsOn: string[], priority?: number): GraphBuilder; /** * Add a conditional node that only executes if a condition is met */ addConditionalTool(id: string, toolName: string, input: string | ((context: any) => string), condition: (results: Map<string, ToolOutput>) => boolean, dependsOn?: string[], priority?: number): GraphBuilder; /** * Add a node with output transformation */ addTransformingTool(id: string, toolName: string, input: string | ((context: any) => string), transformOutput: (output: ToolOutput, context: any) => any, dependsOn?: string[], priority?: number): GraphBuilder; /** * Add a node with retry capabilities */ addRetryableTool(id: string, toolName: string, input: string | ((context: any) => string), retryConfig: { maxRetries: number; delayMs: number; shouldRetry?: (error: Error, attempt: number) => boolean; }, dependsOn?: string[], priority?: number): GraphBuilder; /** * Set execution mode to sequential (default) */ sequential(): GraphBuilder; /** * Set execution mode to parallel */ parallel(maxConcurrency?: number): GraphBuilder; /** * Add a chain of dependent tools */ addChain(chainConfig: { prefix: string; tools: Array<{ toolName: string; input: string | ((prevResult: any) => string); transformOutput?: (output: ToolOutput) => any; }>; }): GraphBuilder; /** * Build and return the final execution graph */ build(): ExecutionGraph; /** * Create a simple graph for a single tool */ static createSingleToolGraph(toolName: string, input: string, id?: string): ExecutionGraph; /** * Create a simple sequential chain of tools */ static createSequentialChain(chainConfig: { tools: Array<{ toolName: string; input: string | ((prevResult: any) => string); transformOutput?: (output: ToolOutput) => any; }>; }): ExecutionGraph; /** * Create a graph from an array of tools to run in parallel */ static createParallelGraph(tools: Array<{ toolName: string; input: string; id?: string; }>, maxConcurrency?: number): ExecutionGraph; }