pub struct MessageAttributes {
pub priority: u8,
pub cacheable: bool,
pub cache_type: Option<CacheType>,
pub cache_key: Option<String>,
pub category: MessageCategory,
pub metadata: HashMap<String, Value>,
}Expand description
Attributes that guide how providers handle a message.
These attributes control caching behavior, message ordering, and provide metadata that providers can use for optimization.
§Caching
For Anthropic’s prompt caching, set cacheable: true and optionally
specify a CacheType. The cache_key helps identify content for
deduplication across requests.
§Priority
Priority determines message ordering when using UnifiedLLMRequest::sort_messages().
Lower values = higher priority (processed first). Range: 0-255.
§Example
use multi_llm::{MessageAttributes, MessageCategory, CacheType};
use std::collections::HashMap;
// Cacheable system instruction with highest priority
let system_attrs = MessageAttributes {
priority: 0,
cacheable: true,
cache_type: Some(CacheType::Extended),
cache_key: Some("system-v1".to_string()),
category: MessageCategory::SystemInstruction,
metadata: HashMap::new(),
};
// Current user message (not cached, lowest priority)
let user_attrs = MessageAttributes::default(); // priority=50, cacheable=falseFields§
§priority: u8Priority for message ordering (lower = higher priority).
Default is 50. Range: 0 (highest) to 255 (lowest).
Used by UnifiedLLMRequest::sort_messages() to order messages.
cacheable: boolWhether this message content is static and can be cached.
When true, providers that support caching (like Anthropic) will
attempt to cache this content for subsequent requests.
cache_type: Option<CacheType>Cache TTL type for Anthropic prompt caching.
CacheType::Ephemeral: 5-minute TTL, 1.25x write costCacheType::Extended: 1-hour TTL, 2x write cost
Only meaningful when cacheable is true. Ignored by providers
that don’t support prompt caching.
cache_key: Option<String>Optional cache key for content deduplication.
When provided, helps identify identical content across requests. Useful for versioning system prompts (e.g., “system-v2”).
category: MessageCategorySemantic category for provider-specific handling.
See MessageCategory for details on how categories affect
caching and priority defaults.
metadata: HashMap<String, Value>Custom metadata for application-specific extensions.
This data is passed through but not interpreted by multi-llm. Useful for tracking, logging, or application-specific processing.
Trait Implementations§
Source§impl Clone for MessageAttributes
impl Clone for MessageAttributes
Source§fn clone(&self) -> MessageAttributes
fn clone(&self) -> MessageAttributes
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more