Skip to main content

agentmux_srv_core/backend/supervisor/
message.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The continuation a supervised agent receives (spec §3.5): srv's header, a
5//! fixed instruction for the mode, and the judge's reason and next step,
6//! quoted so model text can neither add a line nor open a marker.
7
8use crate::backend::reactive::sanitize::{quote_in_system_note, supervisor_turn_message};
9
10use super::judge::TEXT_MAX_CHARS;
11use super::SupervisorMode;
12
13const STEADY: &str = "Continue the task you were already doing. Ask the user only if something truly needs them.";
14
15const DRIVE: &str = "Keep going without waiting for confirmation. Research open questions thoroughly, choose the \
16best option on your own judgement, and say what you assumed. Stop and ask only for something irreversible or \
17outward-facing, for something only the user can provide, or if you are blocked.";
18
19const CLOSING: &str = "If the work is done, say so and show the evidence.";
20
21/// The full text for continuation `n` of `of`.
22pub fn continuation(mode: SupervisorMode, n: u32, of: u32, reason: &str, next: &str) -> String {
23    let mut body = String::from(if mode == SupervisorMode::Drive { DRIVE } else { STEADY });
24    body.push(' ');
25    body.push_str(CLOSING);
26    let reason = quote(reason);
27    if !reason.is_empty() {
28        body.push_str("\nWhy: ");
29        body.push_str(&reason);
30    }
31    let next = quote(next);
32    if mode == SupervisorMode::Drive && !next.is_empty() {
33        body.push_str("\nSuggested next step: ");
34        body.push_str(&next);
35    }
36    supervisor_turn_message(mode.as_str(), n, of, &body)
37}
38
39/// Model text, flattened to one line, markers quoted, capped.
40fn quote(text: &str) -> String {
41    let quoted = quote_in_system_note(text);
42    if quoted.chars().count() <= TEXT_MAX_CHARS {
43        return quoted;
44    }
45    let mut out: String = quoted.chars().take(TEXT_MAX_CHARS - 1).collect();
46    out.push('…');
47    out
48}