blyte_agent/state.rs
1//! Execution state, split by authority rather than by who happens to write.
2//!
3//! The split that follows:
4//!
5//! | region | written by | agent may mutate |
6//! |---|---|---|
7//! | [`Brief`] -- goal, gate | human or calling agent | **never** |
8//! | [`Runtime`] -- observed facts | the harness | no |
9//!
10//! The first is the load-bearing one. A control plane whose worker can author its own
11//! definition of done is self-grading with extra steps, which is the failure this project spent
12//! a week establishing. Enforcing it in the type system means it cannot be undone by a prompt.
13
14use serde::{Deserialize, Serialize};
15
16/// What the conversation model decided. The worker reads this and can never change it.
17///
18/// There is deliberately no `&mut` accessor and no setter. Blyte previously asserted
19/// "the orchestrator states the verification command" as doctrine while the code happily let
20/// the worker's own test become the gate; making it structurally impossible is the difference
21/// between a rule and a property.
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
23pub struct Brief {
24 /// What success means, in prose, for the worker.
25 pub goal: String,
26 /// The shell command whose exit code decides completion. Exit 0 and only exit 0.
27 pub verification_cmd: String,
28 #[serde(default)]
29 pub max_cost_usd: Option<f64>,
30 /// Set for `blyte --converse`: the conversation model's instructions, which replace the implementer's
31 /// framing in the system prompt.
32 #[serde(default, skip_serializing_if = "Option::is_none")]
33 pub instructions: Option<String>,
34}
35
36/// Facts the harness observed. Not opinions, and not reported by the worker.
37#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
38pub struct Runtime {
39 pub rollbacks: u32,
40 /// The conversation so far, kept across prompts in an interactive session. `None`: each run starts
41 /// fresh (one-shot runs and dispatches). `Some`: the run continues it and stores it back.
42 #[serde(default, skip_serializing_if = "Option::is_none")]
43 pub conversation: Option<Vec<blyte_provider::Message>>,
44 /// The goal of the conversation's first prompt; the system prompt is built from it for the whole
45 /// conversation, so it stays identical and its cache holds.
46 #[serde(default, skip_serializing_if = "Option::is_none")]
47 pub conversation_goal: Option<String>,
48 /// Extra parts (such as images) attached to the next user prompt only; never serialised.
49 #[serde(skip)]
50 pub pending_user_parts: Vec<blyte_provider::UserPart>,
51}
52
53/// Execution state across two regions: [`Brief`] and [`Runtime`].
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
55pub struct State {
56 pub brief: Brief,
57 pub runtime: Runtime,
58}
59
60impl State {
61 pub fn new(goal: impl Into<String>, verification_cmd: impl Into<String>) -> Self {
62 Self {
63 brief: Brief {
64 goal: goal.into(),
65 verification_cmd: verification_cmd.into(),
66 max_cost_usd: None,
67 instructions: None,
68 },
69 runtime: Runtime::default(),
70 }
71 }
72}