pub struct AutomationMemory {
pub store: HashMap<String, Value>,
pub extractions: Vec<Value>,
pub visited_urls: Vec<String>,
pub action_history: Vec<String>,
}Expand description
In-memory storage for agentic automation sessions.
This provides a key-value store and history tracking that persists across automation rounds, enabling the LLM to maintain context and state without relying on external storage.
§Features
- Key-Value Store: Store and retrieve arbitrary JSON values by key
- Extraction History: Accumulate extracted data across pages
- URL History: Track visited URLs for navigation context
- Action Summary: Brief history of executed actions
§Example
use spider_agent_types::AutomationMemory;
let mut memory = AutomationMemory::default();
memory.set("user_logged_in", serde_json::json!(true));
memory.set("cart_items", serde_json::json!(["item1", "item2"]));
// Memory is serialized and included in LLM context each round
let context = memory.to_context_string();Fields§
§store: HashMap<String, Value>Key-value store for persistent data across rounds.
extractions: Vec<Value>History of extracted data from pages (most recent last).
visited_urls: Vec<String>History of visited URLs (most recent last).
action_history: Vec<String>Brief summary of recent actions (most recent last, max 50).
Implementations§
Source§impl AutomationMemory
impl AutomationMemory
Sourcepub fn clear_store(&mut self)
pub fn clear_store(&mut self)
Clear all stored data.
Sourcepub fn add_extraction(&mut self, data: Value)
pub fn add_extraction(&mut self, data: Value)
Add an extracted value to history.
Sourcepub fn add_visited_url(&mut self, url: impl Into<String>)
pub fn add_visited_url(&mut self, url: impl Into<String>)
Record a visited URL.
Sourcepub fn add_action(&mut self, action: impl Into<String>)
pub fn add_action(&mut self, action: impl Into<String>)
Record an action summary (keeps max 50 entries).
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear all history (extractions, URLs, actions) but keep the store.
Sourcepub fn to_context_string(&self) -> String
pub fn to_context_string(&self) -> String
Generate a context string for inclusion in LLM prompts.
Sourcepub fn apply_operation(&mut self, op: &MemoryOperation)
pub fn apply_operation(&mut self, op: &MemoryOperation)
Apply a memory operation.
Sourcepub fn apply_operations(&mut self, ops: &[MemoryOperation])
pub fn apply_operations(&mut self, ops: &[MemoryOperation])
Apply multiple memory operations.
Sourcepub fn increment_level_attempt(&mut self, level_key: &str) -> u32
pub fn increment_level_attempt(&mut self, level_key: &str) -> u32
Increment and return attempt count for a logical level key.
Stored in store["_level_attempts"][level_key].
Sourcepub fn reset_level_attempt(&mut self, level_key: &str)
pub fn reset_level_attempt(&mut self, level_key: &str)
Reset attempt count for a logical level key (e.g., after forced refresh).
Sourcepub fn get_level_attempt(&self, level_key: &str) -> u32
pub fn get_level_attempt(&self, level_key: &str) -> u32
Return attempt count for a logical level key.
Trait Implementations§
Source§impl Clone for AutomationMemory
impl Clone for AutomationMemory
Source§fn clone(&self) -> AutomationMemory
fn clone(&self) -> AutomationMemory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more