Skip to content

AgentDefinitionCompiler

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Converts an AgentDefinition definition into an executable AI.AIAgent instance.

public sealed class AgentDefinitionCompiler

objectAgentDefinitionCompiler

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

The conversion goes through these steps:

An unknown tool name results in an AgentPrismCompilationException. It is not silently skipped: an agent running with a missing tool is an agent that does not do the work the user expects.

AgentDefinitionCompiler(IModelProviderRegistry, IToolRegistry, ILoggerFactory?, IServiceProvider?, ChatHistoryProvider?, AgentSkillCatalog?, SkillScriptSupport?, CallableAgentResolver?, ITenantContext?, ModelBinding?, AgentFileStore?, IMcpResourceContextProviderFactory?, IVectorSearchStore?, IEmbeddingGenerator<string, Embedding<float>>?, int)

Section titled “ AgentDefinitionCompiler(IModelProviderRegistry, IToolRegistry, ILoggerFactory?, IServiceProvider?, ChatHistoryProvider?, AgentSkillCatalog?, SkillScriptSupport?, CallableAgentResolver?, ITenantContext?, ModelBinding?, AgentFileStore?, IMcpResourceContextProviderFactory?, IVectorSearchStore?, IEmbeddingGenerator<string, Embedding<float>>?, int)”

Creates a new compiler.

public AgentDefinitionCompiler(IModelProviderRegistry models, IToolRegistry tools, ILoggerFactory? loggerFactory = null, IServiceProvider? services = null, ChatHistoryProvider? chatHistoryProvider = null, AgentSkillCatalog? skills = null, SkillScriptSupport? scripts = null, CallableAgentResolver? callableAgents = null, ITenantContext? tenantContext = null, ModelBinding? utilityModel = null, AgentFileStore? fileStore = null, IMcpResourceContextProviderFactory? mcpResources = null, IVectorSearchStore? vectorSearchStore = null, IEmbeddingGenerator<string, Embedding<float>>? embeddingGenerator = null, int knowledgeMaxResults = 5)

models IModelProviderRegistry

Model provider registry.

tools IToolRegistry

Tool registry.

loggerFactory ILoggerFactory?

Logger factory passed to the produced agents.

services IServiceProvider?

Service provider passed to the produced agents.

chatHistoryProvider ChatHistoryProvider?

Chat history provider attached to the produced agents. When null, Microsoft Agent Framework’s in-memory default is used and history is carried inside the session state.

skills AgentSkillCatalog?

Catalog that resolves skill sources.

scripts SkillScriptSupport?

Skill script support. When null, no script can run; the feature is turned on with UseSkillScripts.

callableAgents CallableAgentResolver?

Resolver for callable sub-agents. When null, no agent can call another agent.

tenantContext ITenantContext?

Tenant context. Used to verify that sub-calls do not change tenant.

utilityModel ModelBinding?

Default model for summarization in context compaction. Used when an agent does not supply its own CompactionSettings.SummarizationModel; when null, falls back to the agent’s own model.

fileStore AgentFileStore?

File store used by memory providers. When null, a definition requesting MemorySettings.EnableFileMemory/EnableTextSearch gets a compilation error.

mcpResources IMcpResourceContextProviderFactory?

Factory that builds the context provider for AgentDefinition.McpResourceUris (Mode A). When null, a definition requesting an MCP resource gets a compilation error.

vectorSearchStore IVectorSearchStore?

Semantic search store. When null, a definition requesting MemorySettings.EnableVectorSearch gets a compilation error.

embeddingGenerator IEmbeddingGenerator<string, Embedding<float>>?

Embedding generator. When null, a definition requesting MemorySettings.EnableVectorSearch gets a compilation error.

knowledgeMaxResults int

Maximum number of results the search_knowledge tool returns.

ArgumentNullException

One of the required dependencies is null.

Converts a definition into an executable agent.

public AIAgent Compile(AgentDefinition definition)

definition AgentDefinition

The definition to compile.

AIAgent

The executable agent.

ArgumentNullException

definition is null.

AgentPrismCompilationException

The model provider cannot be found, or the definition references a tool name that is not registered.

Compile(AgentDefinition, ResolvedCallableAgents)

Section titled “ Compile(AgentDefinition, ResolvedCallableAgents)”

Converts a definition, together with its resolved sub-agents, into an executable agent.

public AIAgent Compile(AgentDefinition definition, ResolvedCallableAgents callableAgents)

definition AgentDefinition

The definition to compile.

callableAgents ResolvedCallableAgents

Sub-agent summaries resolved beforehand via AgentDefinitionCompiler.ResolveCallableAgentsAsync.

AIAgent

The executable agent.

ArgumentNullException

definition is null.

AgentPrismCompilationException

The model provider cannot be found, or the definition references a tool name that is not registered.

Compile(AgentDefinition, ResolvedCallableAgents, Func<AIFunction, AIFunction>?, string?)

Section titled “ Compile(AgentDefinition, ResolvedCallableAgents, Func<AIFunction, AIFunction>?, string?)”

Compiles a definition together with its resolved sub-agents, transforming its tools.

public AIAgent Compile(AgentDefinition definition, ResolvedCallableAgents callableAgents, Func<AIFunction, AIFunction>? toolTransform, string? culture = null)

definition AgentDefinition

The definition to compile.

callableAgents ResolvedCallableAgents

Sub-agent summaries resolved beforehand via AgentDefinitionCompiler.ResolveCallableAgentsAsync.

toolTransform Func<AIFunction, AIFunction>?

Transform applied to every tool resolved from the registry. When null, tools are bound as-is.

culture string?

The requested culture, resolved against AgentDefinition.InstructionsByCulture (see InstructionCultureResolver). null uses AgentDefinition.Instructions unconditionally.

AIAgent

The executable agent.

The transform exists for replay (ReplayToolMode.ReplayTools): a DelegatingAIFunction that replays recorded tool results preserves the wrapped tool’s name, description, and JSON schema - the model sees the tools exactly as before but no body actually runs.

The transform applies only to tools resolved from the IToolRegistry registry. Tools opened by skills and callable sub-agents come through an AIContextProvider and do not pass through here; the caller must disable them at the definition level instead.

The compiled agent cache (CompiledAgentCache) is not used for this path: the transform changes per call, and caching a replay agent would also break normal runs.

ArgumentNullException

definition is null.

AgentPrismCompilationException

The model provider cannot be found, or the definition references a tool name that is not registered.

CompileAsync(AgentDefinition, CancellationToken)

Section titled “ CompileAsync(AgentDefinition, CancellationToken)”

Converts a definition into an executable agent (BYOK).

public ValueTask<AIAgent> CompileAsync(AgentDefinition definition, CancellationToken cancellationToken)

definition AgentDefinition

The definition to compile.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AIAgent>

The executable agent.

The async counterpart of AgentDefinitionCompiler.Compile: resolves the requesting tenant’s own provider credential and egress policy (IModelProviderRegistry.CreateChatClientAsync) before building the client. When no tenant context or provider binding is registered, behavior is identical to the sync overload.

ArgumentNullException

definition is null.

AgentPrismCompilationException

The model provider cannot be found, the definition references a tool name that is not registered, the current tenant’s egress policy forbids the provider, or the tenant’s provider binding cannot be resolved to a credential value.

CompileAsync(AgentDefinition, ResolvedCallableAgents, string?, CancellationToken)

Section titled “ CompileAsync(AgentDefinition, ResolvedCallableAgents, string?, CancellationToken)”

Converts a definition, together with its resolved sub-agents, into an executable agent (BYOK).

public ValueTask<AIAgent> CompileAsync(AgentDefinition definition, ResolvedCallableAgents callableAgents, string? culture, CancellationToken cancellationToken)

definition AgentDefinition

The definition to compile.

callableAgents ResolvedCallableAgents

Sub-agent summaries resolved beforehand via AgentDefinitionCompiler.ResolveCallableAgentsAsync.

culture string?

See AgentDefinitionCompiler.Compile.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AIAgent>

The executable agent.

ArgumentNullException

definition is null.

AgentPrismCompilationException

See AgentDefinitionCompiler.CompileAsync.

CompileAsync(AgentDefinition, ResolvedCallableAgents, Func<AIFunction, AIFunction>?, string?, CancellationToken)

Section titled “ CompileAsync(AgentDefinition, ResolvedCallableAgents, Func<AIFunction, AIFunction>?, string?, CancellationToken)”

Compiles a definition together with its resolved sub-agents, transforming its tools (BYOK).

public ValueTask<AIAgent> CompileAsync(AgentDefinition definition, ResolvedCallableAgents callableAgents, Func<AIFunction, AIFunction>? toolTransform, string? culture, CancellationToken cancellationToken)

definition AgentDefinition

The definition to compile.

callableAgents ResolvedCallableAgents

Sub-agent summaries resolved beforehand via AgentDefinitionCompiler.ResolveCallableAgentsAsync.

toolTransform Func<AIFunction, AIFunction>?

Transform applied to every tool resolved from the registry. See AgentDefinitionCompiler.Compile.

culture string?

See AgentDefinitionCompiler.Compile.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AIAgent>

The executable agent.

ArgumentNullException

definition is null.

AgentPrismCompilationException

See AgentDefinitionCompiler.CompileAsync.

UsesTenantProviderOverrideAsync(ModelBinding, CancellationToken)

Section titled “ UsesTenantProviderOverrideAsync(ModelBinding, CancellationToken)”

Reports whether compiling binding for the current tenant would bake a tenant-specific provider credential into the resulting chat client (BYOK).

public ValueTask<bool> UsesTenantProviderOverrideAsync(ModelBinding binding, CancellationToken cancellationToken = default)

binding ModelBinding

The model binding to check — usually an AgentDefinition.Model.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true if the caller must not hand the compiled agent to CompiledAgentCache: see IModelProviderRegistry.HasTenantProviderOverrideAsync for the full reason.