From e40a8bba72f2530dbe58d4281fd7b13f466abc7a Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Sun, 19 Apr 2026 17:39:49 -0600 Subject: [PATCH] fix: RagCache was not being used for agent and sub-agent instantiation --- src/config/agent.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/config/agent.rs b/src/config/agent.rs index 04c330d..edcd733 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -17,6 +17,7 @@ use inquire::{Text, validator::Validation}; use rust_embed::Embed; use serde::{Deserialize, Serialize}; use std::{ffi::OsStr, path::Path}; +use super::rag_cache::RagKey; const DEFAULT_AGENT_NAME: &str = "rag"; @@ -119,7 +120,16 @@ impl Agent { }; let rag = if rag_path.exists() { - Some(Arc::new(Rag::load(app, DEFAULT_AGENT_NAME, &rag_path)?)) + let key = RagKey::Agent(name.to_string()); + let app_clone = app.clone(); + let rag_path_clone = rag_path.clone(); + let rag = app_state + .rag_cache + .load_with(key, || async move { + Rag::load(&app_clone, DEFAULT_AGENT_NAME, &rag_path_clone) + }) + .await?; + Some(rag) } else if !agent_config.documents.is_empty() && !info_flag { let mut ans = false; if *IS_STDOUT_TERMINAL { @@ -152,8 +162,23 @@ impl Agent { document_paths.push(path.to_string()) } } - let rag = Rag::init(app, "rag", &rag_path, &document_paths, abort_signal).await?; - Some(Arc::new(rag)) + let key = RagKey::Agent(name.to_string()); + let app_clone = app.clone(); + let rag_path_clone = rag_path.clone(); + let rag = app_state + .rag_cache + .load_with(key, || async move { + Rag::init( + &app_clone, + "rag", + &rag_path_clone, + &document_paths, + abort_signal, + ) + .await + }) + .await?; + Some(rag) } else { None }