I am trying to stream a response, so it can be delivered in chuncks to the user. I want to stream the ‘answer‘ part from the structured output. Is this possible? I can’t find anything in the documentations about this.
private readonly agent = createAgent({
model: new ChatGoogleGenerativeAI({
model: 'gemini-2.5-flash-lite',
streaming: true,
}),
tools: [retrieveDocuments],
responseFormat: z.object({
answer: z.string().describe('A markdown repsonse to the user query.'),
resources: z.array(z.object({ name: z.string(), url: z.string() })),
}),
contextSchema: z.object({ organisationId: z.number() }),
});
const messages = [
new SystemMessage(systemPrompt.replace('[company]', organisation.name)),
new HumanMessage(query),
];
for await (const [token] of await this.agent.stream(
{ messages },
{
streamMode: 'messages',
context: { organisationId: session.organisationId },
},
)) {
}