Skip to main content

ToolCache

Trait ToolCache 

Source
pub trait ToolCache: Send + Sync {
    // Required methods
    fn get(&self, tool_name: &str, args: &Value) -> Option<Value>;
    fn set(&self, tool_name: &str, args: &Value, result: Value);
}
Expand description

Cache for tool call results.

Implement to deduplicate repeated identical tool calls within a single ReActLoop::run invocation.

§Cache key

Implementations should key on (tool_name, args). The args value is the full parsed JSON object passed to the tool.

§Thread safety

The trait is Send + Sync, so implementations must be safe to share across threads. Wrap mutable state in a Mutex or use lock-free atomics.

§TTL

TTL semantics are implementation-defined. A simple in-memory cache may keep results for the lifetime of the ReActLoop::run call; a distributed cache may use Redis with explicit expiry.

§Lifetime

A cache instance is attached to a ToolRegistry and lives for the lifetime of that registry. Results are not automatically cleared between ReActLoop::run calls — clear the cache explicitly if cross-run dedup is not desired.

Required Methods§

Source

fn get(&self, tool_name: &str, args: &Value) -> Option<Value>

Look up a cached result for (tool_name, args).

Source

fn set(&self, tool_name: &str, args: &Value, result: Value)

Store a result for (tool_name, args).

Implementors§