Expand description
agent-message-window: sliding window of LLM conversation turns with paired tool_use / tool_result protection.
The Anthropic API rejects conversations that contain a tool_result
whose tool_use is no longer in the history. A naive “drop the oldest”
window silently corrupts the conversation. This crate’s eviction logic
never drops a tool_use message without also evicting all tool_result
messages that reference it.
use agent_message_window::MessageWindow;
use serde_json::json;
let mut win = MessageWindow::new(4, true);
win.add(json!({"role": "user", "content": "hi"})).unwrap();
win.add(json!({"role": "assistant", "content": [
{"type": "tool_use", "id": "u1", "name": "search", "input": {}}
]})).unwrap();
win.add(json!({"role": "user", "content": [
{"type": "tool_result", "tool_use_id": "u1", "content": "ok"}
]})).unwrap();
// Even with max_turns=4, paired protection applies.
assert_eq!(win.len(), 3);Structs§
- Message
Window - Sliding window over LLM conversation messages.