coro_core/agent/
execution.rs

1//! Agent execution result structures
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Result of agent execution
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct AgentExecution {
9    /// Whether the execution was successful
10    pub success: bool,
11
12    /// Final result message
13    pub final_result: String,
14
15    /// Number of steps executed
16    pub steps_executed: usize,
17
18    /// Total execution time in milliseconds
19    pub duration_ms: u64,
20
21    /// Optional structured data
22    pub data: Option<serde_json::Value>,
23
24    /// Optional metadata
25    pub metadata: Option<HashMap<String, serde_json::Value>>,
26}
27
28impl AgentExecution {
29    /// Create a successful execution result
30    pub fn success(final_result: String, steps_executed: usize, duration_ms: u64) -> Self {
31        Self {
32            success: true,
33            final_result,
34            steps_executed,
35            duration_ms,
36            data: None,
37            metadata: None,
38        }
39    }
40
41    /// Create a failed execution result
42    pub fn failure(error: String, steps_executed: usize, duration_ms: u64) -> Self {
43        Self {
44            success: false,
45            final_result: format!("Execution failed: {}", error),
46            steps_executed,
47            duration_ms,
48            data: None,
49            metadata: None,
50        }
51    }
52
53    /// Add structured data to the result
54    pub fn with_data(mut self, data: serde_json::Value) -> Self {
55        self.data = Some(data);
56        self
57    }
58
59    /// Add metadata to the result
60    pub fn with_metadata(mut self, metadata: HashMap<String, serde_json::Value>) -> Self {
61        self.metadata = Some(metadata);
62        self
63    }
64}