forked from kent/consciousness
save_agent_log: write flat context array matching AST order
The old code wrote a JSON object with named section keys, which serde_json serialized in alphabetical order — putting conversation before system, making logs misleading. Write a single flat array in section order instead, matching what the model actually sees. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
c300013ce5
commit
28e564aeb2
2 changed files with 6 additions and 9 deletions
|
|
@ -764,7 +764,7 @@ impl ContextState {
|
|||
pub fn conversation(&self) -> &[AstNode] { &self.conversation }
|
||||
pub fn conversation_mut(&mut self) -> &mut Vec<AstNode> { &mut self.conversation }
|
||||
|
||||
fn sections(&self) -> [&Vec<AstNode>; 4] {
|
||||
pub fn sections(&self) -> [&Vec<AstNode>; 4] {
|
||||
[&self.system, &self.identity, &self.journal, &self.conversation]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,14 +309,11 @@ pub async fn save_agent_log(name: &str, agent: &std::sync::Arc<crate::agent::Age
|
|||
if std::fs::create_dir_all(&dir).is_ok() {
|
||||
let ts = chrono::Utc::now().format("%Y%m%d-%H%M%S");
|
||||
let path = dir.join(format!("{}.json", ts));
|
||||
let sections = serde_json::json!({
|
||||
"system": ctx.system(),
|
||||
"identity": ctx.identity(),
|
||||
"journal": ctx.journal(),
|
||||
"conversation": ctx.conversation(),
|
||||
"stats": stats,
|
||||
});
|
||||
if let Ok(json) = serde_json::to_string_pretty(§ions) {
|
||||
let mut context: Vec<&crate::agent::context::AstNode> = Vec::new();
|
||||
for section in ctx.sections() {
|
||||
context.extend(section);
|
||||
}
|
||||
if let Ok(json) = serde_json::to_string_pretty(&context) {
|
||||
let _ = std::fs::write(&path, json);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue