forked from kent/consciousness
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
b4dfd3c092
4 changed files with 55 additions and 15 deletions
|
|
@ -617,6 +617,7 @@ impl Subconscious {
|
|||
|
||||
self.agents[idx].handle = Some(tokio::spawn(async move {
|
||||
let result = auto.run_forked_shared(&forked, &keys, &st, &recent).await;
|
||||
super::unconscious::save_agent_log(&auto.name, &forked).await;
|
||||
(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()
|
||||
.join(format!(".consciousness/logs/{}", name));
|
||||
if std::fs::create_dir_all(&dir).is_err() { return; }
|
||||
let ts = chrono::Utc::now().format("%Y%m%d-%H%M%S");
|
||||
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;
|
||||
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);
|
||||
dbglog!("[unconscious] saved log to {}", path.display());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue