Skip to main content

Function: wrapWithCrossAgentGuardrails()

wrapWithCrossAgentGuardrails(guardrails, crossAgentContext, guardrailContext, stream, options): AsyncGenerator<AgentOSResponse, void, undefined>

Defined in: packages/agentos/src/core/guardrails/crossAgentGuardrailDispatcher.ts:227

Wrap an agent's output stream with cross-agent guardrail supervision.

Creates an async generator that evaluates each chunk through applicable cross-agent guardrails before yielding. If any guardrail returns BLOCK (and has canInterruptOthers: true), the stream is terminated.

Parameters

guardrails

ICrossAgentGuardrailService[]

Cross-agent guardrails to apply

crossAgentContext

CrossAgentGuardrailContext

Source/observer agent context

guardrailContext

GuardrailContext

Standard guardrail context

stream

AsyncGenerator<AgentOSResponse, void, undefined>

Source agent's output stream

options

GuardrailOutputOptions

Stream options

Returns

AsyncGenerator<AgentOSResponse, void, undefined>

Supervised stream with cross-agent guardrail filtering

Example

// Supervisor monitors worker agent
const supervisedStream = wrapWithCrossAgentGuardrails(
[qualityGate, policyEnforcer],
{
sourceAgentId: 'worker-analyst',
observerAgentId: 'supervisor',
agencyId: 'research-agency'
},
guardrailContext,
workerStream,
{ streamId: 'stream-xyz' }
);

for await (const chunk of supervisedStream) {
// Chunk has been approved/modified by cross-agent guardrails
yield chunk;
}