Expand description
§motosan-workflow-core
A general-purpose DAG-based agent workflow engine for orchestrating LLM agents.
This crate is a thin facade that re-exports from three sub-crates:
motosan_workflow_model— types, traits, graph, loader, templatesmotosan_workflow_skill— skill system, ACPmotosan_workflow_runtime— execution engine
§Quick Start
use motosan_workflow_core::*;
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 |
Node::acp_agent | ACP coding agent (external CLI agent) | No |
§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 |
notify-human | Telegram notification for human nodes |
Modules§
- acp
- cancel
- context
- cost
- dag
- error
- event
- execution
- Execution recording data model for workflow history tracking.
- file_
execution_ store - File-system-backed
ExecutionStoreimplementation. - helpers
- llm_
bridge - loader
- YAML/JSON workflow loader.
- node
- orch_
config - Orchestrator configuration system.
- resume
- schema
- skill
- Skill data model and SKILL.md parser.
- state
- State diffing for recurring workflows.
- templates
- Built-in workflow templates embedded at compile time.
- tool_
registry - traits
- validation
- Agent validation utilities for workflow nodes.
- workflow
Structs§
- AcpCapabilities
- Capabilities exposed by an ACP client handler.
- AcpNode
Config - Configuration for an ACP (Agent Coding Protocol) agent node.
- Agent
Config - Configuration for an Agent node.
- Agent
Issue - A single validation issue associated with a workflow node.
- Cancellation
Token - A token that can be used to cancel a running workflow from an external context.
- Checkpoint
- Snapshot of a running workflow’s progress, persisted after each AcpNode success so the workflow can be resumed from the last completed node.
- Compose
Ref - A compose reference that pulls another skill into a specific location.
- Condition
Branch - A single branch in a ConditionNode: a JSON pointer path, comparison operator, and value.
- Condition
Config - Configuration for a Condition node.
- Condition
Resume State - State needed to replay a condition node’s branch selection.
- Cost
Estimate - Aggregated cost estimate for an entire workflow.
- Diff
Result - The result of comparing a new value against a previously stored value.
- Edge
- A directed edge in the workflow graph.
- Error
Summary - Summary of a recurring error.
- Execution
Filter - Filter criteria for querying execution records.
- Execution
Observer - Observer that listens to
WorkflowEvents and automatically builds and persists anExecutionRecord. - Execution
Record - Complete record of a single workflow execution.
- Execution
Stats - Aggregated statistics across multiple workflow executions.
- File
Access Config - File access configuration for an ACP agent.
- File
Execution Store - File-system-backed
ExecutionStorethat stores one JSON file per execution and one checkpoint file per in-flight execution. - File
State Store - A
StateStorebacked by JSON files on the local filesystem. - File
System Skill Provider - Loads skills from the filesystem.
- Human
Config - Configuration for a Human gate node.
- Human
Response - Response from a human input provider.
- LlmCall
Record - Record of a single LLM invocation within a node execution.
- LlmResponse
- Response from an LLM call, including content and token usage.
- Loop
Config - Configuration for a Loop node.
- Loop
Resume State - State needed to resume a loop from a specific iteration.
- McpServer
Config - Configuration for an MCP server to inject into the ACP agent.
- Message
- A single message in a multi-turn conversation.
- Model
Pricing - Pricing information for an LLM model.
- Node
- A single node in a workflow DAG.
- Node
Cost Estimate - Cost estimate for a single node.
- Node
Output - Output of a single node execution.
- Node
Record - Record of a single node’s execution within a workflow run.
- Orchestrator
Config - Top-level orchestrator configuration.
- Resume
Token - A serializable token that captures the state of a paused workflow, allowing it to be resumed later (potentially in a different session).
- Retry
Policy - Configurable retry behavior for a node.
- Runtime
- The workflow execution engine.
- Session
Store - Minimal file-based session_id persistence for
Persistentmode. - Skill
Def - A parsed skill definition.
- Skill
Entry - A single entry in the skill index.
- Skill
Resolver - Resolves skills by name, handling
extendsinheritance andcomposefragment injection. - SubWorkflow
Config - Configuration for a SubWorkflow node (nested workflow composition).
- Swarm
Config - Configuration for a Swarm node in the DAG.
- Swarm
Worker Config - Configuration for a worker in a swarm node.
- Token
Usage - Granular token usage for a single node, including individual LLM call records.
- Tool
Call Record - Record of a single tool invocation made by a node.
- Tool
Call Request - A single tool call requested by the LLM.
- Tool
Definition - Definition of a tool that can be passed to the LLM.
- Tool
Registry - A registry of named tools that can be resolved by agent nodes at runtime.
- Transform
Config - Configuration for a Transform node (pure function, async function, or external script).
- Workflow
- A workflow is a DAG of nodes connected by edges.
- Workflow
Builder - Workflow
Context - Thread-safe shared state for a workflow execution. Stores node outputs and arbitrary key-value data.
- Workflow
Result - Result of a complete workflow execution.
- Workflow
Stats - Per-workflow aggregated statistics.
Enums§
- AcpFallback
- Fallback behavior when an ACP agent is unavailable.
- AcpSession
Mode - Session mode for an ACP agent node.
- Agency
Skill - A skill that an ACP agent can use.
- Agent
Response - Response from a workflow LLM call, wrapping
motosan_agent_loop::LlmResponsewith per-call token tracking that the workflow engine needs for budgeting and cost estimation. - Condition
Op - Comparison operators for condition evaluation.
- Execution
Status - Overall status of a workflow execution.
- Failure
Mode - What to do when a node exhausts all retries.
- Foreach
Error Mode - How to handle errors in individual foreach items.
- Format
- The serialization format for workflow definitions.
- Issue
Severity - Severity level of a validation issue.
- Message
Content - The content of a message, which may be text, tool calls, or a tool result.
- Message
Role - The role of a message sender.
- Node
Kind - The kind of a workflow node.
- Node
Status - Status of an individual node execution.
- Skill
Select Strategy - Strategy for automatic skill selection.
- Skill
Type - The category of a skill.
- Stop
Reason - The reason the LLM stopped generating.
- Swarm
Completion Criteria - Completion criteria for a swarm node.
- Trigger
Type - How a workflow execution was triggered.
- Workflow
Error - Workflow
Event - Events emitted during workflow execution.
- Workflow
Status - The terminal status of a workflow execution.
Traits§
- Execution
Store - Pluggable storage backend for execution records.
- Human
Input Provider - Trait for providing human input to HumanNode gates.
- Into
Input Ids - Trait that allows
input_from()to accept both a single string and a collection of strings. - LlmClient
- Trait for LLM clients. Implement this to connect to your LLM provider.
- Skill
Provider - A source that can load skill definitions by name.
- State
Store - Persistent key-value store for workflow state.
- Tool
Executor - Trait for executing tools requested by the LLM during multi-turn conversations.
- Workflow
LlmClient - Thin wrapper trait on top of
motosan_agent_loop::LlmClientthat adds per-call token tracking required by the workflow engine.
Functions§
- auto_
select - Run the full auto-select flow.
- build_
system_ prompt - Build a combined system prompt from an optional skill and context files.
- builtin_
workflow - Load a single built-in workflow template by name.
- builtin_
workflows - Load all built-in workflow templates.
- diff_
and_ store - Compare
valueagainst the previously stored value forkey, store the new value, and return aDiffResultdescribing what changed. - estimate_
cost - Estimate cost for a workflow before execution.
- load_
skill_ index - Load a skill index from all
.mdfiles indir. - load_
workflow - Load a workflow from a file path. The format is detected from the file extension.
- load_
workflow_ from_ str - Load a workflow from a string in the specified format.
- load_
workflow_ with_ base - Load a workflow from a file path, resolving
$refpaths relative tobase_dir. - parse_
skill_ md - Parse a SKILL.md string into a
SkillDef. - resolve_
skill_ content - Resolve an
AgencySkillvariant to its markdown content string. - select_
by_ keyword - Select the best skill using simple keyword matching (offline, no LLM).
- select_
by_ llm - Select the best skill using an LLM routing call.
- validate_
agents - Validate all agent nodes in
workflowand return any issues found. - validate_
condition_ paths - Check that
input_fromreferences on condition-routed target nodes are ancestors of the condition node itself. - workflow_
fingerprint - Compute a SHA-256 fingerprint from a workflow’s structural identity.
- write_
skill_ tempfile - Write prompt content to a temporary file and return its
TempPath.
Type Aliases§
- Async
Transform Fn - The type of an async transform function — supports HTTP calls, file I/O, etc.
- Result
- Transform
Fn - The type of a synchronous transform function.