1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use crate::engine_error::EngineError;
use crate::traits::run_context::RunContext;
/// Trait for pluggable action execution.
pub trait ActionExecutor: Send + Sync {
#[allow(dead_code)]
fn name(&self) -> &str;
fn execute(
&self,
ctx: &dyn RunContext,
info: &StepInfo,
params: &ActionParams,
) -> Result<ActionOutput, EngineError>;
#[allow(dead_code)]
fn cancel(&self, execution_id: &str) -> Result<(), EngineError> {
let _ = execution_id;
Ok(())
}
}
/// Engine-populated per-call info for a workflow step.
pub struct StepInfo {
pub step_id: String,
pub step_timeout: Duration,
}
/// Per-invocation inputs passed to an `ActionExecutor`.
pub struct ActionParams {
pub name: String,
pub inputs: Arc<HashMap<String, String>>,
#[allow(dead_code)]
pub retries_remaining: u32,
pub retry_error: Option<String>,
pub snippets: Vec<String>,
pub dry_run: bool,
#[allow(dead_code)]
pub gate_feedback: Option<String>,
pub extensions: crate::extensions::Extensions,
/// Optional named variant of the executor's underlying tool/agent.
///
/// Cross-runtime convention — every major terminal AI tool uses `--model`:
/// Claude (`claude-opus-4-7`), OpenAI Codex (`gpt-5.4`, `gpt-5.3-codex`),
/// Moonshot Kimi (`k2.5`), Google Gemini (`gemini-2.5-flash`), Simon
/// Willison's `llm` CLI, `aichat`, image-gen tools, etc.
///
/// Conductor's `CliRuntime` substitutes `{{model}}` into a configurable arg
/// template so any of these tools can be driven by a runkon-flow workflow
/// (`runkon-runtimes/src/runtime/cli.rs`).
///
/// Executors that have no concept of named variants (e.g. `SendEmailExecutor`,
/// `HttpRequestExecutor`) ignore the field. `None` means "use the executor's
/// default."
pub model: Option<String>,
/// When `Some`, names the identity this step's action should act as.
/// Executor implementations resolve it into harness-defined auth
/// material — typically credentials threaded into the spawned agent.
/// Examples:
///
/// - GitHub App installation name → `GH_TOKEN`
/// - AWS service account ID → `AWS_ACCESS_KEY_ID` / related vars
/// - Slack bot user ID → `SLACK_BOT_TOKEN`
/// - Agent persona key → API key scoped to that persona
///
/// Executors that don't model named identities ignore the field.
pub as_identity: Option<String>,
pub plugin_dirs: Vec<String>,
}
/// Output produced by an `ActionExecutor` on success.
#[derive(Debug, Default)]
pub struct ActionOutput {
pub markers: Vec<String>,
pub context: Option<String>,
pub result_text: Option<String>,
pub structured_output: Option<String>,
/// Executor-specific key/value metadata. Claude executors populate the seven
/// metric keys defined in `runkon_flow::constants::metadata_keys`.
pub metadata: HashMap<String, String>,
pub child_run_id: Option<String>,
}
/// Holds named and fallback `ActionExecutor` implementations.
pub struct ActionRegistry {
named: HashMap<String, Box<dyn ActionExecutor>>,
fallback: Option<Box<dyn ActionExecutor>>,
}
impl ActionRegistry {
/// Construct a registry from pre-built maps (called only by `FlowEngineBuilder`).
pub(crate) fn new(
named: HashMap<String, Box<dyn ActionExecutor>>,
fallback: Option<Box<dyn ActionExecutor>>,
) -> Self {
Self { named, fallback }
}
/// Construct a registry for external consumers that build registries outside the
/// `FlowEngineBuilder` pipeline — such as bridge adapters or integration-test harnesses
/// — that cannot use the builder's fluent API.
pub fn from_executors(
named: HashMap<String, Box<dyn ActionExecutor>>,
fallback: Option<Box<dyn ActionExecutor>>,
) -> Self {
Self::new(named, fallback)
}
/// Returns `true` if the named executor is registered OR a fallback is configured.
///
/// Mirrors the fallback semantics of `dispatch()`: a harness that registers only
/// a fallback executor passes all action name checks.
pub fn has_action(&self, name: &str) -> bool {
self.named.contains_key(name) || self.fallback.is_some()
}
fn find_executor(&self, name: &str) -> Option<&dyn ActionExecutor> {
self.named
.get(name)
.map(|e| e.as_ref())
.or(self.fallback.as_deref())
}
/// Find the executor for `name` and run it.
pub fn dispatch(
&self,
name: &str,
ctx: &dyn RunContext,
info: &StepInfo,
params: &ActionParams,
) -> Result<ActionOutput, EngineError> {
match self.find_executor(name) {
Some(e) => e.execute(ctx, info, params),
None => Err(EngineError::Workflow(format!(
"no registered ActionExecutor for '{}' and no fallback configured",
name
))),
}
}
/// Call `cancel()` on the executor for `name`, if registered.
/// Used by `FlowEngine::cancel_run()` to fire-and-forget executor-level cancellation.
pub fn cancel(&self, name: &str, execution_id: &str) -> Result<(), EngineError> {
match self.find_executor(name) {
Some(e) => e.cancel(execution_id),
None => Ok(()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_helpers::{make_params, make_run_ctx, make_step_info};
struct NoopExecutor;
impl ActionExecutor for NoopExecutor {
fn name(&self) -> &str {
"noop"
}
fn execute(
&self,
_ctx: &dyn RunContext,
_info: &StepInfo,
_params: &ActionParams,
) -> Result<ActionOutput, EngineError> {
Ok(ActionOutput {
markers: vec!["done".to_string()],
context: Some("noop ran".to_string()),
..Default::default()
})
}
}
#[test]
fn dispatch_named_executor() {
let registry = ActionRegistry::new(
[(
"noop".to_string(),
Box::new(NoopExecutor) as Box<dyn ActionExecutor>,
)]
.into_iter()
.collect(),
None,
);
let ctx = make_run_ctx();
let info = make_step_info();
let params = make_params("noop");
let output = registry
.dispatch("noop", ctx.as_ref(), &info, ¶ms)
.unwrap();
assert_eq!(output.markers, vec!["done"]);
}
#[test]
fn dispatch_fallback_when_no_named_match() {
let registry = ActionRegistry::new(
std::collections::HashMap::new(),
Some(Box::new(NoopExecutor)),
);
let ctx = make_run_ctx();
let info = make_step_info();
let params = make_params("anything");
let output = registry
.dispatch("anything", ctx.as_ref(), &info, ¶ms)
.unwrap();
assert_eq!(output.markers, vec!["done"]);
}
#[test]
fn dispatch_error_when_no_executor_or_fallback() {
let registry = ActionRegistry::new(std::collections::HashMap::new(), None);
let ctx = make_run_ctx();
let info = make_step_info();
let params = make_params("missing");
let err = registry
.dispatch("missing", ctx.as_ref(), &info, ¶ms)
.unwrap_err();
assert!(
err.to_string()
.contains("no registered ActionExecutor for 'missing'"),
"got: {err}"
);
}
#[test]
fn cancel_default_impl_is_noop() {
let executor = NoopExecutor;
assert!(executor.cancel("any-id").is_ok());
}
#[test]
fn has_action_named_executor_found() {
let registry = ActionRegistry::new(
[(
"noop".to_string(),
Box::new(NoopExecutor) as Box<dyn ActionExecutor>,
)]
.into_iter()
.collect(),
None,
);
assert!(registry.has_action("noop"));
assert!(!registry.has_action("missing"));
}
#[test]
fn has_action_true_with_fallback_regardless_of_name() {
let registry = ActionRegistry::new(
std::collections::HashMap::new(),
Some(Box::new(NoopExecutor)),
);
assert!(registry.has_action("anything"));
assert!(registry.has_action("also_this"));
}
#[test]
fn has_action_false_when_empty() {
let registry = ActionRegistry::new(std::collections::HashMap::new(), None);
assert!(!registry.has_action("noop"));
}
}