Skip to main content

motosan_workflow_core/
lib.rs

1//! # motosan-workflow-core
2//!
3//! A general-purpose DAG-based agent workflow engine for orchestrating LLM agents.
4//!
5//! This crate is a thin facade that re-exports from three sub-crates:
6//! - [`motosan_workflow_model`] — types, traits, graph, loader, templates
7//! - [`motosan_workflow_skill`] — skill system, ACP
8//! - [`motosan_workflow_runtime`] — execution engine
9//!
10//! ## Quick Start
11//!
12//! ```rust,no_run
13//! use motosan_workflow_core::*;
14//! use serde_json::json;
15//!
16//! // Build a workflow
17//! let workflow = Workflow::builder("research")
18//!     .name("Research Pipeline")
19//!     .node(
20//!         Node::agent("researcher")
21//!             .system_prompt("Find key facts about the topic.")
22//!             .build(),
23//!     )
24//!     .node(
25//!         Node::agent("writer")
26//!             .system_prompt("Write a structured report.")
27//!             .input_from("researcher")
28//!             .build(),
29//!     )
30//!     .edge("researcher", "writer")
31//!     .build()
32//!     .unwrap();
33//! ```
34//!
35//! ## Node Types
36//!
37//! | Type | Description | LLM |
38//! |------|-------------|-----|
39//! | [`Node::agent`] | LLM-powered agent | Yes |
40//! | [`Node::human`] | Human-in-the-loop gate | No |
41//! | [`Node::transform`] | Pure function transform | No |
42//! | [`Node::condition`] | Conditional branching | No |
43//! | [`Node::loop_node`] | Iterative loop with `_loop` context injection | Depends |
44//! | [`Node::sub_workflow`] | Nested sub-workflow | Depends |
45//! | [`Node::acp_agent`] | ACP coding agent (external CLI agent) | No |
46//!
47//! ## Features
48//!
49//! - **DAG execution**: Topological sort with automatic parallelization
50//! - **YAML/JSON loader**: [`load_workflow`] and [`load_workflow_from_str`]
51//! - **Schema validation**: JSON Schema with auto self-correction
52//! - **Retry policies**: Exponential backoff with Skip/Abort/Fallback modes
53//! - **Event streaming**: [`WorkflowEvent`] via tokio mpsc channel
54//! - **Cost estimation**: [`estimate_cost`] with per-node token tracking
55//! - **Skill system**: [`SkillResolver`] with extends/compose resolution
56//! - **Node `$ref`**: Reusable node definitions via [`load_workflow_with_base`]
57//! - **Loop context injection**: Body nodes receive `_loop` with iteration, history, previous
58//! - **8 built-in templates**: [`builtin_workflows`]
59//!
60//! ## Feature Flags
61//!
62//! | Flag | Description |
63//! |------|-------------|
64//! | `ag-ui` | AG-UI protocol event adapter |
65//! | `notify-human` | Telegram notification for human nodes |
66
67// ── Model: types, traits, graph, loader, templates ──────────────────────────
68
69pub use motosan_workflow_model::*;
70
71// Re-export model modules for namespaced access
72pub use motosan_workflow_model::{
73    context, cost, dag, error, event, execution, loader, node, orch_config, schema, state,
74    templates, tool_registry, traits, validation, workflow,
75};
76
77// ── Skill: skill system, ACP ────────────────────────────────────────────────
78
79pub use motosan_workflow_skill::*;
80
81// Re-export skill modules for namespaced access
82pub use motosan_workflow_skill::{acp, skill};
83
84// ── Runtime: execution engine ───────────────────────────────────────────────
85
86pub use motosan_workflow_runtime::*;
87
88// Re-export runtime sub-modules for namespaced access
89pub use motosan_workflow_runtime::{cancel, helpers, llm_bridge, resume};
90
91#[cfg(feature = "ag-ui")]
92pub use motosan_workflow_runtime::ag_ui;
93
94#[cfg(feature = "notify-human")]
95pub use motosan_workflow_runtime::notify_human;