Build a result from a turn that was cancelled mid-generation. Keeps the conversation accumulated so far (the user's message above all) so the next turn remembers it. Appends a short assistant marker when the log would otherwise end on a user message, so the next user turn still alternates.
(mut self)
| 216 | /// turn remembers it. Appends a short assistant marker when the log would |
| 217 | /// otherwise end on a user message, so the next user turn still alternates. |
| 218 | pub(super) fn finish_interrupted(mut self) -> AgentResult { |
| 219 | let ends_on_user = self |
| 220 | .messages |
| 221 | .last() |
| 222 | .map(|m| m.role != "assistant") |
| 223 | .unwrap_or(false); |
| 224 | if ends_on_user { |
| 225 | self.messages.push(Message { |
| 226 | role: "assistant".to_string(), |
| 227 | content: vec![ContentBlock::Text { |
| 228 | text: "(Response interrupted by the user.)".to_string(), |
| 229 | }], |
| 230 | reasoning_content: None, |
| 231 | }); |
| 232 | } |
| 233 | AgentResult { |
| 234 | text: String::new(), |
| 235 | messages: self.messages, |
| 236 | usage: self.total_usage, |
| 237 | tool_calls_count: self.tool_calls_count, |
| 238 | verification_reports: self.verification_reports, |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | fn tool_signature(tool_name: &str, args: &Value) -> String { |
| 243 | format!( |
no outgoing calls