Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/tinycomputer-bus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions crates/tinycomputer-bus/src/agent/agent_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down
6 changes: 6 additions & 0 deletions crates/tinycomputer-bus/src/agent/types/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
/// 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<u32>,
}

/// `AwaitTask`: wait for a task to need something or finish.
Expand Down
9 changes: 7 additions & 2 deletions crates/tinycomputer-bus/src/flow/flow_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions crates/tinycomputer-bus/src/flow/types/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions crates/tinycomputer-bus/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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)));
/// ```
Expand Down
8 changes: 6 additions & 2 deletions crates/tinycomputer-bus/src/version/version_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
Expand All @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion crates/tinycomputer-engine/src/agentic/flow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions crates/tinycomputer-engine/src/agentic/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<FlowLoop>,
pub(super) memory: Vec<GroundingHint>,
pub(super) learned: Vec<GroundingHint>,
Expand Down
4 changes: 3 additions & 1 deletion crates/tinycomputer-engine/src/agentic/flow/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions crates/tinycomputer-engine/src/agentic/flow/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -99,7 +97,7 @@ pub(super) async fn run<B: AgentBackend + Sync>(
// 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,
Expand Down
4 changes: 3 additions & 1 deletion crates/tinycomputer-engine/src/task/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions crates/tinycomputer-engine/src/task/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions crates/tinycomputer-engine/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down
9 changes: 7 additions & 2 deletions crates/tinycomputer-engine/src/task/task_tests/start_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion crates/tinycomputer-skills/schemas/start_task.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion crates/tinycomputer/tests/public_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
5 changes: 4 additions & 1 deletion docs/crates/tinycomputer-bus/agent-and-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/crates/tinycomputer-bus/flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlowLoop>, // empty in production; for measurement
Expand Down
Loading
Loading