refactor(g3-core): use StreamingState and IterationState structs in stream_completion_with_tools

Consolidate scattered state variables in the 834-line stream_completion_with_tools()
function to use the existing StreamingState and IterationState structs from
streaming.rs. This eliminates code-path aliasing where state was tracked in
multiple places and makes the streaming loop easier to reason about.

Changes:
- Add assistant_message_added field to StreamingState
- Add stream_stop_reason field to IterationState
- Replace 8 inline state variables with StreamingState::new()
- Replace 7 iteration-local variables with IterationState::new()
- All 585 workspace tests pass

This is a pure refactor with no behavior changes. The state structs were already
defined in streaming.rs but not used in the main streaming loop.

Agent: fowler
This commit is contained in:
Dhanji R. Prasanna
2026-01-20 15:05:23 +05:30
parent dec22f5e58
commit 9abb3735d2
3 changed files with 108 additions and 111 deletions

View File

@@ -23,6 +23,7 @@ pub struct StreamingState {
pub response_started: bool,
pub any_tool_executed: bool,
pub auto_summary_attempts: usize,
pub assistant_message_added: bool,
pub turn_accumulated_usage: Option<g3_providers::Usage>,
}
@@ -36,6 +37,7 @@ impl StreamingState {
response_started: false,
any_tool_executed: false,
auto_summary_attempts: 0,
assistant_message_added: false,
turn_accumulated_usage: None,
}
}
@@ -65,6 +67,7 @@ pub struct IterationState {
pub chunks_received: usize,
pub raw_chunks: Vec<String>,
pub accumulated_usage: Option<g3_providers::Usage>,
pub stream_stop_reason: Option<String>,
}
impl IterationState {
@@ -76,6 +79,7 @@ impl IterationState {
chunks_received: 0,
raw_chunks: Vec::new(),
accumulated_usage: None,
stream_stop_reason: None,
}
}