Agent Scoping¶
You can have several agents in one application. By default, every registered component (policy, gate, validator, ...) runs for all agents. With scoping, you can say: "this component runs only for this agent".
Two Ways to Register¶
// GLOBAL — runs on ALL agents (this is the default)
services.AddAgentQualityGate<JsonQualityGate>();
services.AddAgentResultValidator<MyValidator>();
// SCOPED — runs only on agents that match the condition
services.AddAgentQualityGate<UrlStructureGate>(
appliesTo: ctx => ctx.AgentName == "UrlResearchAgent");
services.AddAgentInputValidator<PricingFormatValidator>(
appliesTo: ctx => ctx.AgentName == "PricingAgent");
services.AddAgentResultValidator<DomainValidator>(
appliesTo: ctx => ctx.AgentName == "DataAgent");
The appliesTo argument is a small function that returns true or
false. It receives the IAgentContext, so you can match on any context
property — not only the agent name.
Selecting the Agent¶
The request decides which agent runs, through AgentName. The scoped
components compare their condition against this name:
var request = new AgentRequest(
Goal: "Find pricing URL",
AgentName: "UrlResearchAgent", // scoped components match against this
AllowedToolNames: ["search_web"]);
Input Validation¶
Input validation is its own step in the pipeline. It checks the input before any work starts:
services.AddAgentInputValidator<ValidUrlInputValidator>(
appliesTo: ctx => ctx.AgentName == "UrlResearchAgent");
Input validators run after the policies and before the planning. Each
validator answers with an InputValidationResult that has two fields:
IsValid and Error. If one fails, the run stops immediately. The run
then returns an unsuccessful AgentResult that contains the validation
error — it does not return the InputValidationResult itself.
Implementation Note¶
Scoping works with small wrapper classes (FilteredPolicy, FilteredGate,
and so on) in Runtime/Filtering. The runtime itself contains no scoping
rules.