Skip to content

CodeAgentSource

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A source that exposes code-defined agents in the catalog.

public sealed class CodeAgentSource : IAgentSource

objectCodeAgentSource

IAgentSource

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Its priority is 0, the highest. If a database definition has the same name, code wins because it is validated at build time while the database definition is run-time data.

CodeAgentSource(IEnumerable<CodeAgentRegistration>, AgentDefinitionCompiler, CompiledAgentCache, IServiceProvider, ITenantContext)

Section titled “ CodeAgentSource(IEnumerable<CodeAgentRegistration>, AgentDefinitionCompiler, CompiledAgentCache, IServiceProvider, ITenantContext)”

Initializes a new code source.

public CodeAgentSource(IEnumerable<CodeAgentRegistration> registrations, AgentDefinitionCompiler compiler, CompiledAgentCache cache, IServiceProvider services, ITenantContext tenantContext)

registrations IEnumerable<CodeAgentRegistration>

The code agent registrations.

compiler AgentDefinitionCompiler

The compiler for declarative definitions.

cache CompiledAgentCache

The compiled agent cache.

services IServiceProvider

The service provider supplied to factory registrations.

tenantContext ITenantContext

The tenant context. Code agent definitions are shared across tenants, but AgentDefinitionCompiler can bind tenant-dependent tools, such as semantic search, to the ambient tenant at compilation time. See AddVectorSearchTool. Adding the tenant to the cache key prevents that binding from leaking to another tenant.

ArgumentNullException

A dependency is null.

AgentPrismException

The same agent name is registered more than once.

Gets the name of the source, used for diagnostics and user interface badges.

public string Name { get; }

string

Gets the resolution priority. A lower value is tried first. When two agents share a name, the source with priority wins.

public int Priority { get; }

int

The values in use: 0 for the code source, 10 for the MAF hosting source, 100 for the database source.

Lists every agent in this source.

public ValueTask<IReadOnlyList<AgentDescriptor>> ListAsync(CancellationToken cancellationToken = default)

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<AgentDescriptor>>

The agent summaries.

ResolveAsync(string, string?, CancellationToken)

Section titled “ ResolveAsync(string, string?, CancellationToken)”

Resolves the agent with the given name and makes it runnable.

public ValueTask<AIAgent?> ResolveAsync(string agentName, string? culture = null, CancellationToken cancellationToken = default)

agentName string

The agent name.

culture string?

The requested culture, resolved against the definition’s culture-keyed instructions (see AgentDefinition.InstructionsByCulture). null uses the definition’s default instructions.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AIAgent?>

The agent, or null when this source does not hold it.