Skip to main content
Receive messages through Flow, run your Mastra agent and deliver its answer as chat bubbles. Keep the agent’s existing tools and workflows.
TypeScript

How it fits

  • reply() reads the stream’s textStream, keeps typing on and sends a bubble at each paragraph break.
  • Mastra memory: use the Flow conversation.id as the thread ID and conversation.contact (the contact’s ID) as the resource ID, so each person keeps their own history.
  • In a Mastra server, receive Flow webhooks on a custom route and call the same code; verify signatures with flow.webhooks.constructEvent(rawBody, signatureHeader, secret), which returns the typed event with event.conversation ready to reply on. See Events and webhooks.
  • To see each turn’s model and tool calls and get every reply graded, send this agent’s traces to Flow Observe: Traces from agent frameworks.

Full example

examples/mastra on GitHub.