wire up /score command and debug screen for memory importance

/score snapshots the context and client, releases the agent lock,
runs scoring in background. Only one score task at a time
(scoring_in_flight flag). Results stored on Agent and shown on
the F10 context debug screen with importance scores per memory.

ApiClient derives Clone. ContextState derives Clone.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 22:18:50 -04:00
parent df9b610c7f
commit c01d4a5b08
7 changed files with 64 additions and 4 deletions

View file

@ -57,6 +57,7 @@ pub enum StreamEvent {
Error(String),
}
#[derive(Clone)]
pub struct ApiClient {
client: Client,
api_key: String,

View file

@ -76,6 +76,10 @@ pub struct Agent {
session_id: String,
/// Agent orchestration state (surface-observe, journal, reflect).
pub agent_cycles: crate::subconscious::subconscious::AgentCycleState,
/// Latest memory importance scores from training scorer.
pub memory_scores: Option<crate::thought::training::MemoryScore>,
/// Whether a /score task is currently running.
pub scoring_in_flight: bool,
}
fn render_journal(entries: &[journal::JournalEntry]) -> String {
@ -125,6 +129,8 @@ impl Agent {
prompt_file,
session_id,
agent_cycles,
memory_scores: None,
scoring_in_flight: false,
};
agent.load_startup_journal();
@ -670,8 +676,16 @@ impl Agent {
_ => unreachable!(),
};
let text = entry.message().content_text();
let score = self.memory_scores.as_ref()
.and_then(|s| s.memory_weights.iter()
.find(|(k, _)| k == key)
.map(|(_, v)| *v));
let label = match score {
Some(v) => format!("{} (importance: {:.1})", key, v),
None => key.to_string(),
};
ContextSection {
name: key.to_string(),
name: label,
tokens: count(text),
content: String::new(),
children: Vec::new(),
@ -970,6 +984,10 @@ impl Agent {
}
/// Mutable access to conversation entries (for /retry).
pub fn client_clone(&self) -> ApiClient {
self.client.clone()
}
pub fn entries_mut(&mut self) -> &mut Vec<ConversationEntry> {
&mut self.context.entries
}

View file

@ -397,6 +397,7 @@ impl ConversationEntry {
}
}
#[derive(Clone)]
pub struct ContextState {
pub system_prompt: String,
pub personality: Vec<(String, String)>,