agent_chain_core/messages/
modifier.rs

1//! Message modifier types.
2//!
3//! This module contains types for modifying message history,
4//! such as `RemoveMessage`. Mirrors `langchain_core.messages.modifier`.
5
6use serde::{Deserialize, Serialize};
7
8#[cfg(feature = "specta")]
9use specta::Type;
10
11/// Message responsible for deleting other messages.
12///
13/// This is used to remove messages from a conversation history by their ID.
14/// This corresponds to `RemoveMessage` in LangChain Python.
15#[cfg_attr(feature = "specta", derive(Type))]
16#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
17pub struct RemoveMessage {
18    /// The ID of the message to remove
19    id: String,
20}
21
22impl RemoveMessage {
23    /// Create a new RemoveMessage.
24    ///
25    /// # Arguments
26    ///
27    /// * `id` - The ID of the message to remove.
28    pub fn new(id: impl Into<String>) -> Self {
29        Self { id: id.into() }
30    }
31
32    /// Get the ID of the message to be removed.
33    pub fn id(&self) -> Option<&str> {
34        Some(&self.id)
35    }
36
37    /// Get the target message ID.
38    pub fn target_id(&self) -> &str {
39        &self.id
40    }
41}