Overview
The MastraAgent wraps a Mastra Agent (from @mastra/core) and streams AG-UI compatible events for @ag-kit/server. Provide a runnableFactory that constructs and returns a Mastra Agent when invoked. Key capabilities:- Run any Mastra Agent created with @mastra/core
- Stream BaseEvent types (text chunks, tool calls/results)
- Forward client-provided tools from agent.run(…) to Mastra
Installation
Exports
All exports are available from@ag-kit/adapter-mastra:
Exports:
- MastraAgent – Main agent class for Mastra integration
Quick start
Server integration
API
class MastraAgent
Unique identifier for the agent.
Human-readable description of the agent.
Factory that returns a Mastra Agent instance. It will be invoked at run time to create the runnable.
Methods
run()
- input – RunAgentInput containing messages, runId, threadId, tools, etc.
- returns –
Observable<BaseEvent>
Note: Event types and semantics match the LangGraph Agent reference.
Examples
- Agentic chat (TS): project path typescript-sdk/packages/examples/agents/mastra/agentic-chat
- Human-in-the-loop workflow (TS): project path typescript-sdk/packages/examples/agents/mastra/human-in-the-loop
See also
- Core agent reference: /reference/agents/agents
- Server integration: /reference/server/overview