Skip to main content

motosan_workflow_runtime/
lib.rs

1//! # motosan-workflow-runtime
2//!
3//! Execution engine for the motosan-workflow DAG-based agent workflow engine.
4//!
5//! This crate provides the `Runtime` struct which orchestrates workflow execution,
6//! including agent nodes, human gates, conditions, loops, sub-workflows, ACP agents,
7//! and swarm nodes.
8
9mod builder;
10pub mod cancel;
11mod execute;
12pub mod file_execution_store;
13pub mod helpers;
14pub mod llm_bridge;
15mod node_acp;
16mod node_agent;
17mod node_condition;
18pub(crate) mod node_dispatch;
19mod node_human;
20mod node_loop;
21mod node_sub_workflow;
22mod node_swarm;
23pub(crate) mod node_transform;
24pub(crate) mod process_cleanup;
25pub mod resume;
26
27#[cfg(feature = "ag-ui")]
28pub mod ag_ui;
29
30#[cfg(feature = "notify-human")]
31pub mod notify_human;
32
33use std::collections::HashMap;
34use std::sync::atomic::AtomicU64;
35use std::sync::Arc;
36
37use tokio::sync::{mpsc, RwLock};
38
39use motosan_workflow_model::{
40    ExecutionStore, HumanInputProvider, LlmClient, ModelPricing, TokenUsage, ToolExecutor,
41    ToolRegistry, WorkflowEvent,
42};
43use motosan_workflow_skill::SkillResolver;
44
45// ---- Re-exports ----
46
47pub use cancel::CancellationToken;
48pub use file_execution_store::FileExecutionStore;
49pub use llm_bridge::{AgentResponse, WorkflowLlmClient};
50pub use resume::{ConditionResumeState, LoopResumeState};
51
52#[cfg(feature = "ag-ui")]
53pub use ag_ui::AgUiAdapter;
54
55#[cfg(feature = "notify-human")]
56pub use notify_human::{NotifyHumanTool, TelegramConfig};
57
58/// The workflow execution engine.
59pub struct Runtime {
60    pub(crate) llm_client: Arc<dyn LlmClient>,
61    pub(crate) human_input_provider: Option<Arc<dyn HumanInputProvider>>,
62    pub(crate) skill_resolver: Option<Arc<SkillResolver>>,
63    pub(crate) event_sender: Option<mpsc::UnboundedSender<WorkflowEvent>>,
64    pub(crate) total_tokens: Arc<AtomicU64>,
65    pub(crate) token_budget: Option<u64>,
66    pub(crate) tokens_per_node: Arc<RwLock<HashMap<String, TokenUsage>>>,
67    pub(crate) model_pricing: Option<ModelPricing>,
68    pub(crate) tool_executor: Option<Arc<dyn ToolExecutor>>,
69    /// Named tool registry for resolving YAML `tools: [name]` to implementations.
70    pub(crate) tool_registry: Arc<ToolRegistry>,
71    /// Optional loop resume state, consumed on first use by the matching loop node.
72    pub(crate) loop_resume: Arc<RwLock<Option<LoopResumeState>>>,
73    /// Cancellation token for cooperative cancellation of running workflows.
74    pub(crate) cancel_token: CancellationToken,
75    /// Optional checkpoint store for persisting execution state (resume support).
76    pub(crate) checkpoint_store: Option<Arc<dyn ExecutionStore>>,
77    /// Maximum number of nodes executed concurrently by the ready-queue scheduler.
78    pub(crate) max_parallel_workers: usize,
79    /// Optional tool context passed to every AgentLoop tool invocation.
80    pub(crate) tool_context: Option<motosan_agent_tool::ToolContext>,
81}