Expand description
§motosan-agent-workflow
A general-purpose DAG-based agent workflow engine for orchestrating LLM agents.
§Quick Start
use motosan_agent_workflow::*;
use serde_json::json;
// Build a workflow
let workflow = Workflow::builder("research")
.name("Research Pipeline")
.node(
Node::agent("researcher")
.system_prompt("Find key facts about the topic.")
.build(),
)
.node(
Node::agent("writer")
.system_prompt("Write a structured report.")
.input_from("researcher")
.build(),
)
.edge("researcher", "writer")
.build()
.unwrap();§Node Types
| Type | Description | LLM |
|---|---|---|
Node::agent | LLM-powered agent | Yes |
Node::human | Human-in-the-loop gate | No |
Node::transform | Pure function transform | No |
Node::condition | Conditional branching | No |
Node::loop_node | Iterative loop with _loop context injection | Depends |
Node::sub_workflow | Nested sub-workflow | Depends |
§Features
- DAG execution: Topological sort with automatic parallelization
- YAML/JSON loader:
load_workflowandload_workflow_from_str - Schema validation: JSON Schema with auto self-correction
- Retry policies: Exponential backoff with Skip/Abort/Fallback modes
- Event streaming:
WorkflowEventvia tokio mpsc channel - Cost estimation:
estimate_costwith per-node token tracking - Skill system:
SkillResolverwith extends/compose resolution - Node
$ref: Reusable node definitions viaload_workflow_with_base - Loop context injection: Body nodes receive
_loopwith iteration, history, previous - 8 built-in templates:
builtin_workflows
§Feature Flags
| Flag | Description |
|---|---|
ag-ui | AG-UI protocol event adapter |
Re-exports§
pub use context::WorkflowContext;pub use error::Result;pub use error::WorkflowError;pub use event::WorkflowEvent;pub use node::AgentConfig;pub use node::ConditionBranch;pub use node::ConditionConfig;pub use node::ConditionOp;pub use node::FailureMode;pub use node::HumanConfig;pub use node::AsyncTransformFn;pub use node::IntoInputIds;pub use node::LoopConfig;pub use node::Node;pub use node::NodeKind;pub use node::RetryPolicy;pub use node::SubWorkflowConfig;pub use node::TransformConfig;pub use node::TransformFn;pub use runtime::HumanInputProvider;pub use runtime::HumanResponse;pub use runtime::LlmClient;pub use runtime::LlmResponse;pub use runtime::NodeOutput;pub use runtime::ResumeToken;pub use runtime::Runtime;pub use runtime::TokenUsage;pub use runtime::WorkflowResult;pub use runtime::WorkflowStatus;pub use cost::estimate_cost;pub use cost::CostEstimate;pub use cost::ModelPricing;pub use cost::NodeCostEstimate;pub use loader::load_workflow;pub use loader::load_workflow_from_str;pub use loader::load_workflow_with_base;pub use loader::Format;pub use skill::parse_skill_md;pub use skill::ComposeRef;pub use skill::FileSystemSkillProvider;pub use skill::SkillDef;pub use skill::SkillProvider;pub use skill::SkillResolver;pub use skill::SkillType;pub use state::DiffResult;pub use state::FileStateStore;pub use state::StateStore;pub use state::diff_and_store;pub use templates::builtin_workflow;pub use templates::builtin_workflows;pub use workflow::Edge;pub use workflow::Workflow;pub use workflow::WorkflowBuilder;pub use execution::ErrorSummary;pub use execution::ExecutionFilter;pub use execution::ExecutionObserver;pub use execution::ExecutionRecord;pub use execution::ExecutionStats;pub use execution::ExecutionStatus;pub use execution::ExecutionStore;pub use execution::FileExecutionStore;pub use execution::LlmCallRecord;pub use execution::NodeRecord;pub use execution::NodeStatus;pub use execution::ToolCallRecord;pub use execution::TriggerType;pub use execution::WorkflowStats;