delete dead flat-file journal tool and ephemeral stripping
Journal entries are written to the memory graph via journal_new/ journal_update, not appended to a flat file. Remove thought/journal.rs (67 lines), strip_ephemeral_tool_calls (55 lines), default_journal_path, and all wiring. -141 lines. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
aceaf0410e
commit
809679b6ce
5 changed files with 1 additions and 142 deletions
|
|
@ -362,10 +362,7 @@ impl Agent {
|
|||
|
||||
let msg = crate::agent::api::build_response_message(content, tool_calls);
|
||||
|
||||
// Strip ephemeral tool calls (journal) that the API has
|
||||
// now processed. They're persisted to disk; no need to keep
|
||||
// them in the conversation history burning tokens.
|
||||
self.strip_ephemeral_tool_calls();
|
||||
|
||||
|
||||
if let Some(usage) = &usage {
|
||||
self.last_prompt_tokens = usage.prompt_tokens;
|
||||
|
|
@ -897,66 +894,6 @@ impl Agent {
|
|||
|
||||
/// Strip ephemeral tool calls from the conversation history.
|
||||
///
|
||||
/// Ephemeral tools (like journal) persist their output to disk,
|
||||
/// so the tool call + result don't need to stay in the context
|
||||
/// window. We keep them for exactly one API round-trip (the model
|
||||
/// needs to see the result was acknowledged), then strip them.
|
||||
///
|
||||
/// If an assistant message contains ONLY ephemeral tool calls,
|
||||
/// the entire message and its tool results are removed. If mixed
|
||||
/// with non-ephemeral calls, we leave it (rare case, small cost).
|
||||
fn strip_ephemeral_tool_calls(&mut self) {
|
||||
// Collect IDs of tool calls to strip
|
||||
let mut strip_ids: Vec<String> = Vec::new();
|
||||
let mut strip_msg_indices: Vec<usize> = Vec::new();
|
||||
|
||||
for (i, entry) in self.context.entries.iter().enumerate() {
|
||||
let msg = entry.message();
|
||||
if msg.role != Role::Assistant {
|
||||
continue;
|
||||
}
|
||||
let calls = match &msg.tool_calls {
|
||||
Some(c) if !c.is_empty() => c,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let all_ephemeral = calls.iter().all(|c| {
|
||||
c.function.name == tools::journal::TOOL_NAME
|
||||
});
|
||||
|
||||
if all_ephemeral {
|
||||
strip_msg_indices.push(i);
|
||||
for call in calls {
|
||||
strip_ids.push(call.id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if strip_ids.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove in reverse order to preserve indices
|
||||
self.context.entries.retain(|entry| {
|
||||
let msg = entry.message();
|
||||
if msg.role == Role::Assistant {
|
||||
if let Some(calls) = &msg.tool_calls {
|
||||
if calls.iter().all(|c| strip_ids.contains(&c.id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if msg.role == Role::Tool {
|
||||
if let Some(ref id) = msg.tool_call_id {
|
||||
if strip_ids.contains(id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
/// Last prompt token count reported by the API.
|
||||
pub fn last_prompt_tokens(&self) -> u32 {
|
||||
self.last_prompt_tokens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue