Log full agent context window on completion
Save all context sections (system, identity, journal, conversation) to per-agent log files for both subconscious and unconscious agents. Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
parent
be44a3bb0d
commit
b356b94d0e
2 changed files with 10 additions and 4 deletions
|
|
@ -617,6 +617,7 @@ impl Subconscious {
|
||||||
|
|
||||||
self.agents[idx].handle = Some(tokio::spawn(async move {
|
self.agents[idx].handle = Some(tokio::spawn(async move {
|
||||||
let result = auto.run_forked_shared(&forked, &keys, &st, &recent).await;
|
let result = auto.run_forked_shared(&forked, &keys, &st, &recent).await;
|
||||||
|
super::unconscious::save_agent_log(&auto.name, &forked).await;
|
||||||
(auto, result)
|
(auto, result)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -296,17 +296,22 @@ impl Unconscious {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save_agent_log(name: &str, agent: &std::sync::Arc<crate::agent::Agent>) {
|
pub async fn save_agent_log(name: &str, agent: &std::sync::Arc<crate::agent::Agent>) {
|
||||||
let dir = dirs::home_dir().unwrap_or_default()
|
let dir = dirs::home_dir().unwrap_or_default()
|
||||||
.join(format!(".consciousness/logs/{}", name));
|
.join(format!(".consciousness/logs/{}", name));
|
||||||
if std::fs::create_dir_all(&dir).is_err() { return; }
|
if std::fs::create_dir_all(&dir).is_err() { return; }
|
||||||
let ts = chrono::Utc::now().format("%Y%m%d-%H%M%S");
|
let ts = chrono::Utc::now().format("%Y%m%d-%H%M%S");
|
||||||
let path = dir.join(format!("{}.json", ts));
|
let path = dir.join(format!("{}.json", ts));
|
||||||
let nodes: Vec<crate::agent::context::AstNode> = {
|
let sections: serde_json::Value = {
|
||||||
let ctx = agent.context.lock().await;
|
let ctx = agent.context.lock().await;
|
||||||
ctx.conversation().to_vec()
|
serde_json::json!({
|
||||||
|
"system": ctx.system(),
|
||||||
|
"identity": ctx.identity(),
|
||||||
|
"journal": ctx.journal(),
|
||||||
|
"conversation": ctx.conversation(),
|
||||||
|
})
|
||||||
};
|
};
|
||||||
if let Ok(json) = serde_json::to_string_pretty(&nodes) {
|
if let Ok(json) = serde_json::to_string_pretty(§ions) {
|
||||||
let _ = std::fs::write(&path, json);
|
let _ = std::fs::write(&path, json);
|
||||||
dbglog!("[unconscious] saved log to {}", path.display());
|
dbglog!("[unconscious] saved log to {}", path.display());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue