Skip to content

API overview ​

Prefer the guide for when-to-use context. This page is a quick reference.

Subpaths ​

SubpathModule
mastra-effectBarrel — common imports
mastra-effect/AgentAgent.of
mastra-effect/ToolMastraTool.make
mastra-effect/ToolkitToolkit.make, toMastra
mastra-effect/ToolUIHITL schemas, stream cards
mastra-effect/MemoryMastraMemory
mastra-effect/StreamMastra stream helpers
mastra-effect/SuspendSuspend.execute
mastra-effect/ObservabilitySpan stitching
mastra-effect/ErrorMastraError, reasons
mastra-effect/assistant-uiClientToolkit (React)

Tools (mastra-effect/Tool, mastra-effect/Toolkit) ​

ExportWhen to use
MastraTool.makeDefine a tool with Effect Schema
tool.annotate(ToolUI.Schema, s)Client registration — marks client-fulfilled tool for ClientToolkit
MastraTool.getToolUISchemaRead Tool UI schema annotation from a tool
Toolkit.make / Toolkit.mergeBuild typed toolkits
toolkit.of(handlers)Typed identity for handler maps — helps inference at call sites
toolkit.schemasTool UI schemas from annotated tools (client registration index)
toolkit.toMastraToolsMastra ToolsInput for agent loop
ToolHandlersServer handler registry context
HandlerRequirementsFrom<H>Union of handler R — provide at execute/stream, not on layer

Agent (mastra-effect/Agent) ​

ExportWhen to use
Agent.of(id, { …, toolkit, handlers })Preferred wiring — typed ops; handler R on method Effects
Context.Service + Layer.effectPreferred agent — service class + explicit Live layer
yield* ServiceCall agent methods; method Effects carry handler R

Agent.of config accepts Mastra inputProcessors, outputProcessors, errorProcessors, requestContext, and dynamic instruction fields. Per-call overrides via agent.stream(msgs, { inputProcessors }) too. See Agents guide.

Memory (mastra-effect/Memory) ​

ExportWhen to use
MastraMemory.layer(config?)Construct @mastra/memory
MastraMemory.layer(instance)Wrap an existing Mastra memory instance
MastraMemory.recall, getThreadById, listThreads, saveThread, saveMessages, createThread, deleteThread, settledEffect wrappers

Stream (mastra-effect/Stream) ​

ExportWhen to use
fromMastraOutputMastraModelOutput.fullStream → Stream
fromReadableStream / fromAsyncIterableAdapters

ToolUI (mastra-effect/ToolUI) ​

ExportWhen to use
ToolUI.makeInert schema (stateSchema, optional answerSchema, optional equals)
ToolUI.equalsBy / ToolUI.answersEqualOptional sugar for answer equality; default is Object.is
ToolUI.getSchemaRead Tool UI schema annotation from a tool (alias)
ToolUI.present(schema, args, { transient? })Stream card create (no answerSchema)
ToolUI.update(schema, id, args, { transient? })Stream card update
ToolUI.toSuspendPayload / encodeResumeAnswerWire encode for client rendering / resume
ToolUI.fromSuspendArgs / fromToolCallSuspendParse suspend payloads (advanced)
ToolUI.isStreamChunk / fromStreamChunkParse data-mastra-effect-block chunks
ToolUI.RuntimeService required by Tool UI ops (auto-provided)
ToolUI.ErrorEncode/decode or missing Mastra context failures

Suspend (mastra-effect/Suspend) ​

ExportWhen to use
Suspend.execute(schema, args)HITL suspend — requires answerSchema on the schema
Suspend.isToolCallSuspendPartParse tool-call-suspend chunks (advanced)

Observability (mastra-effect/Observability) ​

See the observability guide.

ExportWhen to use
MastraObservability.layer()Opt in to span stitching at tool FFI
ObservabilityBridgeShape of the MastraObservability service value
enterMastraSpanContext / runEffectInMastraSpanPromise FFI span stitching
currentSpanFromToolContextRead active span from Mastra tool context

Errors (mastra-effect/Error) ​

See the errors guide for Match / catchTag examples.

ExportWhen to use
fromUnknownBridge native MastraError / unknown failures at boundaries
MastraErrorTop-level Effect error; narrow reason with Match.tag
reasonsById / mastraErrorsByIdLookup generated reason class by Mastra id
ErrorDomain, ErrorCategoryRe-exported from @mastra/core/error
ClientToolRequiredErrorServer hit an annotated tool without client fulfillment
UnknownMastraErrorFallback reason when no Mastra id matches

Assistant UI (mastra-effect/assistant-ui) ​

ExportWhen to use
ClientToolkit.of(toolkit, handlers)Handlers for annotated tools + stream views
clientToolkit.toAssistantUiTools()Assistant UI human tools from annotated tool views
clientToolkit.renderChunk(chunk, { resume })Demux suspend / stream-card / ignore
clientToolkit.renderToolUIRender suspend payloads directly
clientToolkit.renderStreamToolUIRender data-mastra-effect-block stream chunks
clientToolkit.encodeResumeSchema-encode resume answers
clientToolIds / serverToolIdsList tool ids by kind

Pass clientToolkit.toAssistantUiTools() to Assistant UI's Tools({ toolkit }) helper.