Implementation:23blocks OS Ai maestro Agent Cache
| Knowledge Sources | |
|---|---|
| Domains | Caching, UI |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for client-side hybrid caching of remote-host agents in localStorage with a 24-hour TTL, falling back to cached data when peers are unreachable, provided by AI Maestro's `lib/agent-cache.ts`.
Description
The agent-cache module provides hybrid client-side caching for agents from peer hosts. `cacheRemoteAgents` stores agents per host in localStorage (`aimaestro-remote-agents`) with a timestamp. `getCachedAgents` returns cached agents for a host only if the cache is within the 24-hour TTL; expired cache is cleared. The cache is used by `useAgents` to keep the dashboard usable when peer hosts are down.
Usage
Call `cacheRemoteAgents(hostId, agents)` after a successful peer fetch. Call `getCachedAgents(hostId)` on fetch failure to fall back.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/agent-cache.ts
- Lines: L1-L173
Signature
export function cacheRemoteAgents(hostId: string, agents: UnifiedAgent[]): void
export function getCachedAgents(hostId: string): UnifiedAgent[] | null
export function clearCachedHost(hostId: string): void
export function clearAllCachedAgents(): void
Import
import { cacheRemoteAgents, getCachedAgents } from '@/lib/agent-cache'
I/O Contract
| Name | Type | Description |
|---|---|---|
| getCachedAgents() returns | null | Cached agents (within TTL) or null |
| cacheRemoteAgents() | void | Stores agents with current timestamp |
Usage Examples
import { cacheRemoteAgents, getCachedAgents } from '@/lib/agent-cache'
// On successful fetch
cacheRemoteAgents(host.id, agents)
// On fetch failure — fall back
const cached = getCachedAgents(host.id)
if (cached) renderFromCache(cached)