zagens_core/engine/turn_loop/control.rs
1//! Turn-loop control-flow results returned by host hooks (P2 PR4).
2
3use crate::engine::streaming::ToolUseState;
4use crate::error_taxonomy::ErrorCategory;
5use crate::turn::TurnOutcomeStatus;
6
7/// Control return from `handle_no_tool_uses` / subagent wait paths.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum TurnLoopControl {
10 /// Keep iterating the outer turn loop (`continue`).
11 Continue,
12 /// Exit the outer loop (`break`).
13 Break,
14 /// End the turn immediately.
15 Return(TurnOutcomeStatus, Option<String>),
16}
17
18/// Result of [`super::tool_phase::run_tool_execution_phase`].
19#[derive(Debug, Default)]
20pub struct TurnLoopToolPhaseOutcome {
21 pub step_error_count: usize,
22 pub step_error_categories: Vec<ErrorCategory>,
23 /// `stop_after_plan_tool` or loop-guard halt — exit the outer turn loop.
24 pub break_outer_loop: bool,
25 /// The break was caused by a [`LoopGuard`](crate::engine::loop_guard::LoopGuard)
26 /// halt (a tool failed too many times in a row), as opposed to a plan-mode
27 /// `update_plan` stop. Lets the outer loop offer a long-horizon
28 /// "change approach" continuation instead of a silent `Completed`.
29 pub loop_guard_halted: bool,
30 /// Capacity post-tool checkpoint requested another model step.
31 pub continue_outer_loop: bool,
32}
33
34/// Result of [`super::streaming_phase::run_streaming_phase`].
35#[derive(Debug, Default)]
36pub struct TurnLoopStreamingPhaseOutcome {
37 /// Parsed tool calls from the model stream (empty → no tool phase this step).
38 pub tool_uses: Vec<ToolUseState>,
39 /// Steer messages queued during streaming (drained after tool phase).
40 pub pending_steers: Vec<String>,
41 /// Retry the outer turn loop (stream died with nothing / `handle_no_tool_uses` continue).
42 pub continue_outer_loop: bool,
43 /// Exit the outer turn loop (`handle_no_tool_uses` break).
44 pub break_outer_loop: bool,
45 /// End the turn immediately (`handle_no_tool_uses` return or fatal stream error).
46 pub return_early: Option<(TurnOutcomeStatus, Option<String>)>,
47}