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/// Total follow-up slots: primary plus overflow plus the one reserved
15/// recovery slot. The memory envelope retains the same count oldest-first
16/// per snapshot.
17pub const MAX_PENDING_FOLLOW_UP_INTENTS: usize = MAX_QUEUED_FOLLOW_UP_INTENTS + MAX_OVERFLOW_FOLLOW_UP_INTENTS + 1;
18/// Maximum number of applied follow-up IDs retained for restart recovery.
19pub const MAX_APPLIED_FOLLOW_UP_INTENT_IDS: usize = 64;
20
21/// Origin of a queued follow-up, preserved when it is applied to conversation history.
22#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum FollowUpProvenance {
25    /// Input supplied by a user through the steering interface.
26    #[default]
27    UserInput,
28    /// A harness-generated continuation or recovery instruction.
29    Synthetic,
30}
31
32/// A follow-up instruction with a stable identity for recovery and
33/// de-duplication.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35pub struct QueuedFollowUpIntent {
36    id: String,
37    text: String,
38    /// Defaults to user input for envelopes written before provenance existed.
39    #[serde(default)]
40    provenance: FollowUpProvenance,
41}
42
43impl QueuedFollowUpIntent {
44    /// Create a new intent with a UUIDv4 identity.
45    #[must_use]
46    pub fn new(text: String) -> Self {
47        Self::new_with_provenance(text, FollowUpProvenance::UserInput)
48    }
49
50    /// Create a new intent with an explicit source and UUIDv4 identity.
51    #[must_use]
52    pub fn new_with_provenance(text: String, provenance: FollowUpProvenance) -> Self {
53        Self { id: Uuid::new_v4().to_string(), text, provenance }
54    }
55
56    /// Reconstruct an intent recovered from durable state.
57    pub fn from_parts(id: impl Into<String>, text: impl Into<String>) -> Self {
58        Self::from_parts_with_provenance(id, text, FollowUpProvenance::UserInput)
59    }
60
61    /// Reconstruct an intent recovered from durable state with its source.
62    pub fn from_parts_with_provenance(
63        id: impl Into<String>,
64        text: impl Into<String>,
65        provenance: FollowUpProvenance,
66    ) -> Self {
67        Self { id: id.into(), text: text.into(), provenance }
68    }
69
70    #[must_use]
71    pub fn id(&self) -> &str {
72        &self.id
73    }
74
75    #[must_use]
76    pub fn text(&self) -> &str {
77        &self.text
78    }
79
80    #[must_use]
81    pub const fn provenance(&self) -> FollowUpProvenance {
82        self.provenance
83    }
84
85    /// Consume the intent and return its user-visible text.
86    #[must_use]
87    pub fn into_parts(self) -> (String, String) {
88        (self.id, self.text)
89    }
90
91    /// Consume the intent and return its identity, text, and source.
92    #[must_use]
93    pub fn into_parts_with_provenance(self) -> (String, String, FollowUpProvenance) {
94        (self.id, self.text, self.provenance)
95    }
96}
97
98/// Error returned when a runtime cannot accept another follow-up intent.
99#[derive(Debug, Clone, PartialEq, Eq)]
100pub struct FollowUpQueueFull {
101    pub capacity: usize,
102}
103
104impl fmt::Display for FollowUpQueueFull {
105    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106        write!(f, "follow-up intent queue is full (capacity {})", self.capacity)
107    }
108}
109
110impl std::error::Error for FollowUpQueueFull {}
111
112/// Messages used to steer the agent's execution loop from an external source.
113#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
114pub enum SteeringMessage {
115    /// Stop the agent's execution loop immediately (Steering).
116    SteerStop,
117    /// Pause the agent's execution loop.
118    Pause,
119    /// Resume the agent's execution loop.
120    Resume,
121    /// Inject input as a follow-up user message. The turn loop applies it to
122    /// live history at the next iteration boundary (mid-turn steering) or, if
123    /// the turn ends first, delivers it at the next turn boundary.
124    FollowUpInput(String),
125}