Expand description
Workflow Module
工作流引擎核心框架,提供基于 YAML 定义的 DAG 工作流管理。
§模块结构
def: 工作流定义结构(WorkflowDef, NodeDef, EdgeDef 等)parser: YAML 解析器context: 运行时状态管理template: 模板渲染引擎({{var}} 替换)rule_engine: 验证规则引擎engine: 状态机引擎executors: 节点执行器(AI、工具、条件、验证)
§快速开始
ⓘ
use matrixcode::workflow::{parse_workflow, WorkflowEngine, WorkflowContext};
// 解析工作流定义
let yaml = r#"
id: hello-workflow
name: Hello Workflow
nodes:
- id: start
type: start
name: Start
- id: greet
type: task
name: Greet
task: greet
- id: end
type: end
name: End
edges:
- from: start
to: greet
- from: greet
to: end
"#;
let workflow = parse_workflow(yaml)?;
// 创建引擎并运行
let engine = WorkflowEngine::new(workflow)?;
let context = engine.run(HashMap::new()).await?;
println!("Workflow status: {:?}", context.status);Re-exports§
pub use def::WorkflowDef;pub use def::NodeDef;pub use def::EdgeDef;pub use def::NodeType;pub use def::FailureStrategy;pub use def::InputDef;pub use def::OutputDef;pub use def::BranchDef;pub use def::ParallelBranchDef;pub use parser::parse_workflow;pub use parser::parse_workflow_from_file;pub use parser::to_yaml;pub use context::WorkflowContext;pub use context::WorkflowStatus;pub use context::NodeStatus;pub use context::NodeExecution;pub use template::TemplateRenderer;pub use template::render as render_template;pub use rule_engine::Rule;pub use rule_engine::RuleEngine;pub use rule_engine::ValidationResult;pub use rule_engine::evaluate_expression;pub use engine::WorkflowEngine;pub use engine::WorkflowEvent;pub use engine::EventListener;pub use engine::TaskExecutor;pub use engine::DefaultTaskExecutor;pub use persistence::WorkflowPersistence;pub use registry::WorkflowRegistry;pub use registry::WorkflowInfo;pub use registry::WorkflowSource;pub use executors::NodeExecutor;pub use executors::AiExecutor;pub use executors::AiExecutorConfig;pub use executors::ToolExecutor;pub use executors::ToolExecutorConfig;pub use executors::ProxyExecutor;pub use executors::ConditionExecutor;pub use executors::ValidateExecutor;pub use executors::ValidateExecutorConfig;pub use executors::CompositeExecutor;pub use executors::CompositeMode;pub use executors::ExecutorFactory;
Modules§
- context
- Workflow Context and Runtime State
- def
- Workflow Definition Structures
- engine
- Workflow Engine - State Machine Implementation
- executors
- Workflow Executors
- parser
- YAML Parser for Workflow Definitions
- persistence
- Workflow persistence module
- registry
- Workflow Registry - Discovery and Matching
- rule_
engine - Rule Engine for Workflow Validation
- template
- Template Rendering Engine