mastra-ai/mastra · error

Weather agent not found

Error message

Weather agent not found

What it means

The default workflow step fetches the Mastra instance from context and calls mastra.getAgent('weatherAgent'), throwing 'Weather agent not found' when the lookup returns undefined. This means the Mastra instance wiring into the workflow does not contain a registered agent with id 'weatherAgent'.

Source

Thrown at packages/agent-builder/src/defaults.ts:346

const planActivities = createStep({
  id: 'plan-activities',
  description: 'Suggests activities based on weather conditions',
  inputSchema: forecastSchema,
  outputSchema: z.object({
    activities: z.string(),
  }),
  execute: async (inputData, context) => {
    const mastra = context?.mastra;
    const forecast = inputData;

    if (!forecast) {
      throw new Error('Forecast data not found');
    }

    const agent = mastra?.getAgent('weatherAgent');
    if (!agent) {
      throw new Error('Weather agent not found');
    }

    const prompt = \${weatherWorkflowPrompt}

    const response = await agent.stream([
      {
        role: 'user',
        content: prompt,
      },
    ]);

    let activitiesText = '';

    for await (const chunk of response.textStream) {
      process.stdout.write(chunk);
      activitiesText += chunk;
    }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Register the default weather agent with id 'weatherAgent' in the Mastra instance used to run the workflow (new Mastra({ agents: { weatherAgent } }))
  2. Verify context?.mastra is defined at execute time — if undefined, the getAgent chain silently yields undefined
  3. Keep the agent id in sync if you renamed it, or update the hardcoded 'weatherAgent' string in the step
  4. Run the workflow through the fully-assembled default Mastra (as built in defaults.ts/mastra config) rather than a partial instance

Example fix

// before
const mastra = new Mastra({ workflows: { weatherWorkflow } }); // agent missing

// after
const mastra = new Mastra({
  agents: { weatherAgent },
  workflows: { weatherWorkflow },
});
Defensive patterns

Strategy: validation

Validate before calling

const mastra = new Mastra({ agents: { weatherAgent }, workflows: { weatherWorkflow } });
if (!mastra.getAgent('weatherAgent')) {
  throw new Error('weatherAgent must be registered before running weatherWorkflow');
}

Prevention

When it happens

Trigger: Executing the forecast-reporting step inside a Mastra instance whose agents map has no 'weatherAgent' registration — e.g. the agent was removed/renamed in defaults.ts, the step runs with context.mastra undefined or a bare Mastra created without registering the default agent.

Common situations: Custom Mastra instantiation that includes the default workflow but not the default agent; renaming the agent id while the workflow hardcodes 'weatherAgent'; DI/config in mastra/ omitting the defaults agent; tests constructing a partial Mastra.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a656a58563d47967. Report an issue: GitHub.