Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent): place changing guidance after accepted history

thinhlpg4c1d33da32b0
diff --git a/docs/src/pages/docs/agent/context.mdx b/docs/src/pages/docs/agent/context.mdx
index aa226337c..f400ddedf 100644
--- a/docs/src/pages/docs/agent/context.mdx
+++ b/docs/src/pages/docs/agent/context.mdx
@@ -126,12 +126,13 @@ sit at the front of every request.
- The stable part of the system prompt (identity, guidelines, working directory, skills, memory
catalog) is written once at the head of the conversation and never rewritten.
-- Per-turn context (today's date, memory recall, plan and todo state) lives in its own slot behind
- it, and is rewritten only when its content changes.
-- A system prompt that changes mid-session - an edited `agent.toml`, a skill installed while the
- session is open, a mode switch - is appended as a new system message instead of overwriting the
- head. The provider keeps the cached prefix, and the model still reads the update last, so the
- change is honored without re-sending the whole conversation as new bytes.
+- Per-turn context (today's date, memory recall, plan and todo state) is appended after the
+ conversation as marked guidance. Previously sent messages stay untouched, and provider
+ adapters do not lift the changing guidance into the system prompt.
+- A stable prompt that changes mid-session - an edited `agent.toml`, a skill installed while
+ the session is open, a mode switch - is retained as a new system message. Providers combine
+ system messages into one instruction field, so a change to these prefix contributors still
+ invalidates the cached conversation. Use tail placement for changing context.
- The advertised tool array is ordered deterministically, so a restart that advertises the same
tools advertises them as the same bytes.
diff --git a/docs/src/pages/docs/agent/project-config.mdx b/docs/src/pages/docs/agent/project-config.mdx
index 1f7ff1fd0..0eae29256 100644
--- a/docs/src/pages/docs/agent/project-config.mdx
+++ b/docs/src/pages/docs/agent/project-config.mdx
@@ -148,6 +148,10 @@ turn belongs below the conversation, not in front of it. Placement is deny-wins,
nothing reaches the prefix without being allowed there, and the safe answer for a contributor no
policy mentions is the tail.
+Tail blocks are sent as `<SYSTEM>`-marked guidance after the conversation, including when the
+allowlist leaves no stable prompt. They are not system-role messages: provider adapters would
+move those ahead of history and defeat the placement policy.
+
```toml
[prompt]
# Only these may sit above the cache line. Unset keeps each contributor's own
diff --git a/src-tauri/src/core/agent/genai_bridge.rs b/src-tauri/src/core/agent/genai_bridge.rs
index 5a6d0e1d2..34425c5a2 100644
--- a/src-tauri/src/core/agent/genai_bridge.rs
+++ b/src-tauri/src/core/agent/genai_bridge.rs
@@ -950,6 +950,36 @@ mod tests {
assert_eq!(req.messages.len(), 3, "only the conversation remains");
}
+ #[test]
+ fn prompt_tail_stays_after_history_in_the_provider_request() {
+ let mut messages = vec![
+ json!({"role": "system", "content": "Stable instructions."}),
+ json!({"role": "user", "content": "first question"}),
+ json!({"role": "assistant", "content": "first answer"}),
+ json!({"role": "user", "content": "second question"}),
+ ];
+ crate::core::agent::upstream::append_prompt_tail(
+ &mut messages,
+ "Today's date is 2026-09-21.",
+ );
+ let (_, request) = chat_request_from_body(&json!({
+ "model": "m",
+ "messages": messages,
+ }))
+ .unwrap();
+
+ assert_eq!(request.system.as_deref(), Some("Stable instructions."));
+ assert_eq!(request.messages[0].role, ChatRole::User);
+ assert_eq!(request.messages[1].role, ChatRole::Assistant);
+ assert_eq!(request.messages[2].role, ChatRole::User);
+ let tail = request.messages.last().unwrap();
+ assert_eq!(tail.role, ChatRole::User);
+ assert_eq!(
+ tail.content.first_text(),
+ Some("<SYSTEM>\nToday's date is 2026-09-21.\n</SYSTEM>")
+ );
+ }
+
#[test]
fn assistant_reasoning_and_tool_calls_survive_the_round_trip() {
let body = json!({
diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rs
index 06166d6f1..7e1b4c5e9 100644
--- a/src-tauri/src/core/agent/loop.rs
+++ b/src-tauri/src/core/agent/loop.rs
@@ -20,10 +20,10 @@ use crate::core::agent::events::{StreamEvent, Usage};
use crate::core::agent::prompt::{Composer, Placement, PromptPolicy};
use crate::core::agent::session::SessionBudget;
use crate::core::agent::upstream::{
- arguments_are_executable, collect_mcp_openai_tools, copy_optional_chat_params,
- drop_malformed_tool_calls, execute_mcp_tool_calls, extract_choice_message, extract_tool_calls,
- load_assistant_config, parse_openai_messages, repair_dangling_tool_calls,
- insert_volatile_system, resolve_api_type_for_model, resolve_upstream_for_model,
+ append_prompt_tail, arguments_are_executable, collect_mcp_openai_tools,
+ copy_optional_chat_params, drop_malformed_tool_calls, execute_mcp_tool_calls,
+ extract_choice_message, extract_tool_calls, load_assistant_config, parse_openai_messages,
+ repair_dangling_tool_calls, resolve_api_type_for_model, resolve_upstream_for_model,
set_system_prompt, stream_openai_chat_completions,
};
use crate::core::server::converters::{converter_for, UpstreamConverter};
@@ -2044,7 +2044,12 @@ fn latest_user_text(messages: &[serde_json::Value]) -> Option<String> {
let content = messages
.iter()
.rev()
- .find(|m| m.get("role").and_then(|r| r.as_str()) == Some("user"))?
+ .find(|m| {
+ m.get("role").and_then(|v| v.as_str()) == Some("user")
+ && !crate::core::agent::reminder::is_reminder_only(
+ m.get("content").unwrap_or(&serde_json::Value::Null),
+ )
+ })?
.get("content")?;
match content {
serde_json::Value::String(s) => Some(s.clone()),
@@ -2347,12 +2352,12 @@ async fn orchestrate_inner(
.map(|root| resolve_run_settings(root, *sandbox));
// The stable system prompt: identity, guidelines, environment, skills and
- // the memory catalog. Byte-identical across the turns of a session (within a
- // day), so it is kept as system message 0 and never mixed with per-turn
- // content -- that is what lets a provider cache this long prefix. Volatile
- // per-turn context (date, git state, query memory recall, plan/todo state)
- // is collected separately below and emitted as a second system message so it
- // cannot invalidate the cached prefix above.
+ // the memory catalog. Byte-identical across the turns of a session, so it
+ // is kept as system message 0 and never mixed with per-turn content.
+ // Changing context (date, git state, query memory recall, plan/todo state)
+ // is collected separately and appended as marked guidance after history.
+ // A second system message would be hoisted ahead of history by the provider
+ // bridge, invalidating the cached conversation on every change.
//
// Which blocks land in which half is `[prompt]`'s decision, resolved here:
// the composition returns them split rather than joined, and a composer the
@@ -2448,18 +2453,14 @@ async fn orchestrate_inner(
.collect::<Vec<_>>()
.join("\n\n");
- match &stable_system {
- // An allowlist can move every block below the cache line, which leaves
- // no stable prompt at all: the volatile block then stands in as
- // message 0 rather than an empty system node preceding it.
- Some(composed) if !composed.prefix.is_empty() => {
+ if let Some(composed) = &stable_system {
+ if !composed.prefix.is_empty() {
set_system_prompt(&mut conversation_messages, &composed.prefix);
- insert_volatile_system(&mut conversation_messages, &volatile_block);
}
- // No stable prompt (an isolated child run with no override): the
- // volatile block is all there is, so it stands in as message 0.
- _ => set_system_prompt(&mut conversation_messages, &volatile_block),
}
+ // Even without a stable prefix, tail policy must survive the provider
+ // bridge: system-role guidance would be lifted ahead of all history.
+ append_prompt_tail(&mut conversation_messages, &volatile_block);
// Paired with the addendum above: force the model's very first tool call
// to actually be `todo` rather than leaving compliance up to a prompt it
// could silently ignore.
@@ -3684,9 +3685,8 @@ mod tests {
/// The cache-prefix contract from #340: across turns the system prompt at
/// message 0 and the tool schema must be byte-identical, so a provider can
- /// cache them; only the volatile message 1 (date, memory recall, plan state)
- /// changes. A regression here silently defeats prompt caching, which no
- /// functional test would catch.
+ /// cache them; changing guidance is appended after the conversation.
+ /// A regression here silently defeats prompt caching.
#[test]
fn system_prefix_and_tools_are_byte_identical_across_turns() {
let tools = vec![json!({
@@ -3701,7 +3701,7 @@ mod tests {
let mut turn1 = vec![json!({"role": "user", "content": "first"})];
set_system_prompt(&mut turn1, "STABLE PREFIX");
- insert_volatile_system(&mut turn1, "Today's date is 2026-09-16.");
+ append_prompt_tail(&mut turn1, "Today's date is 2026-09-16.");
let req1 = build_completion_request("m", &turn1, &tools, &body, None);
// A later turn: the conversation has grown and the volatile block differs.
@@ -3711,7 +3711,7 @@ mod tests {
json!({"role": "user", "content": "second"}),
];
set_system_prompt(&mut turn2, "STABLE PREFIX");
- insert_volatile_system(
+ append_prompt_tail(
&mut turn2,
"Today's date is 2026-09-17.\n\n# Recalled memory\n- a note",
);
@@ -3722,11 +3722,22 @@ mod tests {
assert_eq!(node0(&req1), node0(&req2), "node 0 must be byte-stable");
assert_eq!(tools_of(&req1), tools_of(&req2), "tools must be byte-stable");
assert_ne!(
- req1["messages"][1], req2["messages"][1],
+ req1["messages"].as_array().unwrap().last(),
+ req2["messages"].as_array().unwrap().last(),
"the volatile block is expected to differ"
);
}
+ #[test]
+ fn prompt_tail_does_not_replace_the_user_query() {
+ let mut messages = vec![json!({"role": "user", "content": "find the configuration"})];
+ append_prompt_tail(&mut messages, "Today's date is 2026-09-21.");
+ assert_eq!(
+ latest_user_text(&messages).as_deref(),
+ Some("find the configuration")
+ );
+ }
+
struct MockModel {
responses: StdMutex<VecDeque<serde_json::Value>>,
// Every request this mock was invoked with, in order -- lets a test
diff --git a/src-tauri/src/core/agent/prefix_stability.rs b/src-tauri/src/core/agent/prefix_stability.rs
index 523b7b279..2f1b25348 100644
--- a/src-tauri/src/core/agent/prefix_stability.rs
+++ b/src-tauri/src/core/agent/prefix_stability.rs
@@ -19,7 +19,7 @@
//!
//! What they drive is the real production code for each contributor to the
//! prefix - `compose_system_prompt` and the placement policy, the two helpers
-//! that place the stable and volatile system messages, `build_completion_request`,
+//! that place the stable prompt and marked tail guidance, `build_completion_request`,
//! and the tool-array assembly and reuse. The one thing not driven here is the
//! *order* in which `orchestrate_inner` calls those pieces, which is inline in
//! that function and only reachable with a live upstream. When that assembly is
@@ -35,7 +35,7 @@ use super::events::StreamEvent;
use super::prompt::{Composer, Placement, PromptPolicy};
use super::r#loop::{build_completion_request, ModelInvoker};
use super::upstream::{
- assemble_tool_array, insert_volatile_system, reuse_last_good_listings, set_system_prompt,
+ append_prompt_tail, assemble_tool_array, reuse_last_good_listings, set_system_prompt,
RenderedTool,
};
use async_trait::async_trait;
@@ -232,13 +232,13 @@ fn advertised(names: &[&str]) -> Vec<Value> {
}
/// One turn's request, assembled the way `orchestrate_inner` assembles one: the
-/// composed prompt at the front, the policy's tail blocks plus the per-turn
-/// blocks merged in registry order behind it, then the conversation.
+/// composed prompt at the front, then accepted history, then the policy's tail
+/// blocks plus the per-turn blocks merged in registry order.
///
/// The per-turn blocks are the date and a fixed git line - the two the loop
/// always has - rather than the memory/plan/todo blocks, which depend on
/// session state this suite does not drive. What the assertions here need is
-/// the *shape*: one volatile system message directly behind the stable prompt.
+/// the *shape*: one marked guidance message after the conversation.
fn turn(project: &Path, history: &[Value], date: &str, tools: &[Value]) -> Request {
let composed =
compose_system_prompt(None, project, None, false, &PromptPolicy::default()).unwrap();
@@ -257,7 +257,7 @@ fn turn(project: &Path, history: &[Value], date: &str, tools: &[Value]) -> Reque
let mut messages = history.to_vec();
set_system_prompt(&mut messages, &composed.prefix);
- insert_volatile_system(&mut messages, &volatile);
+ append_prompt_tail(&mut messages, &volatile);
let body = serde_json::to_string(&build_completion_request(
"test-model",
@@ -344,16 +344,10 @@ fn consecutive_turns_extend_the_previous_request() {
let tools = advertised(&["read_file"]);
let first = turn(project.root(), &[user("first question")], DAY, &tools);
- let second = turn(
- project.root(),
- &[
- user("first question"),
- assistant("first answer"),
- user("second question"),
- ],
- DAY,
- &tools,
- );
+ let mut history = first.messages.clone();
+ history.push(assistant("first answer"));
+ history.push(user("second question"));
+ let second = turn(project.root(), &history, DAY, &tools);
first.assert_extended_by("an unchanged project on the next turn", &second);
}
@@ -456,6 +450,24 @@ fn a_midnight_crossing_diverges_inside_the_volatile_block() {
);
}
+#[test]
+fn a_changing_tail_preserves_all_accepted_history() {
+ let project = Project::new("tail-history");
+ let tools = advertised(&["read_file"]);
+ let first = turn(
+ project.root(),
+ &[user("first question")],
+ "2026-09-20",
+ &tools,
+ );
+ let mut history = first.messages.clone();
+ history.push(assistant("first answer"));
+ history.push(user("second question"));
+
+ let second = turn(project.root(), &history, "2026-09-21", &tools);
+ first.assert_extended_by("changed context belongs after accepted history", &second);
+}
+
/// #8959: the tool array sits at the front of the request, so it has to be a
/// function of configuration alone. Moving a project changes the prompt - the
/// working directory names it - but must not move the tools in front of it.
@@ -573,6 +585,7 @@ async fn compaction_breaks_the_prefix_exactly_once() {
breaks += 1;
}
}
+ history = request.messages.clone();
previous = Some(request);
history.push(assistant(&format!("answer {index}")));
if index == 2 {
diff --git a/src-tauri/src/core/agent/upstream.rs b/src-tauri/src/core/agent/upstream.rs
index 307054728..c6a088a4b 100644
--- a/src-tauri/src/core/agent/upstream.rs
+++ b/src-tauri/src/core/agent/upstream.rs
@@ -321,38 +321,11 @@ fn system_text(message: &serde_json::Value) -> Option<&str> {
message.get("content").and_then(|c| c.as_str())
}
-/// A node this module wrote to carry per-turn context rather than history: a
-/// `system` message that is not a compaction summary.
-fn is_volatile_node(message: &serde_json::Value) -> bool {
- is_system_node(message) && !crate::core::agent::compaction::is_compaction_summary(message)
-}
-
-/// Where the per-turn volatile block belongs: index 1 once a stable prompt
-/// holds index 0, else index 0. One slot, because the stable prompt is only
-/// ever placed at index 0 or appended behind it - so this is the single
-/// position a per-turn block can be rewritten in without disturbing the bytes
-/// an earlier request already sent as its head.
-fn volatile_slot(messages: &[serde_json::Value]) -> usize {
- usize::from(messages.first().is_some_and(is_system_node))
-}
-
-/// Index of the stable prompt node the next request would extend: the last
-/// `system` node this module owns, i.e. neither the volatile slot nor a
-/// compaction summary (condensed history that happens to carry the same role).
-///
-/// The layout is `[stable, volatile, ..history..]`, so before any update this
-/// resolves to index 0; after one it resolves to the node appended at the tail.
-/// That is what makes a repeated turn a no-op instead of a second append, and
-/// what keeps an update from being mistaken for the volatile block and vice
-/// versa.
+/// The most recent stable prompt, excluding condensed conversation history.
fn live_stable_index(messages: &[serde_json::Value]) -> Option<usize> {
- let slot = volatile_slot(messages);
- messages
- .iter()
- .enumerate()
- .rev()
- .find(|(index, message)| is_volatile_node(message) && *index != slot)
- .map(|(index, _)| index)
+ messages.iter().rposition(|message| {
+ is_system_node(message) && !crate::core::agent::compaction::is_compaction_summary(message)
+ })
}
/// Apply the session's stable system prompt, append-only.
@@ -412,28 +385,17 @@ pub(crate) fn replace_system_prompt(messages: &mut Vec<serde_json::Value>, syste
messages.insert(0, system_node(system_prompt));
}
-/// Place the per-turn context block (today's date, query-specific memory
-/// recall, plan/todo state) in the conversation's volatile slot, leaving the
-/// stable prompt ahead of it untouched.
-///
-/// The block is the same on every turn between its own changes, so the slot is
-/// rewritten only when the content differs. That matters for the same reason
-/// the stable prompt is append-only: rewriting it ends the reusable prefix
-/// there, so a turn that changed nothing but the conversation's tail must not
-/// rewrite it either.
-///
-/// Assumes `set_system_prompt` has already placed the stable prompt.
-pub(crate) fn insert_volatile_system(messages: &mut Vec<serde_json::Value>, content: &str) {
- let slot = volatile_slot(messages);
- match messages.get(slot) {
- // This turn's block is already in place: leave every byte alone.
- Some(existing) if is_volatile_node(existing) && system_text(existing) == Some(content) => {}
- // A block from an earlier turn (or a caller's own second system
- // message) holds the slot. It is per-turn content, so it is replaced
- // rather than accumulated; a summary that landed here is not, which is
- // why the guard above asks for a volatile node.
- Some(existing) if is_volatile_node(existing) => messages[slot] = system_node(content),
- _ => messages.insert(slot, system_node(content)),
+/// Append changing guidance after accepted history, using the same trusted
+/// marker as turn reminders. A system-role message would be hoisted into the
+/// provider's system field and invalidate the conversation's cached prefix.
+/// Keep a separate message even after a user turn: that turn may already have
+/// been sent, and its bytes must not be rewritten.
+pub(crate) fn append_prompt_tail(messages: &mut Vec<serde_json::Value>, content: &str) {
+ if !content.is_empty() {
+ messages.push(serde_json::json!({
+ "role": "user",
+ "content": crate::core::agent::reminder::wrap(content),
+ }));
}
}
@@ -1765,71 +1727,35 @@ mod tests {
use super::*;
use serde_json::json;
- #[test]
- fn volatile_system_follows_the_stable_prompt_and_leaves_it_byte_stable() {
- let mut msgs = vec![json!({ "role": "user", "content": "hi" })];
- set_system_prompt(&mut msgs, "STABLE");
- insert_volatile_system(&mut msgs, "date + memory");
- assert_eq!(msgs[0]["role"], "system");
- assert_eq!(msgs[0]["content"], "STABLE");
- assert_eq!(msgs[1]["role"], "system");
- assert_eq!(msgs[1]["content"], "date + memory");
- assert_eq!(msgs[2]["role"], "user");
-
- // A second turn with different volatile content must not disturb node 0.
- let mut next = vec![
- json!({ "role": "user", "content": "hi" }),
- json!({ "role": "assistant", "content": "yo" }),
- json!({ "role": "user", "content": "again" }),
- ];
- set_system_prompt(&mut next, "STABLE");
- insert_volatile_system(&mut next, "different date");
- assert_eq!(next[0], msgs[0]);
- }
-
#[test]
fn compaction_summary_survives_a_system_prompt_update() {
let marker = crate::core::agent::compaction::SUMMARY_MARKER;
// The history a turn inherits after a mid-run compaction: previous
- // rebuilt system prompt, its volatile message, the summary, kept tail.
+ // rebuilt system prompt, its marked guidance, the summary, kept tail.
let mut history = vec![
json!({ "role": "system", "content": "OLD STABLE" }),
- json!({ "role": "system", "content": "old date" }),
+ json!({ "role": "user", "content": crate::core::agent::reminder::wrap("old date") }),
json!({ "role": "system", "content": format!("{marker}\n\ncondensed") }),
json!({ "role": "assistant", "content": "kept" }),
json!({ "role": "user", "content": "new question" }),
];
- let before = serde_json::to_string(&history[2]).unwrap();
+ let before = history.clone();
set_system_prompt(&mut history, "NEW STABLE");
- insert_volatile_system(&mut history, "new date");
+ append_prompt_tail(&mut history, "new date");
// The head keeps the bytes the previous request already sent: that is
// the whole point of appending the update instead of rewriting node 0.
assert_eq!(history[0]["content"], "OLD STABLE");
- assert_eq!(history[1]["content"], "new date");
- assert_eq!(
- serde_json::to_string(&history[2]).unwrap(),
- before,
- "nothing deletes by role, so the summary is untouched"
- );
+ assert_eq!(&history[..before.len()], before.as_slice());
assert_eq!(history[3]["content"], "kept");
assert_eq!(history[4]["content"], "new question");
// The update is the newest system node, so it is the one the model
// reads last rather than a duplicate of the head.
- let newest = history.last().unwrap();
+ let newest = history.iter().rev().find(|m| is_system_node(m)).unwrap();
assert_eq!(newest["role"], "system");
assert_eq!(newest["content"], "NEW STABLE");
}
- #[test]
- fn volatile_system_stands_in_as_node_zero_when_no_stable_prompt() {
- let mut msgs = vec![json!({ "role": "user", "content": "hi" })];
- insert_volatile_system(&mut msgs, "date only");
- assert_eq!(msgs[0]["role"], "system");
- assert_eq!(msgs[0]["content"], "date only");
- assert_eq!(msgs[1]["role"], "user");
- }
-
/// The system nodes a request carries, in the order the provider
/// concatenates them.
fn system_contents(messages: &[serde_json::Value]) -> Vec<String> {
@@ -1854,7 +1780,7 @@ mod tests {
fn a_repeated_turn_mutates_nothing() {
let mut conversation = vec![
json!({ "role": "system", "content": "STABLE" }),
- json!({ "role": "system", "content": "date" }),
+ json!({ "role": "user", "content": crate::core::agent::reminder::wrap("date") }),
json!({ "role": "user", "content": "hi" }),
json!({ "role": "assistant", "content": "yo" }),
json!({ "role": "user", "content": "again" }),
@@ -1862,7 +1788,6 @@ mod tests {
let before = serde_json::to_string(&conversation).unwrap();
set_system_prompt(&mut conversation, "STABLE");
- insert_volatile_system(&mut conversation, "date");
assert_eq!(serde_json::to_string(&conversation).unwrap(), before);
}
@@ -1874,7 +1799,7 @@ mod tests {
fn a_changed_system_prompt_appends_behind_bytes_already_sent() {
let mut conversation = vec![
json!({ "role": "system", "content": "STABLE v1" }),
- json!({ "role": "system", "content": "date" }),
+ json!({ "role": "user", "content": crate::core::agent::reminder::wrap("date") }),
json!({ "role": "user", "content": "hi" }),
json!({ "role": "assistant", "content": "yo" }),
json!({ "role": "user", "content": "go on" }),
@@ -1882,7 +1807,6 @@ mod tests {
let sent = serialized(&conversation);
set_system_prompt(&mut conversation, "STABLE v2");
- insert_volatile_system(&mut conversation, "date");
assert_eq!(conversation.len(), sent.len() + 1, "one appended update");
assert_eq!(
@@ -1894,7 +1818,6 @@ mod tests {
// The next turn applies the same prompt again: no second copy of it.
set_system_prompt(&mut conversation, "STABLE v2");
- insert_volatile_system(&mut conversation, "date");
assert_eq!(conversation.len(), sent.len() + 1);
assert_eq!(conversation.last().unwrap()["content"], "STABLE v2");
}
@@ -1907,15 +1830,15 @@ mod tests {
fn an_appended_update_is_the_last_system_node() {
let mut conversation = vec![json!({ "role": "user", "content": "hi" })];
set_system_prompt(&mut conversation, "STABLE v1");
- insert_volatile_system(&mut conversation, "date");
+ append_prompt_tail(&mut conversation, "date");
set_system_prompt(&mut conversation, "STABLE v2");
assert_eq!(
system_contents(&conversation),
- vec!["STABLE v1", "date", "STABLE v2"]
+ vec!["STABLE v1", "STABLE v2"]
);
// ...and the history it was appended behind is still there.
- assert_eq!(conversation[2]["content"], "hi");
+ assert_eq!(conversation[1]["content"], "hi");
}
/// Nothing is deleted by role: history another producer stored under
@@ -1945,24 +1868,11 @@ mod tests {
assert_eq!(messages[0]["role"], "system");
assert_eq!(messages[0]["content"], "STABLE");
- insert_volatile_system(&mut messages, "date");
+ append_prompt_tail(&mut messages, "date");
assert_eq!(messages[0]["content"], "STABLE");
- assert_eq!(messages[1]["content"], "date");
- }
-
- /// The layout both writers depend on: the stable prompt owns index 0, the
- /// per-turn block owns the slot behind it, and a new day rewrites only
- /// that slot.
- #[test]
- fn the_per_turn_block_never_displaces_the_stable_prompt() {
- let mut messages = vec![json!({ "role": "user", "content": "hi" })];
- set_system_prompt(&mut messages, "STABLE");
- for day in ["day 1", "day 2", "day 3"] {
- insert_volatile_system(&mut messages, day);
- assert_eq!(messages[0]["content"], "STABLE");
- assert_eq!(messages[1]["content"], day);
- assert_eq!(messages.len(), 3, "the block is replaced, not stacked");
- }
+ assert!(crate::core::agent::reminder::is_reminder_only(
+ &messages[1]["content"]
+ ));
}
fn rendered(tool_name: &str) -> RenderedTool {