Skip to main content

latch_core/
message.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
4pub struct Message {
5    pub role: String,
6    pub content: String,
7}
8
9impl Message {
10    pub fn new(role: impl Into<String>, content: impl Into<String>) -> Self {
11        Self {
12            role: role.into(),
13            content: content.into(),
14        }
15    }
16
17    /// Check if this message contains a tool_use content block
18    /// This is a lightweight check that looks for the "type":"tool_use" pattern in content
19    pub fn is_tool_call(&self) -> bool {
20        self.role == "assistant" && self.content.contains("\"type\":\"tool_use\"")
21    }
22
23    /// Check if this message contains a tool_result content block
24    /// This is a lightweight check that looks for the "type":"tool_result" pattern in content
25    pub fn is_tool_result(&self) -> bool {
26        self.role == "user" && self.content.contains("\"type\":\"tool_result\"")
27    }
28}