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:
ProofOfConcept 2026-04-11 19:28:03 -04:00
parent c300013ce5
commit 28e564aeb2
2 changed files with 6 additions and 9 deletions

View file

@ -764,7 +764,7 @@ impl ContextState {
pub fn conversation(&self) -> &[AstNode] { &self.conversation } pub fn conversation(&self) -> &[AstNode] { &self.conversation }
pub fn conversation_mut(&mut self) -> &mut Vec<AstNode> { &mut 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] [&self.system, &self.identity, &self.journal, &self.conversation]
} }
} }

View file

@ -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() { if std::fs::create_dir_all(&dir).is_ok() {
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 sections = serde_json::json!({ let mut context: Vec<&crate::agent::context::AstNode> = Vec::new();
"system": ctx.system(), for section in ctx.sections() {
"identity": ctx.identity(), context.extend(section);
"journal": ctx.journal(), }
"conversation": ctx.conversation(), if let Ok(json) = serde_json::to_string_pretty(&context) {
"stats": stats,
});
if let Ok(json) = serde_json::to_string_pretty(&sections) {
let _ = std::fs::write(&path, json); let _ = std::fs::write(&path, json);
} }
} }