Documents the CrestApps.Core 2.0 orchestration pipeline: registration, context building, tool scoping, preemptive RAG, and custom orchestrator creation.
Ships in crestapps-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The orchestrator is the agentic loop: it builds context from the profile, scopes tools, runs preemptive retrieval, calls the model with function invocation, and streams the answer. DefaultOrchestrator (name "default") is registered by AddCoreAIOrchestration(); Claude ("anthropic") and Copilot ("copilot") are alternatives.
AddAISuite(...) or AddCoreAIOrchestration().IOrchestrationContextBuilder.BuildAsync(resource, configure, cancellationToken) instead of filling OrchestrationContext by hand; the handlers add the system message, tools, documents, RAG and security preamble.IOrchestratorResolver.Resolve(name). An empty or unknown name falls back to OrchestratorOptions.DefaultOrchestratorName.chat slot and planning runs on the utility deployment (falling back to chat). See crestapps-core-ai-runtime.builder.Services.AddCrestAppsCore(crestApps => crestApps
.AddAISuite(ai => ai
.AddOpenAI()
)
);
Raw form:
builder.Services
.AddCoreAIServices()
.AddCoreAIOrchestration()
.AddCoreAIOpenAI();
using CrestApps.Core.AI.Models;
using CrestApps.Core.AI.Orchestration;
using Microsoft.Extensions.AI;
public sealed class ProfileChatService
{
private readonly IOrchestrationContextBuilder _contextBuilder;
private readonly IOrchestratorResolver _orchestratorResolver;
public ProfileChatService(
IOrchestrationContextBuilder contextBuilder,
IOrchestratorResolver orchestratorResolver)
{
_contextBuilder = contextBuilder;
_orchestratorResolver = orchestratorResolver;
}
public async IAsyncEnumerable<string> StreamAsync(
AIProfile profile,
string userMessage,
IList<ChatMessage> history,
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var context = await _contextBuilder.BuildAsync(
profile,
ctx =>
{
ctx.UserMessage = userMessage;
ctx.ConversationHistory = history;
},
cancellationToken);
var orchestrator = _orchestratorResolver.Resolve(profile.OrchestratorName);
await foreach (var update in orchestrator.ExecuteStreamingAsync(context, cancellationToken))
{
if (!string.IsNullOrEmpty(update.Text))
{
yield return update.Text;
}
}
}
}
There is no separate non-streaming API; collect the updates when you need the full text. The built-in chat hubs go through IChatResponseHandler (see crestapps-core-response-handlers), which also sets AIInvocationScope for tools and agents; code that calls the orchestrator directly should wrap the call in using var scope = AIInvocationScope.Begin(); when it uses tool-capable agents or citation tools.
| Service | Purpose |
|---|---|
IOrchestrator | Name and ExecuteStreamingAsync(OrchestrationContext, CancellationToken) returning IAsyncEnumerable<ChatResponseUpdate> |
IOrchestratorResolver | Resolve(orchestratorName) with fallback to the default |
IOrchestrationContextBuilder | Runs IOrchestrationContextBuilderHandlers |
IToolRegistry | GetAllAsync(AICompletionContext, CancellationToken) merges every IToolRegistryProvider |
IAIToolsService | Resolve a registered keyed AITool by name |
IChatResponseHandlerResolver | Pick the response handler for a session or interaction |
Tool registry providers: SystemToolRegistryProvider, ProfileToolRegistryProvider, AgentToolRegistryProvider, SharedStateToolRegistryProvider (update_shared_state when an AG-UI run shares state), ClientToolRegistryProvider (an AG-UI client's frontend tools), and ToolInstanceRegistryProvider when tool instances are enabled. Built-in orchestration handlers: CompletionContextOrchestrationHandler, PreemptiveRagOrchestrationHandler, RealtimeRagGuidanceHandler, AIToolExecutionContextOrchestrationHandler, SecurityPromptOrchestrationHandler, ClientContextOrchestrationHandler (AG-UI page context and shared state in the system message, as data), plus data source, memory and document handlers from their features.
IToolMaterializer (DefaultToolMaterializer) turns registry entries into AITool instances with ToolMaterializationOptions: EnforceListableAccess and User for the Chat Interaction access check (alias-aware through the IAIToolAccessEvaluator.IsAuthorizedAsync(user, name, definition) extension), SupportsToolApproval, set from AICompletionContextKeys.ToolApprovalSupported, and ApprovalPolicy, from AICompletionContextKeys.ToolApprovalPolicy.
RequiresApproval is set (an explicit .RequireApproval() or a Destructive, External or Security kind) is wrapped in ApprovalRequiredAIFunction when the caller can ask, and replaced with an internal stand-in (same name and schema) that returns a "was not run" message when it cannot, so realtime sessions, the Claude and Copilot orchestrators, chat interactions and background work never run it unasked. A non-AIFunction approval tool is left out of every request.ToolApprovalPolicy lets run without asking is wrapped so that it logs and counts each call; a tool with an ApprovalFloor always asks.AgentProxyTool keeps the agent's run, and the orchestrator adds a ToolApprovalRequestContent per waiting call (with AgentToolApprovalProperties) at the end of the stream. See crestapps-core-ag-ui and crestapps-core-ai-agents.AgentToolRegistryProvider and the system message's agent list skip AICompletionContext.RunningAgentName, so an agent is never offered to itself.ProfileToolRegistryProvider, DefaultToolRegistry and ExpandToolNames resolve stored tool aliases to the current name.Built-in system tools: GenerateImageTool and GenerateChartTool (purpose content_generation) and CurrentDateTimeTool (selectable, category Utilities).
| Tool count | Behavior |
|---|---|
At or below ScopingThreshold (30) | All tools are passed through |
Above that, at or below PlanningThreshold (100), no MCP tools | Token relevance scoring against the latest user and assistant messages; top InitialToolCount (20) plus must-include tools |
Above PlanningThreshold, or any MCP tools | A planning call on the utility deployment, then relevance scoring |
If planning fails, the orchestrator logs a warning and still scopes by the user message and recent conversation. Planning resolves the utility deployment with ResolveUtilityOrDefaultAsync, applies UseDefaultResilience() and the utility model parameters (UseModelParameters(..., AIDeploymentParameterScope.Utility)), and is labeled AIUsagePurposes.Planning in usage records.
builder.Services.Configure<DefaultOrchestratorOptions>(options =>
{
options.InitialToolCount = 20;
options.ScopingThreshold = 30;
options.PlanningThreshold = 100;
options.MaxExpansionRounds = 3;
options.MaxToolCount = 30;
options.PlanningHistoryMessageCount = 10;
});
builder.Services.Configure<DefaultOrchestratorSettings>(settings =>
{
settings.EnablePreemptiveRag = true;
});
The tool-calling loop iteration cap comes from DefaultAIOptions.MaximumIterationsPerRequest (default 30, absolute cap AbsoluteMaximumIterationsPerRequest 100), which a site can override through GeneralAIOptions (OverrideMaximumIterationsPerRequest, MaximumIterationsPerRequest, also default 30).
DefaultAIOptions.TopP, FrequencyPenalty and PresencePenalty default to null, like Temperature and MaxOutputTokens; a null value is not sent, so the model uses its own default. A profile's past-messages count keeps that many of the most recent messages; blank, 0 or negative keeps them all. With session memory on, the messages that fall out are summarized instead of dropped (see crestapps-core-ai-memory).
Site-wide DefaultOrchestratorSettings.EnablePreemptiveRag = false hands data-source and document retrieval to the search tools, but preemptive memory retrieval follows its own GeneralAIOptions.EnablePreemptiveMemoryRetrieval switch. An IPreemptiveRagHandler with its own switch returns true from RunsWhenPreemptiveRagIsDisabled. Data-source search instructions are no longer added to a prompt with no data source or document to search.
using System.Runtime.CompilerServices;
using CrestApps.Core.AI.Completions;
using CrestApps.Core.AI.Deployments;
using CrestApps.Core.AI.Models;
using CrestApps.Core.AI.Orchestration;
using Microsoft.Extensions.AI;
public sealed class SingleShotOrchestrator : IOrchestrator
{
public const string OrchestratorName = "single-shot";
private readonly IAICompletionService _completionService;
private readonly IAIDeploymentManager _deploymentManager;
public SingleShotOrchestrator(
IAICompletionService completionService,
IAIDeploymentManager deploymentManager)
{
_completionService = completionService;
_deploymentManager = deploymentManager;
}
public string Name => OrchestratorName;
public async IAsyncEnumerable<ChatResponseUpdate> ExecuteStreamingAsync(
OrchestrationContext context,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(context);
var deployment = await _deploymentManager.ResolveSlotAsync(
AIDeploymentSlotNames.Chat,
deploymentName: context.CompletionContext?.ChatDeploymentName,
cancellationToken: cancellationToken)
?? throw new InvalidOperationException("Unable to resolve a chat deployment.");
var messages = new List<ChatMessage>(context.ConversationHistory)
{
new(ChatRole.User, context.UserMessage),
};
await foreach (var update in _completionService.CompleteStreamingAsync(
deployment, messages, context.CompletionContext, cancellationToken))
{
yield return update;
}
}
}
builder.Services.AddOrchestrator<SingleShotOrchestrator>(SingleShotOrchestrator.OrchestratorName)
.WithTitle("Single shot");
The completion context already carries the system message the handlers built, so a custom orchestrator does not add it again. Set AIProfile.OrchestratorName to route a profile to it.
| Situation | Behavior |
|---|---|
| Planning failure | Logged; falls back to relevance scoring |
| No chat deployment resolves | InvalidOperationException |
OperationCanceledException | Always rethrown |
| Provider error after retries | Propagates to the caller |
| Tool error | Returned to the model as the tool result |
| Approval-required tool, caller cannot ask | The model gets a "was not run" result; crestapps.core.ai.tool.denied with reason=approval |
TopP, FrequencyPenalty and PresencePenalty no longer default to 1, 0 and 0. Reasoning models (gpt-5.x and later) rejected a saved TopP = 1 with HTTP 400. A host that set "TopP": null in configuration to work around it can remove that.MaximumIterationsPerRequest defaults to 30 (was 10) in DefaultAIOptions, GeneralAIOptions and GeneralAISettings.AICompletionContextKeys.ContinuesOnNextPage, it sets AICompletionContextKeys.EndTurnAfterToolCalls in AIInvocationScope.Current.Items and terminates the function invocation loop, as WebMcpPageToolFunction does for page_navigate. A run that resumes after a tool approval (the history ends with ToolApprovalResponseContent) goes to the model as it is.ResolveSlotAsync(AIDeploymentSlotNames.Chat, ...) and planning with ResolveUtilityOrDefaultAsync(...); custom orchestrators that used ResolveOrDefaultAsync(AIDeploymentPurpose...) must switch.reasoningEffort of None for a reasoning utility model).IAIToolAccessEvaluator.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/crestapps-core:crestapps-core-orchestrationfrom crestapps-core
npx claudepluginhub crestapps/crestapps.agentskills --plugin crestapps-core51 skills in this plugin
/crestapps-core-a2aSkill for Agent-to-Agent (A2A) protocol support in CrestApps.Core on the A2A 1.0 SDK. Covers AddA2AClient and AddCoreAIA2AClient with Entity Framework Core or YesSql connection stores, A2AConnection and A2AConnectionMetadata authentication, AIProfileA2AMetadata, the agent card cache and A2AToolRegistryProvider, the listAvailableAgents, findAgentForTask and findToolsForTask tools, building an A2A host with IAgentHandler, A2AServer, ITaskStore and MapA2A, A2A 1.0 agent cards with supportedInterfaces published at /.well-known/agent-card.json, A2AHostOptions authentication and ExposeAgentsAsSkill, system agents exposed through the host, and upgrading from the 0.3 SDK./crestapps-core-ag-uiSkill for running the CrestApps.Core 2.0 AI chat as an AG-UI agent. Covers the CrestApps.Core.AI.AGUI package (AGUIRunEventWriter, AGUIRunRequest, AGUIJson), AIChatHubCore.RunAgent over SignalR and MapAGUIChat with Server-Sent Events, the RunAgentInput members and streamed events, tool approvals with RequireApproval or an approval tool kind, ApprovalRequiredAIFunction, interrupts and resume, approvals inside agents, page context with crestAppsAGUI.registerContextProvider, shared state with registerStateProvider and update_shared_state, frontend tools, stored tool calls (ChatTurnToolActivity), runs that continue on the next page, AGUIChatOptions.DisconnectedRunTimeout, the protocol and sendPageContext chat options, and the AICompletionContextKeys and ChatResponseHandlerContext members. Use it when showing tool calls in the chat, asking a person before a tool runs, sharing page state with the agent, connecting CopilotKit or another AG-UI client, or troubleshooting approvals and continued runs./crestapps-core-ai-agentsSkill for AI agents in CrestApps.Core 2.0, specialized AIProfile records of type Agent that the primary model invokes as tools. Covers creating agent profiles with AgentMetadata availability (OnDemand or AlwaysAvailable), linking them with AgentInvocationMetadata, how AgentProxyTool runs an agent with tools disabled or through the orchestrator when AllowToolInvocation is set, the AgentInvocationDepth recursion guard, never offering an agent to itself (RunningAgentName), tools of an agent that require an approval and pause the agent, deployment inheritance and the chat slot, code-defined and system agents through IAIProfileProvider including the Tabular Data, PDF, Presentation and Word agents, chat-specific agents that read AIInvocationScope, exposing agents to MCP clients with McpServerOptions Agents and ExposeAllAgents, and SubAgent usage labels. Use it when delegating work to sub-agents, adding a framework-managed agent, publishing an agent over MCP, or troubleshooting an agent the model does not call./crestapps-core-ai-markdownSkill for Markdig-backed Markdown normalization in CrestApps.Core 2.0 AI document, data source and RAG flows. Covers the CrestApps.Core.AI.Markdown package, AddMarkdown on the AI suite builder and AddCoreAIMarkdown on IServiceCollection, MarkdownAITextNormalizer replacing the default IAITextNormalizer, RagTextNormalizer content, chunk and title normalization with HTML stripping and Microsoft.Extensions.DataIngestion.Markdig parsing, the gpt-4o tokenizer chunker with 500 tokens per chunk and 50 tokens of overlap, the plain-text fallback for unsupported inline types, where the normalizer is used (data source indexing, preemptive retrieval, reference titles), and pairing it with document processing. Use it when indexing Markdown-heavy content for retrieval, replacing the text normalizer, or troubleshooting chunk sizes and leftover markup in retrieved text./crestapps-core-ai-memorySkill for AI memory in CrestApps.Core. Covers AddAIMemory, AddCoreAIMemory and AddCoreAIMemoryIndexing, Entity Framework Core and YesSql memory stores, the AIMemory index profile on the Elasticsearch, Azure AI Search and PostgreSQL backends, AIMemoryOptions, the store fallback when no index is usable, background memory indexing, the three kinds of memory (session memory with AIConversationMemory summaries and search_conversation, past conversations with search_past_conversations and list_recent_conversations, durable user memory) switched by MemoryMetadata and ChatInteractionMemoryOptions, preemptive memory retrieval and RunsWhenPreemptiveRagIsDisabled, owner-only chat sessions, the user memory tools, IAIMemorySafetyService validation, and custom IMemoryVectorSearchService implementations./crestapps-core-ai-model-capabilitiesSkill for metadata-driven deployment capabilities in CrestApps.Core 2.0. Covers trained model features such as textGeneration, toolCalling, streaming, reasoning, realtime, textEmbedding, speechToText and textToSpeech, model parameters such as reasoningEffort, declaring them with AIDeploymentMetadata or the Features and Parameters configuration shorthand for Azure App Service settings, registering custom features, parameters and slots with AddAIDeploymentFeature, AddAIDeploymentParameter, AddAIDeploymentSlot and AIDeploymentCapabilityOptions, IAIDeploymentCapabilityService, deployment slots and their resolution chain, AIDeploymentParametersMetadata chat and utility values, IAIDeploymentParameterBinder, UseModelParameters, capability enforcement, the ChatApi Responses routing for reasoning with tools, capability-aware chat UIs, and migrating from AIDeploymentPurpose. Use it when declaring what a model supports, adding a new knob, or fixing stripped tools, missing pickers, or reasoning-effort errors.Other plugins' skills for the same job