Skip to main content

hanzo_agent/
result.rs

1//! Result types for agent runs
2
3use crate::types::{InputItem, ModelResponse, RunItem, Usage};
4use serde::{Deserialize, Serialize};
5
6/// Result of an agent run
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct RunResult {
9    /// The original input
10    pub input: Vec<InputItem>,
11
12    /// New items generated during the run
13    pub new_items: Vec<RunItem>,
14
15    /// Raw model responses
16    pub raw_responses: Vec<ModelResponse>,
17
18    /// The final output
19    pub final_output: String,
20
21    /// Total usage statistics
22    pub usage: Usage,
23}
24
25impl RunResult {
26    /// Create a new run result
27    pub fn new(
28        input: Vec<InputItem>,
29        new_items: Vec<RunItem>,
30        raw_responses: Vec<ModelResponse>,
31        final_output: String,
32        usage: Usage,
33    ) -> Self {
34        Self {
35            input,
36            new_items,
37            raw_responses,
38            final_output,
39            usage,
40        }
41    }
42
43    /// Convert the result back to a list of input items
44    ///
45    /// This merges the original input with all new items,
46    /// useful for continuing a conversation.
47    pub fn to_input_list(&self) -> Vec<InputItem> {
48        let mut items = self.input.clone();
49        items.extend(self.new_items.iter().map(|item| item.to_input_item()));
50        items
51    }
52
53    /// Get the last message content from the result
54    pub fn last_message(&self) -> Option<&str> {
55        self.new_items.iter().rev().find_map(|item| {
56            if let RunItem::Message { content, .. } = item {
57                Some(content.as_str())
58            } else {
59                None
60            }
61        })
62    }
63}
64
65/// Streaming result (placeholder for future implementation)
66#[derive(Debug)]
67pub struct RunResultStreaming {
68    // TODO: Implement streaming support
69    _placeholder: (),
70}
71
72impl RunResultStreaming {
73    pub(crate) fn _new() -> Self {
74        Self { _placeholder: () }
75    }
76}