Interface AgencyStreamResult

Public stream result returned by agency().stream(...).

This exposes both low-latency raw streaming and finalized post-processing results so callers can choose the right trade-off for their UI or runtime.

Prefer:

  • textStream for raw token-by-token UX
  • fullStream for structured lifecycle events
  • text or finalTextStream for the finalized approved answer

textStream may differ from the finalized answer when output guardrails or beforeReturn HITL rewrite the result. finalTextStream and text always reflect the finalized post-processing output.

Example

const stream = team.stream('Summarize HTTP/3 rollout risks.');

for await (const chunk of stream.textStream) {
process.stdout.write(chunk); // raw live output
}

for await (const approved of stream.finalTextStream) {
console.log('Approved answer:', approved);
}

console.log(await stream.agentCalls);
console.log(await stream.text);
interface AgencyStreamResult {
    textStream: AsyncIterable<string, any, any>;
    fullStream: AsyncIterable<AgencyStreamPart, any, any>;
    text: Promise<string>;
    usage: Promise<{
        promptTokens: number;
        completionTokens: number;
        totalTokens: number;
        costUSD?: number;
    }>;
    agentCalls: Promise<AgentCallRecord[]>;
    parsed: Promise<unknown>;
    finalTextStream: AsyncIterable<string, any, any>;
}

Properties

textStream: AsyncIterable<string, any, any>

Raw live text chunks from the underlying strategy.

fullStream: AsyncIterable<AgencyStreamPart, any, any>

Structured live + finalized event stream.

This includes raw text/tool/lifecycle events and also the finalized final-output event after post-processing completes.

text: Promise<string>

Finalized scalar text after guardrails, HITL, and parsing hooks.

usage: Promise<{
    promptTokens: number;
    completionTokens: number;
    totalTokens: number;
    costUSD?: number;
}>

Final aggregate usage for the streamed run.

Type declaration

  • promptTokens: number
  • completionTokens: number
  • totalTokens: number
  • Optional costUSD?: number
agentCalls: Promise<AgentCallRecord[]>

Final per-agent execution ledger for the streamed run.

parsed: Promise<unknown>

Final structured payload; resolves to undefined when structured output was not configured for the run.

finalTextStream: AsyncIterable<string, any, any>

Finalized approved-only text stream.

Unlike textStream, this yields only the post-guardrail/post-HITL answer. For most runs it emits a single finalized chunk.