Workflow.tool()
The .tool() method adds a tool as a declarative step. The tool's own input and output schemas apply, so the previous step's output must satisfy the tool's input schema. Use .map() to transform the data if they don't match.
Unlike wrapping a tool with createStep(), .tool() records a declarative entry in the workflow graph. This makes the workflow portable: the same graph can be serialized and persisted as a stored workflow.
Usage exampleDirect link to Usage example
workflow.tool(testTool).commit();
ParametersDirect link to Parameters
toolOrId:
options?:
stepOptions?:
ReturnsDirect link to Returns
workflow:
Referencing a tool by IDDirect link to Referencing a tool by ID
Pass a string to reference a registered tool without importing it. The tool must be registered on the Mastra instance when the workflow runs:
workflow.tool("lookup-customer", { retries: 2 }).commit();
Persisting tool stepsDirect link to Persisting tool steps
Workflows built with .tool() serialize to the same declarative entries that stored workflows use. Only retries and metadata round-trip through storage. A function-valued scorers option throws an error when the workflow is stored.