defs.rs: async conversion, remove block_in_place
Convert resolve(), resolve_placeholders(), run_agent() to async. Use memory_render/memory_query directly with .await instead of block_in_place wrappers. Propagate async to callers: - config.rs: resolve(), load_session(), reload_for_model() - identity.rs: load_memory_files(), assemble_context_message() - oneshot.rs: run_one_agent() - prompts.rs: agent_prompt() Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
9bb07bc26a
commit
359955f838
10 changed files with 44 additions and 64 deletions
|
|
@ -7,6 +7,7 @@
|
|||
use anyhow::Result;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::agent::tools::memory::memory_render;
|
||||
use crate::config::{ContextGroup, ContextSource};
|
||||
|
||||
/// Read a file if it exists and is non-empty.
|
||||
|
|
@ -71,7 +72,7 @@ fn find_context_files(cwd: &Path, prompt_file: &str) -> Vec<PathBuf> {
|
|||
/// 2. Project dir (if set)
|
||||
/// 3. Global (~/.consciousness/)
|
||||
/// For journal source, loads recent journal entries.
|
||||
fn load_memory_files(memory_project: Option<&Path>, context_groups: &[ContextGroup]) -> Vec<(String, String)> {
|
||||
async fn load_memory_files(memory_project: Option<&Path>, context_groups: &[ContextGroup]) -> Vec<(String, String)> {
|
||||
let home = match dirs::home_dir() {
|
||||
Some(h) => h,
|
||||
None => return Vec::new(),
|
||||
|
|
@ -94,12 +95,7 @@ fn load_memory_files(memory_project: Option<&Path>, context_groups: &[ContextGro
|
|||
ContextSource::Store => {
|
||||
// Load from the memory graph store via typed API
|
||||
for key in &group.keys {
|
||||
let content = tokio::task::block_in_place(|| {
|
||||
tokio::runtime::Handle::current().block_on(
|
||||
crate::agent::tools::memory::memory_render(None, key, Some(true))
|
||||
)
|
||||
});
|
||||
if let Ok(c) = content {
|
||||
if let Ok(c) = memory_render(None, key, Some(true)).await {
|
||||
if !c.trim().is_empty() {
|
||||
memories.push((key.clone(), c));
|
||||
}
|
||||
|
|
@ -141,7 +137,7 @@ fn load_memory_files(memory_project: Option<&Path>, context_groups: &[ContextGro
|
|||
}
|
||||
|
||||
/// Context message: instruction files + memory files + manifest.
|
||||
pub fn assemble_context_message(cwd: &Path, prompt_file: &str, memory_project: Option<&Path>, context_groups: &[ContextGroup]) -> Result<(Vec<(String, String)>, usize, usize)> {
|
||||
pub async fn assemble_context_message(cwd: &Path, prompt_file: &str, memory_project: Option<&Path>, context_groups: &[ContextGroup]) -> Result<(Vec<(String, String)>, usize, usize)> {
|
||||
let mut parts: Vec<(String, String)> = vec![
|
||||
("Preamble".to_string(),
|
||||
"Everything below is already loaded — your identity, instructions, \
|
||||
|
|
@ -162,7 +158,7 @@ pub fn assemble_context_message(cwd: &Path, prompt_file: &str, memory_project: O
|
|||
}
|
||||
}
|
||||
|
||||
let memories = load_memory_files(memory_project, context_groups);
|
||||
let memories = load_memory_files(memory_project, context_groups).await;
|
||||
let memory_count = memories.len();
|
||||
for (name, content) in memories {
|
||||
parts.push((name, content));
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ pub async fn prepare_spawn(name: &str, mut auto: AutoAgent) -> Result<SpawnResul
|
|||
let exclude: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
let batch = match defs::run_agent(
|
||||
&store, &def, def.count.unwrap_or(5), &exclude,
|
||||
) {
|
||||
).await {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
dbglog!("[unconscious] {} query failed: {}", name, e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue