agent-message-window 0.1.0

Sliding window of recent LLM conversation turns with paired-protection: never drop a tool_use without its tool_result sibling. Zero deps (serde_json only).
Documentation
  • Coverage
  • 50%
    8 out of 16 items documented1 out of 14 items with examples
  • Size
  • Source code size: 31.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 438.41 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • MukundaKatta/agent-message-window-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MukundaKatta

agent-message-window

Sliding window of recent LLM conversation turns with paired-protection: never drop a tool_use message without also dropping its tool_result sibling.

The Anthropic API rejects conversations where a tool_result block references a tool_use ID that is no longer in the message history. A naive "drop the oldest" window breaks the next request silently. This crate fixes that.

Usage

use agent_message_window::MessageWindow;
use serde_json::json;

let mut win = MessageWindow::new(20, true);

win.add(json!({"role": "user", "content": "search for X"})).unwrap();
win.add(json!({
    "role": "assistant",
    "content": [
        {"type": "tool_use", "id": "u1", "name": "search", "input": {"q": "X"}}
    ]
})).unwrap();
win.add(json!({
    "role": "user",
    "content": [
        {"type": "tool_result", "tool_use_id": "u1", "content": "results..."}
    ]
})).unwrap();

// Pass win.messages_owned() to the next API call.

Features

  • max_turns cap with oldest-first eviction
  • Paired protection: evicting a tool_use cascades to orphaned tool_result messages
  • paired_protect = false for raw oldest-first eviction
  • Zero dependencies beyond serde_json

License

MIT OR Apache-2.0