1use ainl_memory::{GraphMemory, GraphStore};
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
11pub struct RuntimeConfig {
12 pub max_delegation_depth: u32,
14
15 pub enable_graph_memory: bool,
17}
18
19impl Default for RuntimeConfig {
20 fn default() -> Self {
21 Self {
22 max_delegation_depth: 10,
23 enable_graph_memory: true,
24 }
25 }
26}
27
28pub struct RuntimeContext {
30 _config: RuntimeConfig,
31 memory: Option<GraphMemory>,
32}
33
34impl RuntimeContext {
35 pub fn new(config: RuntimeConfig, memory: Option<GraphMemory>) -> Self {
37 Self {
38 _config: config,
39 memory,
40 }
41 }
42
43 pub fn record_delegation(
45 &self,
46 delegated_to: String,
47 trace_event: Option<serde_json::Value>,
48 ) -> Result<uuid::Uuid, String> {
49 if let Some(ref memory) = self.memory {
50 memory.write_episode(
51 vec!["agent_delegate".to_string()],
52 Some(delegated_to),
53 trace_event,
54 )
55 } else {
56 Err("Memory not initialized".to_string())
57 }
58 }
59
60 pub fn record_tool_execution(
62 &self,
63 tool_name: String,
64 trace_event: Option<serde_json::Value>,
65 ) -> Result<uuid::Uuid, String> {
66 if let Some(ref memory) = self.memory {
67 memory.write_episode(vec![tool_name], None, trace_event)
68 } else {
69 Err("Memory not initialized".to_string())
70 }
71 }
72
73 pub fn store(&self) -> Option<&dyn GraphStore> {
75 self.memory.as_ref().map(|m| m.store())
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn test_runtime_config_default() {
85 let config = RuntimeConfig::default();
86 assert_eq!(config.max_delegation_depth, 10);
87 assert!(config.enable_graph_memory);
88 }
89}