Tool Caching
RadarOS supports result caching for tools. When a tool is called with the same arguments within the TTL window, the cached result is returned instantly — no re-execution.Quick Start
getWeather("Mumbai") twice within 60 seconds, the second call returns the cached result without hitting the API.
Configuration
Add acache property to any tool definition:
Time-to-live in milliseconds. Cached results expire after this duration. Example:
60_000 for 1 minute, 300_000 for 5 minutes.How It Works
- When a tool is called, the
ToolExecutorgenerates a cache key from the tool name and a stable serialization of the arguments. - If a valid (non-expired) cache entry exists for that key, the result is returned immediately.
- If no cache entry exists, the tool executes normally and the result is stored with an expiry timestamp.
Cache Key Strategy
Cache keys are generated astoolName:stableStringify(args) — arguments are sorted by key to ensure consistent hashing regardless of property order.
Clearing the Cache
TheToolExecutor exposes a clearCache() method for programmatic cache invalidation. This is useful in testing or when you know external data has changed.
When to Use
Good Candidates
- External API calls (weather, exchange rates)
- Database lookups with stable results
- Expensive computations
- Rate-limited APIs
Poor Candidates
- Tools with side effects (send email, write file)
- Real-time data that changes every second
- Tools where arguments include timestamps
ToolCacheConfig Type
Logging
WhenlogLevel is "info" or higher, cached tool results are prefixed with [cached] in the logs, making it easy to verify caching behavior during development.