Class: ParallelGuardrailDispatcher
Defined in: packages/agentos/src/safety/guardrails/ParallelGuardrailDispatcher.ts:385
Stateless two-phase parallel guardrail dispatcher.
All methods are static — no instantiation needed. The class exists purely as a namespace to keep the two public entry points grouped.
Constructors
Constructor
new ParallelGuardrailDispatcher():
ParallelGuardrailDispatcher
Returns
ParallelGuardrailDispatcher
Methods
evaluateInput()
staticevaluateInput(services,input,context):Promise<GuardrailInputOutcome>
Defined in: packages/agentos/src/safety/guardrails/ParallelGuardrailDispatcher.ts:414
Evaluate user input through registered guardrails using two-phase execution.
Phase 1 (Sequential — sanitizers):
Guardrails with config.canSanitize === true or config.sequential === true
run one-at-a-time in registration order. Each sees (and, with canSanitize,
may modify) the cumulative sanitized input. A BLOCK result short-circuits
immediately — Phase 2 never runs.
Phase 2 (Parallel — classifiers):
All remaining guardrails run concurrently via Promise.allSettled on
the text produced by Phase 1. A Phase 2 SANITIZE is downgraded to FLAG.
Aggregation: worst-wins (BLOCK > FLAG > ALLOW). The singular
evaluation field is set to the first BLOCK without a hold, else the
first hold, else the worst-severity evaluation, else the last evaluation
by registration order. outcome says what the evaluations amount to: a
refusal outranks a hold, and a hold outranks the rest.
Parameters
services
Array of guardrail services (already normalized)
input
User input to evaluate
context
Conversational context for policy decisions
Returns
Promise<GuardrailInputOutcome>
Outcome with sanitized input and all evaluations in registration order
evaluateToolCall()
staticevaluateToolCall(services,context,chunk,ragSources?,pickBlock?):Promise<GuardrailToolCallVerdict>
Defined in: packages/agentos/src/safety/guardrails/ParallelGuardrailDispatcher.ts:574
Evaluate one TOOL_CALL_REQUEST chunk with the guardrails that evaluate
tool calls (config.evaluateToolCalls), as wrapOutput evaluates
the tool-call chunks of a stream: the guards with config.sequential
first, one at a time, and a BLOCK among them ends the evaluation; the rest
in parallel, a SANITIZE applied as a BLOCK, the first refusal in
registration order the verdict, else the first hold. Services without the
flag are not called.
Parameters
services
Array of guardrail services (already normalized)
context
Conversational context for policy decisions
chunk
The tool-call chunk to evaluate
ragSources?
RAG sources to pass to the guardrails, when the caller has them
pickBlock?
(evaluations) => GuardrailEvaluationResult | undefined
Picks which evaluation blocks the call, as GuardrailOutputOptions.pickBlock does for a reply. Default: the first BLOCK without a hold, else the first hold.
Returns
Promise<GuardrailToolCallVerdict>
The blocking evaluation, or every evaluation of a chunk the guardrails pass
wrapOutput()
staticwrapOutput(services,context,stream,options):AsyncGenerator<AgentOSResponse,void,undefined>
Defined in: packages/agentos/src/safety/guardrails/ParallelGuardrailDispatcher.ts:625
Wrap a response stream with two-phase guardrail filtering.
Partitions services into four groups (once, up front). "Phase 1" is a
guard with canSanitize or sequential; a SANITIZE from one without
canSanitize is downgraded to FLAG.
- Streaming sanitizers (phase 1 and
evaluateStreamingChunks) - Streaming parallel classifiers (
evaluateStreamingChunks, not phase 1) - Final sanitizers (every phase 1 guard)
- Final parallel classifiers (the rest with
evaluateOutput)
For each TEXT_DELTA chunk: Phase 1 runs streaming sanitizers sequentially (with per-service rate limiting), then Phase 2 runs streaming classifiers in parallel.
For each isFinal chunk: Phase 1 runs final sanitizers sequentially, then
Phase 2 runs final classifiers in parallel. All services with
evaluateOutput participate in final evaluation.
For each non-final TOOL_CALL_REQUEST chunk: the services whose config sets
evaluateToolCalls run in parallel on the chunk as the stream carries it.
A SANITIZE is applied as a BLOCK, since a tool call cannot be rewritten; a
BLOCK ends the stream with the verdict in place of the chunk. Services
without the flag never receive a tool-call chunk. A block that withholds
an actionable call (executionMode: 'external'), on its chunk or, in hold
mode, on the text before it, names the call ids in the verdict's
toolCallIds.
A BLOCK in either phase terminates the stream immediately with an error
chunk, or with a final response holding the guard's replacementText.
Parameters
services
Array of guardrail services (already normalized)
context
Conversational context for policy decisions
stream
AsyncGenerator<AgentOSResponse, void, undefined>
Source response stream to filter
options
Stream options and input evaluations to embed
Returns
AsyncGenerator<AgentOSResponse, void, undefined>
Wrapped async generator with guardrail filtering applied