Skip to main content

printobserver_supervisor_api/
assessment.rs

1//! What a supervision turn answers with.
2//!
3//! [`AgentAssessment`] is the shape [`TurnOutcome`](crate::TurnOutcome)
4//! carries: the agent's written record of one turn, produced by the adapter
5//! behind this port against the schema this type generates — which is the one
6//! artifact the agent's answer may be constrained by. It is declared here,
7//! beside the port whose answer carries it, so that what an assessment says
8//! is the supervisor port's to change and nothing central's.
9
10use printobserver_types::contract::Sample;
11use printobserver_types::schemars::JsonSchema;
12use printobserver_types::serde::{Deserialize, Serialize};
13
14/// How sure the agent is.
15///
16/// A closed vocabulary rather than a number, because a number invites a
17/// precision the agent does not have.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
19#[serde(
20    crate = "printobserver_types::serde",
21    rename_all = "snake_case",
22    deny_unknown_fields
23)]
24#[schemars(crate = "printobserver_types::schemars")]
25pub enum Confidence {
26    /// Not sure.
27    Low,
28    /// Fairly sure.
29    Medium,
30    /// Sure.
31    High,
32}
33
34/// The agent's written record of one supervision turn.
35///
36/// This is deliberately not how the agent acts: acting is a
37/// `PrintAction` that policy rules on.
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
39#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
40#[schemars(crate = "printobserver_types::schemars")]
41pub struct AgentAssessment {
42    /// One line saying what is happening.
43    pub summary: String,
44    /// How sure the agent is.
45    pub confidence: Confidence,
46    /// Whether the print should carry on.
47    pub should_continue: bool,
48    /// What the agent did.
49    pub did: String,
50    /// Why it did it.
51    pub why: String,
52    /// Whether the agent is escalating to a person.
53    pub escalating: bool,
54}
55
56impl Sample for Confidence {
57    fn sample_full() -> Self {
58        Self::Medium
59    }
60}
61
62impl Sample for AgentAssessment {
63    fn sample_full() -> Self {
64        Self {
65            summary: "the first layer is down and adhesion looks even".to_owned(),
66            confidence: Confidence::Medium,
67            should_continue: true,
68            did: "slowed the feedrate to 80% for ten minutes".to_owned(),
69            why: "the extrusion width was widening on the long edges".to_owned(),
70            escalating: false,
71        }
72    }
73}