Preserve bounded agent cache prefixes

This commit is contained in:
Meta Vens 2026-08-30 08:12:18 +02:00
commit 8f3c33b2d1
7 changed files with 96 additions and 51 deletions

View file

@ -156,20 +156,10 @@ pub async fn run_model_agent_progress<Tool: ModelAgentTool>(
}
let mut receipts = Vec::new();
let mut input = if tool.context_snapshot().is_some() {
vec![
ModelInputItem::user(spec.instructions.clone()),
ModelInputItem::user(format!(
"AGENT STEP: 1 of {}. Choose one typed tool action admitted by the current output schema. The harness will execute it against the frozen state and return the real tool observation. Do not claim success yourself; only an accepted tool result can end the task.",
spec.max_steps
)),
]
} else {
vec![ModelInputItem::user(format!(
"{}\n\nAGENT STEP: 1 of {}. Choose one typed tool action admitted by the current output schema. The harness will execute it against the frozen state and return the real tool observation. Do not claim success yourself; only an accepted tool result can end the task.",
spec.instructions, spec.max_steps
))]
};
let mut input = vec![ModelInputItem::user(format!(
"{}\n\nAGENT STEP: 1 of {}. Choose one typed tool action admitted by the current output schema. The harness will execute it against the frozen state and return the real tool observation. Do not claim success yourself; only an accepted tool result can end the task.",
spec.instructions, spec.max_steps
))];
let mut last_observation = None;
for step in 0..spec.max_steps {
let action_schema = match tool.action_schema() {

View file

@ -4516,17 +4516,14 @@ mod tests {
let requests = model.requests();
assert_eq!(requests.len(), 3);
let stable_prefix = requests[0]
.lived_stream
.split("\n\nUSER:\nAGENT STEP")
.next()
.unwrap();
let stable_prefix = &requests[0].lived_stream;
assert!(stable_prefix.contains("STAFF BOOK"));
assert!(
requests[1..]
.iter()
.all(|request| request.lived_stream.starts_with(stable_prefix))
);
assert!(stable_prefix.contains("AGENT STEP: 1"));
assert!(requests[1..].iter().all(|request| {
request
.lived_stream
.starts_with(&format!("{stable_prefix}\n\nUSER:\n"))
}));
assert!(requests[1].lived_stream.contains("cracked hinge"));
assert!(requests[2].lived_stream.contains("news:west-gate"));
assert!(!requests[2].lived_stream.contains("cracked hinge"));