creamy-megabyte-39753
09/26/2025, 12:40 PMexport const weatherTool = llm.tool({
description: `Use this tool for detailed weather forecasts and comprehensive activity planning.
...
}),
execute: async ({ location, days = 1, activityType = 'both' }) => {
try {
const weatherAgent = getMastraAgent('weatherAgent');
// Create a detailed prompt for comprehensive planning
const prompt = `For ${location}, provide a ${days}-day weather forecast with ${
activityType === 'both' ? 'both indoor and outdoor' : activityType
} activity suggestions. Please structure the response clearly with weather details and specific activity recommendations for each day.`;
const response = await weatherAgent.streamVNext({ // weatherAgent.streamVNext returns a stream of data
messages: [
{
role: 'user' as const,
content: prompt,
},
]
});
let fullResponse = '';
response.processDataStream({
onChunk: async chunk => {
if (chunk.type !== 'text-delta') {
return;
}
const text = chunk.payload?.text;
if (typeof text !== 'string' || text.length === 0) {
return;
}
logger.info('[Mastra Weather Stream] Streaming response', { text });
fullResponse += text;
},
});
if (!fullResponse) {
throw new Error('No response received from weather planning service');
}
return fullResponse;
} catch (error) {
return handleMastraError(error, {
tool: 'weatherTool',
service: 'weather planning service',
action: `generate a ${days}-day forecast for ${location}`,
location,
days,
activityType,
});
}
},
});
How do I return streams from a tool call? The example above, the tool returns an empty string because it doesn't bubble the stream up