Skip to main content

AutomationMemory

Struct AutomationMemory 

Source
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

Source

pub fn new() -> Self

Create a new empty memory.

Source

pub fn set(&mut self, key: impl Into<String>, value: Value)

Store a value by key.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get a value by key.

Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Remove a value by key.

Source

pub fn contains(&self, key: &str) -> bool

Check if a key exists.

Source

pub fn clear_store(&mut self)

Clear all stored data.

Source

pub fn add_extraction(&mut self, data: Value)

Add an extracted value to history.

Source

pub fn add_visited_url(&mut self, url: impl Into<String>)

Record a visited URL.

Source

pub fn add_action(&mut self, action: impl Into<String>)

Record an action summary (keeps max 50 entries).

Source

pub fn clear_history(&mut self)

Clear all history (extractions, URLs, actions) but keep the store.

Source

pub fn clear_all(&mut self)

Clear everything.

Source

pub fn is_empty(&self) -> bool

Check if memory is empty.

Source

pub fn to_context_string(&self) -> String

Generate a context string for inclusion in LLM prompts.

Source

pub fn apply_operation(&mut self, op: &MemoryOperation)

Apply a memory operation.

Source

pub fn apply_operations(&mut self, ops: &[MemoryOperation])

Apply multiple memory operations.

Source

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].

Source

pub fn reset_level_attempt(&mut self, level_key: &str)

Reset attempt count for a logical level key (e.g., after forced refresh).

Source

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

Source§

fn clone(&self) -> AutomationMemory

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AutomationMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AutomationMemory

Source§

fn default() -> AutomationMemory

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AutomationMemory

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AutomationMemory

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,