Workflow.execute()
The .execute()
method executes a step with input data and returns the output, allowing you to process data within a workflow.
Usage
const inputSchema = z.object({
inputValue: z.string(),
});
const myStep = createStep({
id: "my-step",
description: "Does something useful",
inputSchema,
outputSchema: z.object({
outputValue: z.string(),
}),
resumeSchema: z.object({
resumeValue: z.string(),
}),
suspendSchema: z.object({
suspendValue: z.string(),
}),
execute: async ({
inputData,
mastra,
getStepResult,
getInitData,
runtimeContext,
}) => {
const otherStepOutput = getStepResult(step2);
const initData = getInitData<typeof inputSchema>(); // typed as the input schema variable (zod schema)
return {
outputValue: `Processed: ${inputData.inputValue}, ${initData.startValue} (runtimeContextValue: ${runtimeContext.get("runtimeContextValue")})`,
};
},
});
Parameters
params:
object
Configuration object for executing the step
z.infer<TInput>
ResumeSchema
(suspendPayload: any) => Promise<void>
object
object
Mastra
Returns
result:
Promise<z.infer<TOutput>>
A promise that resolves to the output of the executed step