Problem
When using agent.stream() with structured output, there's no way to get the final parsed response from the stream.
Options
Option 1: Yield as final event
for await (const event of agent.stream(prompt, options)) {
if (event.kind === "tool-call") console.log(event.toolId);
if (event.kind === "text-delta") process.stdout.write(event.text);
if (event.kind === "response") {
const result = event.response;
// { needs_updating: boolean, reason: string }
}
}
Option 2: Property on stream object
const stream = agent.stream(prompt, options);
for await (const event of stream) {
if (event.kind === "tool-call") console.log(event.toolId);
if (event.kind === "text-delta") process.stdout.write(event.text);
}
const result = await stream.response;
// { needs_updating: boolean, reason: string }
Type signature:
interface AgentStreamResult<TResult> extends AsyncIterable<ThreadStreamEvent> {
response: Promise<TResult>;
}
Recommendation
Option 2 - the response isn't really a stream "event", it's the final output. Keeping it separate makes types cleaner.
Problem
When using
agent.stream()with structured output, there's no way to get the final parsed response from the stream.Options
Option 1: Yield as final event
Option 2: Property on stream object
Type signature:
Recommendation
Option 2 - the response isn't really a stream "event", it's the final output. Keeping it separate makes types cleaner.