Function wrapWithCrossAgentGuardrails

  • 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

    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;
    }