0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/workflows
History 2026-11-12 21:12:29 +00:00
..
_test-utils fix(core): pass omitted and null input to evented inputSchema validation (#29542) 2026-11-10 18:58:43 -05:00
inngest chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
temporal chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
oxlint.config.ts chore: migrate linting to oxlint (#20173) 2026-07-25 01:04:02 +02:00
README.md fix(docs): Fix Inngest example (#5500) 2025-07-01 09:43:13 -07:00

Inngest Workflow Engine

Run Mastra workflows with Inngest.

Workflow and step execution functionality is exposed via serve from @mastra/inngest. This is a wrapper that detects all Mastra workflows created to run with Inngest and registers them to the Inngest server.

Steps and workflows are created using the createStep and createWorkflow functions initialized with init() from @mastra/inngest. This makes sure that all the steps are ready and able to connect with the Inngets runtime, publish events for watching, etc.

The Inngest runtime is horizontally scalable, with watching and eventing working through the @inngest/realtime package.

Usage

Running inngest dev server

docker run --rm -p 8288:8288 \
  inngest/inngest \
  inngest dev -u http://host.docker.internal:4111/inngest/api

Example

import { init, serve as inngestServe } from '@mastra/inngest';
import { PinoLogger } from '@mastra/loggers';
import { Inngest } from 'inngest';
import { z } from 'zod';

const inngest = new Inngest({
  id: 'mastra',
  baseUrl: `http://localhost:8288`, // if using local dev server
});

const { createWorkflow, createStep } = init(inngest);

const incrementStep = createStep({
  id: 'increment',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    return { value: inputData.value + 1 };
  },
});

const sideEffectStep = createStep({
  id: 'side-effect',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    console.log('log', inputData.value);
    return { value: inputData.value };
  },
});

const finalStep = createStep({
  id: 'final',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    return { value: inputData.value };
  },
});

const incrementWorkflow = createWorkflow({
  id: 'increment-workflow',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
})
  .dountil(
    createWorkflow({
      id: 'increment-subworkflow',
      inputSchema: z.object({
        value: z.number(),
      }),
      outputSchema: z.object({
        value: z.number(),
      }),
      steps: [incrementStep, sideEffectStep],
    })
      .then(incrementStep)
      .then(sideEffectStep)
      .commit(),
    async ({ inputData }) => inputData.value >= 10,
  )
  .then(finalStep)
  .commit();

export const mastra = new Mastra({
  vnext_workflows: {
    incrementWorkflow,
  },
  server: {
    host: '0.0.0.0',
    apiRoutes: [
      {
        path: '/inngest/api', // this needs to match the path in inngest dev server (or production) config
        method: 'ALL',
        createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
      },
    ],
  },
  logger: new PinoLogger({
    name: 'Mastra',
    level: 'info',
  }),
});