Skip to main content

vtcode_core/core/agent/
steering.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3use uuid::Uuid;
4
5/// Maximum number of follow-up intents held by a runtime before new intents
6/// park in the overflow buffer. The overflow buffer keeps rapid influx from
7/// silently dropping user messages; once both buffers are full the caller
8/// receives `FollowUpQueueFull` so back-pressure stays visible.
9pub const MAX_QUEUED_FOLLOW_UP_INTENTS: usize = 64;
10/// Overflow park capacity after the primary FIFO is full. Combined with the
11/// primary cap this bounds total retained follow-ups while still absorbing
12/// a burst instead of discarding it.
13pub const MAX_OVERFLOW_FOLLOW_UP_INTENTS: usize = 64;
14/// Maximum number of applied follow-up IDs retained for restart recovery.
15pub const MAX_APPLIED_FOLLOW_UP_INTENT_IDS: usize = 64;
16
17/// Origin of a queued follow-up, preserved when it is applied to conversation history.
18#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
19#[serde(rename_all = "snake_case")]
20pub enum FollowUpProvenance {
21    /// Input supplied by a user through the steering interface.
22    #[default]
23    UserInput,
24    /// A harness-generated continuation or recovery instruction.
25    Synthetic,
26}
27
28/// A follow-up instruction with a stable identity for recovery and
29/// de-duplication.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct QueuedFollowUpIntent {
32    id: String,
33    text: String,
34    /// Defaults to user input for envelopes written before provenance existed.
35    #[serde(default)]
36    provenance: FollowUpProvenance,
37}
38
39impl QueuedFollowUpIntent {
40    /// Create a new intent with a UUIDv4 identity.
41    #[must_use]
42    pub fn new(text: String) -> Self {
43        Self::new_with_provenance(text, FollowUpProvenance::UserInput)
44    }
45
46    /// Create a new intent with an explicit source and UUIDv4 identity.
47    #[must_use]
48    pub fn new_with_provenance(text: String, provenance: FollowUpProvenance) -> Self {
49        Self { id: Uuid::new_v4().to_string(), text, provenance }
50    }
51
52    /// Reconstruct an intent recovered from durable state.
53    pub fn from_parts(id: impl Into<String>, text: impl Into<String>) -> Self {
54        Self::from_parts_with_provenance(id, text, FollowUpProvenance::UserInput)
55    }
56
57    /// Reconstruct an intent recovered from durable state with its source.
58    pub fn from_parts_with_provenance(
59        id: impl Into<String>,
60        text: impl Into<String>,
61        provenance: FollowUpProvenance,
62    ) -> Self {
63        Self { id: id.into(), text: text.into(), provenance }
64    }
65
66    #[must_use]
67    pub fn id(&self) -> &str {
68        &self.id
69    }
70
71    #[must_use]
72    pub fn text(&self) -> &str {
73        &self.text
74    }
75
76    #[must_use]
77    pub const fn provenance(&self) -> FollowUpProvenance {
78        self.provenance
79    }
80
81    /// Consume the intent and return its user-visible text.
82    #[must_use]
83    pub fn into_parts(self) -> (String, String) {
84        (self.id, self.text)
85    }
86
87    /// Consume the intent and return its identity, text, and source.
88    #[must_use]
89    pub fn into_parts_with_provenance(self) -> (String, String, FollowUpProvenance) {
90        (self.id, self.text, self.provenance)
91    }
92}
93
94/// Error returned when a runtime cannot accept another follow-up intent.
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct FollowUpQueueFull {
97    pub capacity: usize,
98}
99
100impl fmt::Display for FollowUpQueueFull {
101    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102        write!(f, "follow-up intent queue is full (capacity {})", self.capacity)
103    }
104}
105
106impl std::error::Error for FollowUpQueueFull {}
107
108/// Messages used to steer the agent's execution loop from an external source.
109#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
110pub enum SteeringMessage {
111    /// Stop the agent's execution loop immediately (Steering).
112    SteerStop,
113    /// Pause the agent's execution loop.
114    Pause,
115    /// Resume the agent's execution loop.
116    Resume,
117    /// Inject input as a follow-up user message. The turn loop applies it to
118    /// live history at the next iteration boundary (mid-turn steering) or, if
119    /// the turn ends first, delivers it at the next turn boundary.
120    FollowUpInput(String),
121}