CompiledAgentCache
AgentPrism.Core.dllCaches compiled agents keyed by (tenant, name, version, skill fingerprint, culture).
public sealed class CompiledAgentCacheInheritance
Section titled “Inheritance”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”When a definition is updated, its version increases and the cache naturally becomes stale. There is therefore no explicit invalidation logic; the old version’s entry is cleared with CompiledAgentCache.Evict.
The tenant component of the key is REQUIRED. Agent names are unique
only within a tenant (see SqlAgentDefinitionStore) - it is common for
two different tenants to have a definition with the same name (e.g.
"support"), the same version (the first record is always 1),
and the same dependency fingerprint (an empty string for both if they use
no skills/callable agents). If the tenant is not included in the key,
resolution for the second tenant returns the first tenant’s compiled agent
(instructions, tool bindings - including the tenant identity bound into
e.g. search_knowledge): tenant isolation broken outright.
Constructors
Section titled “Constructors”CompiledAgentCache()
Section titled “ CompiledAgentCache()”public CompiledAgentCache()Properties
Section titled “Properties”Number of entries in the cache.
public int Count { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Clear()
Section titled “ Clear()”Empties the cache entirely.
public void Clear()CombineFingerprints(string, string)
Section titled “ CombineFingerprints(string, string)”Combines multiple dependency fingerprints into a single key component.
public static string CombineFingerprints(string first, string second)Parameters
Section titled “Parameters”first string
First fingerprint.
second string
Second fingerprint.
Returns
Section titled “Returns”The combined fingerprint.
Remarks
Section titled “Remarks”A separator is required: fingerprints may not have a fixed length, and a direct concatenation would let two different pairs produce the same string.
Evict(string)
Section titled “ Evict(string)”Removes all versions of an agent from the cache.
public void Evict(string name)Parameters
Section titled “Parameters”name string
Agent name.
GetOrAdd(string, string, int, Func<AIAgent>)
Section titled “ GetOrAdd(string, string, int, Func<AIAgent>)”Retrieves the agent from the cache; if absent, produces it with
factory and adds it.
public AIAgent GetOrAdd(string tenantId, string name, int version, Func<AIAgent> factory)Parameters
Section titled “Parameters”tenantId string
Identifier of the tenant requesting resolution.
name string
Agent name.
version int
Definition version.
factory Func<AIAgent>
Producer called when absent from the cache.
Returns
Section titled “Returns”AIAgent
The compiled agent.
Exceptions
Section titled “Exceptions”One of the parameters is null.
GetOrAdd(string, string, int, string, Func<AIAgent>)
Section titled “ GetOrAdd(string, string, int, string, Func<AIAgent>)”Retrieves the agent from the cache together with its dependency
fingerprint; if absent, produces it with factory
and adds it.
public AIAgent GetOrAdd(string tenantId, string name, int version, string dependencyFingerprint, Func<AIAgent> factory)Parameters
Section titled “Parameters”tenantId string
Identifier of the tenant requesting resolution.
name string
Agent name.
version int
Definition version.
dependencyFingerprint string
Current fingerprint of the definition’s external dependencies: skills and callable sub-agents. These can change without incrementing the definition’s own version, so they need a separate key component.
factory Func<AIAgent>
Producer called when absent from the cache.
Returns
Section titled “Returns”AIAgent
The compiled agent.
GetOrAdd(string, string, int, string, string, Func<AIAgent>)
Section titled “ GetOrAdd(string, string, int, string, string, Func<AIAgent>)”Retrieves the agent from the cache together with its dependency fingerprint and
requested culture; if absent, produces it with factory and adds it.
public AIAgent GetOrAdd(string tenantId, string name, int version, string dependencyFingerprint, string culture, Func<AIAgent> factory)Parameters
Section titled “Parameters”tenantId string
Identifier of the tenant requesting resolution.
name string
Agent name.
version int
Definition version.
dependencyFingerprint string
See CompiledAgentCache.GetOrAdd.
culture string
The culture the definition was compiled with (see InstructionCultureResolver).
An empty string when the run requested no culture. Part of the key: two runs of the
same definition in different cultures must not share a compiled agent - the requested
instructions text is baked into AI.ChatOptions at
compile time.
factory Func<AIAgent>
Producer called when absent from the cache.
Returns
Section titled “Returns”AIAgent
The compiled agent.
GetOrAddAsync(string, string, int, string, Func<ValueTask<AIAgent>>)
Section titled “ GetOrAddAsync(string, string, int, string, Func<ValueTask<AIAgent>>)”Retrieves the agent from the cache together with its dependency
fingerprint; if absent, produces it asynchronously with
factory and adds it.
public ValueTask<AIAgent> GetOrAddAsync(string tenantId, string name, int version, string dependencyFingerprint, Func<ValueTask<AIAgent>> factory)Parameters
Section titled “Parameters”tenantId string
Identifier of the tenant requesting resolution.
name string
Agent name.
version int
Definition version.
dependencyFingerprint string
See CompiledAgentCache.GetOrAdd.
factory Func<ValueTask<AIAgent>>
Producer called when absent from the cache.
Returns
Section titled “Returns”ValueTask<AIAgent>
The compiled agent.
Remarks
Section titled “Remarks”Compiling now needs an async credential lookup on a
cache miss. Concurrent.ConcurrentDictionary has no
native async GetOrAdd; the same “the factory may run more than
once, production is side-effect free, an extra instance is discarded”
guarantee as the sync overload applies here too.
GetOrAddAsync(string, string, int, string, string, Func<ValueTask<AIAgent>>)
Section titled “ GetOrAddAsync(string, string, int, string, string, Func<ValueTask<AIAgent>>)”Retrieves the agent from the cache together with its dependency fingerprint and
requested culture; if absent, produces it asynchronously with
factory and adds it.
public ValueTask<AIAgent> GetOrAddAsync(string tenantId, string name, int version, string dependencyFingerprint, string culture, Func<ValueTask<AIAgent>> factory)Parameters
Section titled “Parameters”tenantId string
Identifier of the tenant requesting resolution.
name string
Agent name.
version int
Definition version.
dependencyFingerprint string
See CompiledAgentCache.GetOrAdd.
culture string
See CompiledAgentCache.GetOrAdd.
factory Func<ValueTask<AIAgent>>
Producer called when absent from the cache.
Returns
Section titled “Returns”ValueTask<AIAgent>
The compiled agent.