Commit e1c7ea7e
e1c7ea7ece93Merged
Scott Nixon <[email protected]> ยท 9 months ago ยท 2 files ยท ~2 modified
Description
Add --max-budget-usd and --max-steps safety limits
Pipeline engine now enforces step count and budget caps to prevent runaway loops and unbounded spending. Defaults to 200 max steps with no budget limit. Both are configurable via CLI flags.
Details
- Commit
- e1c7ea7ece93
- Parent
- a0aee2fe6130
crates/attractor-cli/src/main.rsmodifiedView file
@@ -33,6 +33,14 @@
3333
/// Don't actually call LLMs (dry run)3434
#[arg(long)]3535
dry_run: bool,36+
37+
/// Maximum total spend across all nodes (USD). Pipeline aborts if exceeded.38+
#[arg(long)]39+
max_budget_usd: Option<f64>,40+
41+
/// Maximum number of node executions before aborting. Prevents runaway loops. Default: 200.42+
#[arg(long, default_value = "200")]43+
max_steps: u64,3644
},3745
3846
/// Validate a pipeline .dot file@@ -64,8 +72,10 @@
6472
workdir,6573
logs,6674
dry_run,75+
max_budget_usd,76+
max_steps,6777
} => {68-
cmd_run(&pipeline, workdir.as_deref(), &logs, dry_run).await?;78+
cmd_run(&pipeline, workdir.as_deref(), &logs, dry_run, max_budget_usd, max_steps).await?;6979
}7080
Commands::Validate { pipeline } => {7181
cmd_validate(&pipeline)?;@@ -151,6 +161,8 @@
151161
workdir: Option<&std::path::Path>,152162
_logs: &std::path::Path,153163
dry_run: bool,164+
max_budget_usd: Option<f64>,165+
max_steps: u64,154166
) -> anyhow::Result<()> {155167
let graph = load_pipeline(path)?;156168
@@ -180,6 +192,18 @@
180192
.await;181193
}182194
195+
// Safety limits196+
if let Some(budget) = max_budget_usd {197+
context198+
.set("max_budget_usd", serde_json::json!(budget))199+
.await;200+
println!("Budget limit: ${:.2}", budget);201+
}202+
context203+
.set("max_steps", serde_json::json!(max_steps))204+
.await;205+
println!("Step limit: {}", max_steps);206+
183207
let executor = attractor_pipeline::PipelineExecutor::with_default_registry();184208
let result = executor.run_with_context(&graph, context).await?;185209
crates/attractor-pipeline/src/engine.rsmodifiedView file
Loading diffโฆ