Cache
cache
¶
Per-agent model roster cache for the ACP host-proxy.
Probing an agent (initialize + session/new + read configOptions) is
expensive and the result is stable for the lifetime of an authenticated
session. The cache is keyed (image_id, auth_identity, agent_id):
same image, same auth, same agent ⇒ same model list.
The cache is populated lazily on the first session/new after a new
auth, and never re-probed mid-session. invalidate_auth lets workflows
flush an entire identity's worth of entries when credentials change (today
auth is global so this is rarely useful; the hook exists for future
per-project auth).
GLOBAL_CACHE = AgentRosterCache()
module-attribute
¶
CacheKey(image_id, auth_identity, agent_id)
dataclass
¶
Composite key for one agent's roster within one auth scope.
auth_identity is the constant "global" today (terok auth is
process-wide); the field exists from day one so per-project auth can
slot in without a key-schema migration.
AgentRosterCache()
¶
Thread-safe map from CacheKey to a tuple of model ids.
Models are stored as a tuple so cache entries are immutable once inserted — callers can return them directly without defensive copying. Empty tuples are valid and signal "probe ran but yielded nothing" (saved to avoid hammering a misconfigured agent on every session).
Source code in src/terok_executor/acp/cache.py
get(key)
¶
put(key, models)
¶
invalidate_auth(auth_identity)
¶
Drop every entry tied to auth_identity.
Used when credentials for an identity rotate — the next
session/new re-probes affected agents.