Skip to main content

Crate motosan_agent_workflow

Crate motosan_agent_workflow 

Source
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

TypeDescriptionLLM
Node::agentLLM-powered agentYes
Node::humanHuman-in-the-loop gateNo
Node::transformPure function transformNo
Node::conditionConditional branchingNo
Node::loop_nodeIterative loop with _loop context injectionDepends
Node::sub_workflowNested sub-workflowDepends

§Features

  • DAG execution: Topological sort with automatic parallelization
  • YAML/JSON loader: load_workflow and load_workflow_from_str
  • Schema validation: JSON Schema with auto self-correction
  • Retry policies: Exponential backoff with Skip/Abort/Fallback modes
  • Event streaming: WorkflowEvent via tokio mpsc channel
  • Cost estimation: estimate_cost with per-node token tracking
  • Skill system: SkillResolver with extends/compose resolution
  • Node $ref: Reusable node definitions via load_workflow_with_base
  • Loop context injection: Body nodes receive _loop with iteration, history, previous
  • 8 built-in templates: builtin_workflows

§Feature Flags

FlagDescription
ag-uiAG-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;

Modules§

context
cost
dag
error
event
execution
Execution recording data model for workflow history tracking.
loader
YAML/JSON workflow loader.
node
runtime
schema
skill
Skill data model and SKILL.md parser.
state
State diffing for recurring workflows.
templates
Built-in workflow templates embedded at compile time.
workflow