diff --git a/crates/tinycomputer-bus/README.md b/crates/tinycomputer-bus/README.md index 88bf0d96f..4def2a27b 100644 --- a/crates/tinycomputer-bus/README.md +++ b/crates/tinycomputer-bus/README.md @@ -169,6 +169,10 @@ See the [Globe contract](src/accessibility/README.md). Reliable Globe callers require a released 2.12-compatible artifact with a verified digest. +Contract 2.27 adds the optional `max_step_turns` field to `TaskBudget` and +`RunFlowRequest`: the turns one `do` step may spend before it fails, 8 unless +set and at most the module's action ceiling, 120. + Contract 2.25 adds the optional `BrowserEgressHost` callbacks, and 2.26 adds the confidential `TraceSinkHost` callback. A host prepares one exact callback binding per loaded module and supplies its unique diff --git a/crates/tinycomputer-bus/src/agent/agent_tests.rs b/crates/tinycomputer-bus/src/agent/agent_tests.rs index fe2e40e21..4b428c829 100644 --- a/crates/tinycomputer-bus/src/agent/agent_tests.rs +++ b/crates/tinycomputer-bus/src/agent/agent_tests.rs @@ -295,6 +295,26 @@ fn waiting_and_continuing_have_forgiving_defaults() { assert_eq!(wire["inputs"], json!({})); } +#[test] +fn step_turns_pin_their_wire_form() { + let request: StartTaskRequest = serde_json::from_value(json!({ + "task": "book a flight", + "budget": {"max_step_turns": 20} + })) + .unwrap(); + assert_eq!(request.budget.max_step_turns, Some(20)); + assert_eq!( + serde_json::to_value(request.budget).unwrap()["max_step_turns"], + 20 + ); + let unset: StartTaskRequest = + serde_json::from_value(json!({"task": "book a flight", "budget": {}})).unwrap(); + assert_eq!( + unset.budget.max_step_turns, None, + "unset takes the module's default" + ); +} + #[test] fn rescues_pin_their_wire_form() { let request: StartTaskRequest = serde_json::from_value(json!({ diff --git a/crates/tinycomputer-bus/src/agent/types/request.rs b/crates/tinycomputer-bus/src/agent/types/request.rs index 83cd9d4a8..fa5bd5fd0 100644 --- a/crates/tinycomputer-bus/src/agent/types/request.rs +++ b/crates/tinycomputer-bus/src/agent/types/request.rs @@ -217,6 +217,12 @@ pub struct TaskBudget { /// before the task fails; the module's default (5, also the most) when /// unset, and `0` turns rescues off. pub max_rescues: Option, + /// Turns a `do` step may spend before it fails, for every `do` the task + /// runs: a planned step's, a recipe's, or a rescue's. A turn is one look + /// at the screen and the move made on it. The module's default (8) when + /// unset, and never more than its action ceiling (120). A cap on each + /// step, not a pool the task spends: every run of the task gets it whole. + pub max_step_turns: Option, } /// `AwaitTask`: wait for a task to need something or finish. diff --git a/crates/tinycomputer-bus/src/flow/flow_tests.rs b/crates/tinycomputer-bus/src/flow/flow_tests.rs index 4a13b3f19..bdaa6de67 100644 --- a/crates/tinycomputer-bus/src/flow/flow_tests.rs +++ b/crates/tinycomputer-bus/src/flow/flow_tests.rs @@ -116,8 +116,13 @@ fn run_requests_default_to_safe_bounded_runs() { serde_json::from_value(json!({"flow": {"app": "Mail", "steps": ["x"]}})).unwrap(); assert!(!request.allow_destructive && !request.include_values); assert_eq!( - (request.max_actions, request.max_model_calls, request.votes), - (60, 3000, 7) + ( + request.max_actions, + request.max_model_calls, + request.max_step_turns, + request.votes + ), + (60, 3000, 8, 7) ); assert!(request.brief.is_empty()); assert!(request.disabled_loops.is_empty() && request.memory.is_empty() && !request.trace); diff --git a/crates/tinycomputer-bus/src/flow/types/request.rs b/crates/tinycomputer-bus/src/flow/types/request.rs index 2e24025ea..52f131e91 100644 --- a/crates/tinycomputer-bus/src/flow/types/request.rs +++ b/crates/tinycomputer-bus/src/flow/types/request.rs @@ -192,6 +192,10 @@ pub struct RunFlowRequest { /// Most Jev evaluations for the whole run; capped by the module at /// 10000. Every framing of a voted decision counts as one. pub max_model_calls: u32, + /// Turns a `do` step may spend before it fails: a turn is one look at + /// the screen and the move made on it. 8 unless set; capped by the + /// module at its action ceiling, 120. + pub max_step_turns: u32, /// How many ways each decision is asked, concurrently, before its /// answers are averaged: 1 asks once. Jev calls are cheap, so accuracy /// is bought with more of them. Capped by the module at 9. @@ -240,6 +244,7 @@ impl Default for RunFlowRequest { include_values: false, max_actions: 60, max_model_calls: 3000, + max_step_turns: 8, votes: 7, brief: FlowBrief::default(), disabled_loops: Vec::new(), diff --git a/crates/tinycomputer-bus/src/version/mod.rs b/crates/tinycomputer-bus/src/version/mod.rs index 841c92b62..bc21fef6a 100644 --- a/crates/tinycomputer-bus/src/version/mod.rs +++ b/crates/tinycomputer-bus/src/version/mod.rs @@ -8,7 +8,7 @@ //! release workflow bumps, which tracks the shipped artifact. /// The wire contract version this crate defines. -pub const CONTRACT_VERSION: (u32, u32) = (2, 26); +pub const CONTRACT_VERSION: (u32, u32) = (2, 27); /// Returns whether a host holding [`CONTRACT_VERSION`] can bind to a module /// reporting `module`. @@ -22,7 +22,7 @@ pub const CONTRACT_VERSION: (u32, u32) = (2, 26); /// ``` /// # use tinycomputer_bus::{is_compatible, CONTRACT_VERSION}; /// assert!(is_compatible(CONTRACT_VERSION)); -/// assert!(is_compatible((2, 26))); +/// assert!(is_compatible((2, 27))); /// assert!(!is_compatible((2, 11))); /// assert!(!is_compatible((1, 8))); /// ``` diff --git a/crates/tinycomputer-bus/src/version/version_tests.rs b/crates/tinycomputer-bus/src/version/version_tests.rs index e813ad574..9953762c2 100644 --- a/crates/tinycomputer-bus/src/version/version_tests.rs +++ b/crates/tinycomputer-bus/src/version/version_tests.rs @@ -6,7 +6,7 @@ use super::{CONTRACT_VERSION, binds, is_compatible}; #[test] fn the_shipped_contract_version_is_pinned() { - assert_eq!(CONTRACT_VERSION, (2, 26)); + assert_eq!(CONTRACT_VERSION, (2, 27)); } #[test] @@ -16,7 +16,7 @@ fn the_contract_binds_to_itself() { #[test] fn a_newer_minor_on_the_module_side_binds() { - assert!(is_compatible((2, 26))); + assert!(is_compatible((2, 27))); assert!(is_compatible((2, 97))); // 2.24 adds same-task flow-to-planner handoff to StartTask. // 2.22 adds optional host-held secret handles to StartTask and RunFlow. @@ -41,6 +41,10 @@ fn a_newer_minor_on_the_module_side_binds() { // would never reach the host's policy. // 2.20 adds SessionOptions identity fields. // 2.25 adds BrowserEgressHost. + // 2.27 adds `max_step_turns` to `TaskBudget` and `RunFlowRequest`: a + // 2.27 host may send it, which a 2.26 module would ignore, giving every + // `do` step eight turns whatever the host asked for. + assert!(!is_compatible((2, 26))); // 2.26 adds TraceSinkHost, so a 2.25 module lacks that callback. assert!(!is_compatible((2, 25))); assert!(!is_compatible((2, 24))); diff --git a/crates/tinycomputer-engine/src/agentic/flow/README.md b/crates/tinycomputer-engine/src/agentic/flow/README.md index 72fdd10ba..4841a38f0 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/README.md +++ b/crates/tinycomputer-engine/src/agentic/flow/README.md @@ -49,7 +49,7 @@ evidence, checked after acting, and undone and retried when wrong. is narrowed, never silently truncated. - Budgets: `max_actions` (≤ 120) and `max_model_calls` (≤ 10000, every voted framing counting as one) per run; a `do` - step takes at most 8 turns. + step takes at most `max_step_turns` turns (8 unless set, ≤ 120). - Irreversible controls are pressed only by `stop_before` with `allow_destructive`, and a deep run needs 0.85 belief first. - Deliberation spends nothing when every gate accepts as it reads; a failed diff --git a/crates/tinycomputer-engine/src/agentic/flow/flow_tests/budget_tests.rs b/crates/tinycomputer-engine/src/agentic/flow/flow_tests/budget_tests.rs index d1184d1f7..09e35edb9 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/flow_tests/budget_tests.rs +++ b/crates/tinycomputer-engine/src/agentic/flow/flow_tests/budget_tests.rs @@ -33,6 +33,27 @@ async fn the_implicit_launch_is_charged_to_the_action_budget() { ); } +#[test] +fn a_step_gets_the_turns_asked_for_within_the_action_ceiling() { + // Whatever a request asks for, a step is given at least one turn and + // never more than the run's action ceiling. + let runtime = runtime(Oracle { + app: App::default(), + hook: Box::new(|_, _, _| None), + requests: Mutex::new(Vec::new()), + fail: false, + }); + for (asked, given) in [(8, 8), (0, 1), (1_000, 120)] { + let request = RunFlowRequest { + flow: serde_json::from_value(mail_flow()).unwrap(), + max_step_turns: asked, + ..RunFlowRequest::default() + }; + let run = super::super::FlowRun::new(App::default(), &runtime, &request, None); + assert_eq!(run.max_step_turns, given, "asked for {asked} turns"); + } +} + #[tokio::test] async fn budgets_invalid_flows_and_provider_failures_stop_cleanly() { let actions = run_with( diff --git a/crates/tinycomputer-engine/src/agentic/flow/flow_tests/do_loop_tests.rs b/crates/tinycomputer-engine/src/agentic/flow/flow_tests/do_loop_tests.rs index ec7c33d29..a63cce626 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/flow_tests/do_loop_tests.rs +++ b/crates/tinycomputer-engine/src/agentic/flow/flow_tests/do_loop_tests.rs @@ -663,6 +663,32 @@ async fn waits_that_change_nothing_are_not_a_stall_and_stop_being_offered() { assert!(told, "Jev is told the page has settled"); } +#[tokio::test] +async fn a_do_step_spends_the_turns_the_request_gives_it() { + // Eight turns unless the request says otherwise: a task whose steps are + // long (a cluttered shop page) asks for more, a quick one for fewer, + // and a step always gets at least one. The failure names what the step + // was given. + for (asked, given) in [(3, 3), (12, 12), (0, 1)] { + let run = run_with( + App::quirky(Quirk::Frozen), + json!({"app": "Mail", "steps": ["open the search results"]}), + |request| request.max_step_turns = asked, + |id, question, _| (id == "move").then(|| pick(question, "wait", 0.9)), + ) + .await; + let step = &run.result.steps[0]; + assert_eq!(run.result.stop, FlowStopReason::StepFailed, "asked {asked}"); + assert_eq!(step.turns, given, "asked for {asked} turns"); + assert!( + step.note + .contains(&format!("not accomplished after {given} turns")), + "asked for {asked} turns: {}", + step.note + ); + } +} + #[tokio::test] async fn after_acting_a_finished_move_stands_unless_the_judge_leans_undone() { let run = run_with( diff --git a/crates/tinycomputer-engine/src/agentic/flow/mod.rs b/crates/tinycomputer-engine/src/agentic/flow/mod.rs index 96e4635d1..ad0b870e6 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/mod.rs +++ b/crates/tinycomputer-engine/src/agentic/flow/mod.rs @@ -97,6 +97,10 @@ const MAX_ACTIONS: u32 = 120; /// Upper bound on [`RunFlowRequest::max_model_calls`]. Jev is cheap, and /// every framing of a voted decision is one evaluation. const MAX_CALLS: u32 = 10_000; +/// Upper bound on [`RunFlowRequest::max_step_turns`]: the run's own action +/// ceiling, since a turn makes at most a move or two, so no step is given +/// more turns than the whole run has actions. +const MAX_STEP_TURNS: u32 = MAX_ACTIONS; /// Choices, picks, and entries remembered for the brief's `so_far`. const MAX_SO_FAR: usize = 12; /// Longest goal the brief carries, in characters. @@ -248,6 +252,8 @@ pub(super) struct FlowRun<'r, B> { pub(super) include_values: bool, max_actions: u32, max_calls: u32, + /// Turns one `do` step may spend before it fails. + max_step_turns: u32, disabled: BTreeSet, pub(super) memory: Vec, pub(super) learned: Vec, diff --git a/crates/tinycomputer-engine/src/agentic/flow/run.rs b/crates/tinycomputer-engine/src/agentic/flow/run.rs index 8f7db8cf3..23eb3113f 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/run.rs +++ b/crates/tinycomputer-engine/src/agentic/flow/run.rs @@ -16,7 +16,7 @@ use tinycomputer_bus::{ use tinycomputer_core::Facts; use super::{ - Ended, FlowRun, Halt, MAX_ACTIONS, MAX_CALLS, StepLog, + Ended, FlowRun, Halt, MAX_ACTIONS, MAX_CALLS, MAX_STEP_TURNS, StepLog, backend::AgentBackend, front::Front, ledger, steps, @@ -114,6 +114,8 @@ impl<'r, B: AgentBackend + Sync> FlowRun<'r, B> { include_values: request.include_values, max_actions: request.max_actions.min(MAX_ACTIONS), max_calls: request.max_model_calls.min(MAX_CALLS), + // A step always gets a turn: with none it could only fail. + max_step_turns: request.max_step_turns.clamp(1, MAX_STEP_TURNS), disabled: request .disabled_loops .iter() diff --git a/crates/tinycomputer-engine/src/agentic/flow/steps/mod.rs b/crates/tinycomputer-engine/src/agentic/flow/steps/mod.rs index d191a7d81..43d067e40 100644 --- a/crates/tinycomputer-engine/src/agentic/flow/steps/mod.rs +++ b/crates/tinycomputer-engine/src/agentic/flow/steps/mod.rs @@ -44,8 +44,6 @@ use tinycomputer_bus::FlowAction; use super::{Ended, FlowRun, Halt, StepLog, backend::AgentBackend}; -/// Turns a `do` step may spend. -const DO_TURNS: u32 = 8; /// Turns spent opening the thing a `choose` step picks from. pub(super) const REVEAL_TURNS: u32 = 3; /// Times `open` checks for a readable window, waiting between checks. @@ -99,7 +97,7 @@ pub(super) async fn run( // then be typed as the caller's card number. FlowAction::Do(intent) => match typing::typing(intent) { Some(slot) => run.enter(log, &[slot]).await, - None => run.accomplish(log, text, DO_TURNS).await, + None => run.accomplish(log, text, run.max_step_turns).await, }, FlowAction::Enter(slots) => run.enter(log, &slots.0).await, FlowAction::Choose(choose) => run.choose(log, choose).await, diff --git a/crates/tinycomputer-engine/src/task/budget.rs b/crates/tinycomputer-engine/src/task/budget.rs index b1755721e..d31735120 100644 --- a/crates/tinycomputer-engine/src/task/budget.rs +++ b/crates/tinycomputer-engine/src/task/budget.rs @@ -15,7 +15,7 @@ use super::brief::brief; use super::names::fact_names; use super::publish::{publish, stopped_summary}; use super::store::{Cell, Run}; -use super::{DEFAULT_MODEL_CALLS, DEFAULT_VOTES, FlowRunner}; +use super::{DEFAULT_MODEL_CALLS, DEFAULT_STEP_TURNS, DEFAULT_VOTES, FlowRunner}; /// A handle to reserve host model calls against this task's Jev evaluation /// budget. Hosts must reserve before starting provider I/O; a reservation is @@ -362,6 +362,8 @@ pub(super) fn run_request( include_values: true, max_actions, max_model_calls, + // A cap on each step, never spent down: every run gets it whole. + max_step_turns: state.budget.max_step_turns.unwrap_or(DEFAULT_STEP_TURNS), votes: state.budget.votes.unwrap_or(DEFAULT_VOTES), strategy: state.budget.strategy.unwrap_or_default(), deliberation: state.budget.deliberation.unwrap_or_default(), diff --git a/crates/tinycomputer-engine/src/task/describe.rs b/crates/tinycomputer-engine/src/task/describe.rs index 21e97c635..cfac749c9 100644 --- a/crates/tinycomputer-engine/src/task/describe.rs +++ b/crates/tinycomputer-engine/src/task/describe.rs @@ -122,6 +122,12 @@ fn start_task_input() -> Value { "type": "integer", "maximum": 5, "description": "how often a failed step may be rescued by the reasoning model; 0 turns rescues off" + }, + "max_step_turns": { + "type": "integer", + "minimum": 1, + "maximum": 120, + "description": "turns one do step may spend before it fails; 8 unless set" } }}, "memory": { diff --git a/crates/tinycomputer-engine/src/task/mod.rs b/crates/tinycomputer-engine/src/task/mod.rs index 66720ef5a..d149c2737 100644 --- a/crates/tinycomputer-engine/src/task/mod.rs +++ b/crates/tinycomputer-engine/src/task/mod.rs @@ -378,6 +378,10 @@ pub(crate) const DEFAULT_MODEL_CALLS: u32 = 6000; /// How many ways each decision is asked when a task's budget does not say. pub(crate) const DEFAULT_VOTES: u32 = 7; +/// Turns one `do` step may spend before it fails when a task's budget does +/// not say. +pub(crate) const DEFAULT_STEP_TURNS: u32 = 8; + /// The longest one rescue may think before the task fails without it. pub(crate) const RESCUE_TIMEOUT_MS: u64 = 120_000; diff --git a/crates/tinycomputer-engine/src/task/task_tests/approval_tests.rs b/crates/tinycomputer-engine/src/task/task_tests/approval_tests.rs index ca76f94bb..292edf847 100644 --- a/crates/tinycomputer-engine/src/task/task_tests/approval_tests.rs +++ b/crates/tinycomputer-engine/src/task/task_tests/approval_tests.rs @@ -170,6 +170,7 @@ async fn an_approval_resume_spends_from_the_tasks_remaining_budget_not_a_fresh_o flow: Some(flow(mail_flow())), budget: tinycomputer_bus::agent::TaskBudget { max_actions: Some(10), + max_step_turns: Some(20), ..tinycomputer_bus::agent::TaskBudget::default() }, ..StartTaskRequest::default() @@ -187,6 +188,10 @@ async fn an_approval_resume_spends_from_the_tasks_remaining_budget_not_a_fresh_o )); let requests = script.requests.lock().unwrap(); assert_eq!(requests.len(), 3); + assert!( + requests.iter().all(|request| request.max_step_turns == 20), + "the step turn budget caps each step, so every run gets it whole" + ); assert_eq!( requests[0].max_actions, 10, "the first run gets the full budget" diff --git a/crates/tinycomputer-engine/src/task/task_tests/describe_tests.rs b/crates/tinycomputer-engine/src/task/task_tests/describe_tests.rs index 6be80573c..461486259 100644 --- a/crates/tinycomputer-engine/src/task/task_tests/describe_tests.rs +++ b/crates/tinycomputer-engine/src/task/task_tests/describe_tests.rs @@ -244,6 +244,7 @@ async fn describe_schemas_name_every_request_field() { deliberation: Some(tinycomputer_bus::Deliberation::default()), max_elapsed_ms: Some(1), max_rescues: Some(1), + max_step_turns: Some(1), }; assert_eq!( documented(&start_schema["properties"]["budget"]), diff --git a/crates/tinycomputer-engine/src/task/task_tests/start_tests.rs b/crates/tinycomputer-engine/src/task/task_tests/start_tests.rs index a18de9c1e..1c69fdc7b 100644 --- a/crates/tinycomputer-engine/src/task/task_tests/start_tests.rs +++ b/crates/tinycomputer-engine/src/task/task_tests/start_tests.rs @@ -63,8 +63,13 @@ async fn a_finished_flow_is_done_with_its_reads_and_no_fact_values() { ); assert!(!request.allow_destructive); assert_eq!( - (request.max_actions, request.max_model_calls, request.votes), - (120, 6000, 7) + ( + request.max_actions, + request.max_model_calls, + request.max_step_turns, + request.votes + ), + (120, 6000, 8, 7) ); assert!(request.facts.is_empty(), "an email is shared, not secret"); assert_eq!(request.brief.details["email"], "asha@example.com"); diff --git a/crates/tinycomputer-skills/schemas/start_task.schema.json b/crates/tinycomputer-skills/schemas/start_task.schema.json index f399c8905..0161fe497 100644 --- a/crates/tinycomputer-skills/schemas/start_task.schema.json +++ b/crates/tinycomputer-skills/schemas/start_task.schema.json @@ -36,7 +36,8 @@ "votes": {"type": "integer", "description": "How many ways each decision is asked before its answers are averaged."}, "strategy": {"type": "string", "enum": ["narrow", "wide"], "description": "How each decision is asked: many small requests (narrow, the default), or one request per turn over a digest of the screen with a working memory (wide)."}, "deliberation": {"type": "string", "enum": ["off", "standard", "deep"], "description": "How much each decision is deliberated before acting: deep (the default) escalates close calls with more framings, pairwise duels, and contrasting questions, checks every action's effect, and undoes and retries mistakes; standard does less; off uses single thresholds."}, - "max_rescues": {"type": "integer", "minimum": 0, "maximum": 5, "description": "How many failed steps a reasoning model may rescue with guidance before the task fails (default and most 5; 0 turns rescues off). Needs the module's planner configuration."} + "max_rescues": {"type": "integer", "minimum": 0, "maximum": 5, "description": "How many failed steps a reasoning model may rescue with guidance before the task fails (default and most 5; 0 turns rescues off). Needs the module's planner configuration."}, + "max_step_turns": {"type": "integer", "minimum": 1, "maximum": 120, "description": "Turns one do step may spend before it fails (default 8, most 120). A cap on each step, not a pool the task spends; raise it for steps on cluttered pages that need many moves, or split such a step."} } }, "trace": {"type": "boolean"}, diff --git a/crates/tinycomputer/tests/public_api_tests.rs b/crates/tinycomputer/tests/public_api_tests.rs index 9497a15c0..fa11ff982 100644 --- a/crates/tinycomputer/tests/public_api_tests.rs +++ b/crates/tinycomputer/tests/public_api_tests.rs @@ -34,7 +34,7 @@ fn the_crate_re_exports_the_contract_rather_than_redefining_it() { #[test] fn the_shipped_contract_binds_to_itself() { assert!(is_compatible(CONTRACT_VERSION)); - assert_eq!(CONTRACT_VERSION, (2, 26)); + assert_eq!(CONTRACT_VERSION, (2, 27)); assert!(!is_compatible((2, 25))); } diff --git a/docs/crates/tinycomputer-bus/agent-and-tasks.md b/docs/crates/tinycomputer-bus/agent-and-tasks.md index 45648e410..4f2b1811a 100644 --- a/docs/crates/tinycomputer-bus/agent-and-tasks.md +++ b/docs/crates/tinycomputer-bus/agent-and-tasks.md @@ -113,7 +113,10 @@ the module's own default rather than the crate baking one in twice: `max_rescues`, how many times a failed step may be handed to a reasoning model for guidance before the task gives up on it. Absent means the module's default, currently 5 (also the maximum); `0` turns rescues off. See -[Rescue](../../rescue.md) for what a rescue actually does. +[Rescue](../../rescue.md) for what a rescue actually does. `max_step_turns` +is how many turns one `do` step may spend before it fails, 8 unless set and +at most 120: a cap on each step, not a pool the task spends, so every run +of the task gets it whole. ### Asking for a shaped answer diff --git a/docs/crates/tinycomputer-bus/flows.md b/docs/crates/tinycomputer-bus/flows.md index 682f580dc..3b59f6b7e 100644 --- a/docs/crates/tinycomputer-bus/flows.md +++ b/docs/crates/tinycomputer-bus/flows.md @@ -113,6 +113,7 @@ pub struct RunFlowRequest { pub include_values: bool, // may ordinary field values reach the decision model? pub max_actions: u32, // default 60, capped at 120 pub max_model_calls: u32, // default 3000, capped at 10000 + pub max_step_turns: u32, // turns per do step: default 8, capped at 120 pub votes: u32, // default 7, capped at 9 pub brief: FlowBrief, pub disabled_loops: Vec, // empty in production; for measurement diff --git a/docs/crates/tinycomputer-bus/versioning.md b/docs/crates/tinycomputer-bus/versioning.md index b4767f549..f8ca24847 100644 --- a/docs/crates/tinycomputer-bus/versioning.md +++ b/docs/crates/tinycomputer-bus/versioning.md @@ -9,7 +9,7 @@ code, so this page exists mostly to keep them apart. ## `CONTRACT_VERSION`: does this host understand this module ```rust,ignore -pub const CONTRACT_VERSION: (u32, u32) = (2, 26); +pub const CONTRACT_VERSION: (u32, u32) = (2, 27); ``` This describes the *vocabulary*: the member set and the payload shapes, @@ -45,15 +45,16 @@ Two conditions, both necessary: relies on changed shape or disappeared, so a mismatched major is refused outright, in either direction. 2. **The module must be at least as new, minor-wise, as the host.** A host - built against `(2, 26)` expects at least the members and fields that - existed at `(2, 26)`. A module reporting `(2, 25)` predates the - `TraceSinkHost` callback added in 2.26, so a 2.26 host rejects it. It does - include `BrowserEgressHost`, which was added in 2.25. A newer module with + built against `(2, 27)` expects at least the members and fields that + existed at `(2, 27)`. A module reporting `(2, 26)` predates the + `max_step_turns` budget field added in 2.27, so a 2.27 host rejects it: it + would run every `do` step on eight turns whatever the host asked for. It + does include `TraceSinkHost`, which was added in 2.26. A newer module with the same major is accepted. ```rust,ignore -assert!(is_compatible(CONTRACT_VERSION)); // (2, 26), the exact version this crate ships -assert!(is_compatible((2, 27))); // a newer, still-compatible module +assert!(is_compatible(CONTRACT_VERSION)); // (2, 27), the exact version this crate ships +assert!(is_compatible((2, 28))); // a newer, still-compatible module assert!(!is_compatible((2, 11))); // an older module, missing something assert!(!is_compatible((2, 25))); // predates TraceSinkHost; includes BrowserEgressHost from 2.25 assert!(!is_compatible((1, 10))); // a different major, all bets off diff --git a/docs/crates/tinycomputer-engine/flow/budgets-and-switches.md b/docs/crates/tinycomputer-engine/flow/budgets-and-switches.md index aee54c088..c28c66bfa 100644 --- a/docs/crates/tinycomputer-engine/flow/budgets-and-switches.md +++ b/docs/crates/tinycomputer-engine/flow/budgets-and-switches.md @@ -5,10 +5,13 @@ be turned off individually. This page is the reference for both. ## The two hard budgets -A run is capped on two things, whatever the request asks for: +A run is capped on three things, whatever the request asks for: - **actions**: at most 120 (`MAX_ACTIONS`), whatever `max_actions` in the request asks for; the default is 60. +- **turns per `do` step**: at most 120 (`MAX_STEP_TURNS`, the action + ceiling), whatever `max_step_turns` asks for; the default is 8, and a step + always gets at least one. - **Jev calls**: at most 10,000 (`MAX_CALLS`), whatever `max_model_calls` asks for; the default is 3,000. Every framing of a voted decision counts as one call, so voting with more framings spends @@ -32,7 +35,7 @@ and the module's own hard cap from 5,000 to 10,000. See | What | Limit | Why | |---|---|---| -| Turns in a `do` step | 8 (`DO_TURNS`) | a step that needs more presses than this should be split into more than one step | +| Turns in a `do` step | `max_step_turns` in the request: 8 unless set, at most 120 (`MAX_STEP_TURNS`) | a step that needs more presses than this should be split into more than one step, or the run given more turns per step | | Options in one Choice | 20 plus `none` (`CAP`) | a bigger pool is narrowed, never silently truncated | | Obstacles dismissed per step | 2 (`MAX_OBSTACLES`) | | | Undos from the `do` loop's own regression check | 2 per step (`MAX_UNDOS`) | shared between "progress dropped" and "didn't help" | diff --git a/docs/crates/tinycomputer-engine/flow/the-do-loop.md b/docs/crates/tinycomputer-engine/flow/the-do-loop.md index d4ce37d23..14c334a47 100644 --- a/docs/crates/tinycomputer-engine/flow/the-do-loop.md +++ b/docs/crates/tinycomputer-engine/flow/the-do-loop.md @@ -2,8 +2,9 @@ Most of a flow is plain strings: "start a new email message", "search for flights", "calculate 128 times 37". Each one runs the same loop, for up to -eight turns (`DO_TURNS`), in `act/`. This is the loop people usually mean -when they talk about "the loop." +`max_step_turns` turns (eight unless the request says otherwise, 120 at +most; a task sets it through `budget.max_step_turns`), in `act/`. This is +the loop people usually mean when they talk about "the loop." ## One turn @@ -218,11 +219,13 @@ look. ### Running out of turns -After eight turns with no end, the runtime looks one last time. If the -completion estimate reaches 0.75, the step is `Done` anyway; otherwise it -fails with "not accomplished after 8 turns." A long key sequence, like -several calculator presses in a row, is the clearest way to hit this: split -it into more than one step rather than relying on eight turns to cover it. +After its turns run out with no end (eight unless the request gives it +more), the runtime looks one last time. If the completion estimate reaches +0.75, the step is `Done` anyway; otherwise it fails with "not accomplished +after 8 turns." A long key sequence, like several calculator presses in a +row, is the clearest way to hit this: split it into more than one step, or +give the run more turns per step, rather than relying on eight turns to +cover it. ## Deliberation changes the thresholds above diff --git a/docs/crates/tinycomputer-engine/tasks.md b/docs/crates/tinycomputer-engine/tasks.md index df73401ac..ceb2b256a 100644 --- a/docs/crates/tinycomputer-engine/tasks.md +++ b/docs/crates/tinycomputer-engine/tasks.md @@ -178,6 +178,7 @@ pub struct TaskBudget { pub deliberation: Option, pub max_elapsed_ms: Option, // default: unbounded pub max_rescues: Option, // default 5, also the ceiling + pub max_step_turns: Option, // default 8, capped at 120; per step } ``` diff --git a/docs/crates/tinycomputer-skills/walking-the-schemas.md b/docs/crates/tinycomputer-skills/walking-the-schemas.md index c7b224791..42491dd97 100644 --- a/docs/crates/tinycomputer-skills/walking-the-schemas.md +++ b/docs/crates/tinycomputer-skills/walking-the-schemas.md @@ -92,7 +92,8 @@ covered in more depth in [Safety and privacy](../../safety-and-privacy.md). "votes": {"type": "integer", ...}, "strategy": {"type": "string", "enum": ["narrow", "wide"], ...}, "deliberation": {"type": "string", "enum": ["off", "standard", "deep"], ...}, - "max_rescues": {"type": "integer", "minimum": 0, "maximum": 5, ...} + "max_rescues": {"type": "integer", "minimum": 0, "maximum": 5, ...}, + "max_step_turns": {"type": "integer", "minimum": 1, "maximum": 120, ...} } } ``` @@ -105,7 +106,9 @@ two settings that trade speed for care rather than capping anything: `deep`, the default, `standard`, or `off`). `max_rescues` caps how many times a failed step may be handed to a reasoning model for another way forward, from 0 (off) up to 5, and needs a planner configured to do -anything at all. These map directly onto the budget concepts explained for +anything at all. `max_step_turns` is how many turns one `do` step may spend +before it fails, 8 unless set and at most 120: a cap on each step rather +than a pool the task spends. These map directly onto the budget concepts explained for a human reader in [Giving it a task](../../giving-it-a-task.md#limits-you-can-set), and onto the deeper mechanics in [`docs/technical/decision-loops.md`](../../technical/decision-loops.md) and diff --git a/docs/giving-it-a-task.md b/docs/giving-it-a-task.md index 68cb90a1d..ab0e0de44 100644 --- a/docs/giving-it-a-task.md +++ b/docs/giving-it-a-task.md @@ -98,7 +98,9 @@ A budget caps how much a task can do, across all of its runs: - `max_elapsed_ms`: how long it may work. Time spent waiting for you doesn't count; - `max_rescues`: how many times a failed step may be rescued, 0 to 5 - (default 5). + (default 5); +- `max_step_turns`: turns one `do` step may spend before it fails, 1 to 120 + (default 8). A cap on each step, not a pool the task spends. Pausing for your approval never refills the budget. The task picks up with whatever is left. diff --git a/docs/technical/decision-loops.md b/docs/technical/decision-loops.md index 73a1240b2..4bb3897a9 100644 --- a/docs/technical/decision-loops.md +++ b/docs/technical/decision-loops.md @@ -164,8 +164,9 @@ the state it saw. ## The `do` loop A plain string step (or `{"do": ...}`) runs `FlowRun::accomplish` for up to -eight turns (`DO_TURNS`). This is the loop most people mean when they say "the -loop". One turn goes like this: +`max_step_turns` turns (eight unless the request says otherwise, 120 at +most). This is the loop most people mean when they say "the loop". One turn +goes like this: ```text look ──► note what the last action changed ──► judge ──► done? ──yes──► end step @@ -317,9 +318,10 @@ overlay leaves no trace afterward for the judge to read. The same check runs once more after the very last turn, so a dismissal that lands on the last permitted turn is not reported as failed for want of another look. -After eight turns without an end, the runtime looks one last time. If the -completion estimate reaches 0.75 the step is `Done`; otherwise it fails with -"not accomplished after 8 turns". +After its turns run out without an end (eight unless the request gives it +more), the runtime looks one last time. If the completion estimate reaches +0.75 the step is `Done`; otherwise it fails with "not accomplished after 8 +turns". ## Grounding: picking one element diff --git a/docs/technical/decision-thresholds.md b/docs/technical/decision-thresholds.md index c65e94e10..67334646a 100644 --- a/docs/technical/decision-thresholds.md +++ b/docs/technical/decision-thresholds.md @@ -32,7 +32,7 @@ Change a constant and its row together. | `CAP` | 20 | `ask/mod.rs` | most options in one Choice | | `HEDGED` | 0.10 | `ask/answers.rs` | distance from an even chance within which a condition's calibrated yes/no says nothing either way, and defers to a crisp coverage | | `CRISP_TOP` | 0.85 | `ask/answers.rs` | probability on a condition's top coverage level at which it stands alone for a hedged yes/no | -| `DO_TURNS` | 8 | `steps/mod.rs` | turns a `do` step may spend | +| `MAX_STEP_TURNS` | 120 | `mod.rs` | most turns a `do` step may be given; `RunFlowRequest.max_step_turns` asks for fewer, 8 unless set | | `REFLECT_FLOOR` | 0.50 | `reflect.rs` | belief that a pressed `choose` left its choice, below which it is repaired, and failed if the repair does not take | | `REPAIR_TURNS` | 4 | `reflect.rs` | turns one reflection repair may spend | | `MAX_ACTIONS` / `MAX_CALLS` | 120 / 10000 | `mod.rs` | per-run caps on actions and Jev calls | diff --git a/docs/technical/specs/desktop-module-contract.md b/docs/technical/specs/desktop-module-contract.md index 79d556918..538b8bbff 100644 --- a/docs/technical/specs/desktop-module-contract.md +++ b/docs/technical/specs/desktop-module-contract.md @@ -120,6 +120,12 @@ configuration, existing desktop trace path and session behavior remain in effect. Hosts should upsert reports by task id because callers may request the same report more than once. +Step turn budget (2.27): `TaskBudget` and `RunFlowRequest` accept the optional +`max_step_turns`, the turns one `do` step may spend before it fails: 8 unless +set, and capped by the module at its action ceiling, 120. It caps each step +rather than being spent by the task, so every run of a task gets it whole. A +2.26 module ignores the field and gives every `do` step eight turns. + Host-held secret facts (2.22): `StartTask` and `RunFlow` accept optional `fact_handles`, keyed by fact name. Each entry carries only the host's opaque handle, a safe mask, and a kind. These fields are confidential request data. diff --git a/docs/technical/tasks.md b/docs/technical/tasks.md index 134f3b4ee..6054a76c9 100644 --- a/docs/technical/tasks.md +++ b/docs/technical/tasks.md @@ -164,6 +164,9 @@ is acted on: `deep` (the default), `standard`, or `off` spends calls only where the evidence is thin, and degrades rung by rung when the budget runs short rather than failing the run. `budget.max_rescues` caps how many failed steps are rescued (below). +`budget.max_step_turns` caps the turns one `do` step may spend before it +fails, 8 unless set and at most 120; it caps each step rather than being +spent, so every run of the task gets it whole. The flow runtime has no clock, so `max_elapsed_ms` is enforced by the controller, which times out a run that would go past what is left. Time spent waiting for the caller does not count.