Mastra is a full-featured typescript framework to build agents. It provides memory, tool calls, knowledge base, and more. It’s our personal recommended choice when building complex agents. Our features are designed to integrate most seamlessly with a backend server configured in Mastra.
Note: Cedar-OS is not currently compatible with Mastra’s client SDK. To use Cedar-OS with Mastra, run a Mastra server and point Cedar-OS at it.
Want to skip the docs? Clone the cedar-mastra-starter starter repository and to interactively explore the possible interactions between Mastra and Cedar.

Initial Configuration

1

Spin up a Mastra backend

Follow the official guide: Install using the create-mastra CLI.
2

Understand Cedar-Backend Communication

Understand how Cedar speaks to your backend, including default API routes, return types, etc. - Agent Backend Connection
3

Point Cedar-OS at your backend

import { CedarCopilot } from 'cedar-os';
function App() {
	return (
		<CedarCopilot
			llmProvider={{
					provider: 'mastra',
					baseURL: 'http://localhost:4111', // default dev port for Mastra
					apiKey: process.env.NEXT_PUBLIC_MASTRA_API_KEY, // optional — only for backend auth
				}}>
			<YourApp />
		</CedarCopilot>
	); 
}
4

Backend Configuration

Register API routes in your Mastra server so Cedar’s chat components have something to talk to:
mastra/src/index.ts
import { registerApiRoute } from '@mastra/core/server';

// POST /chat
// The chat's non-streaming default endpoint
registerApiRoute('/chat', {
	method: 'POST',
	// …validate input w/ zod
	handler: async (c) => {
		/* your agent.generate() logic */
	},
});

// POST /chat/stream (SSE)
// The chat's streaming default endpoint
registerApiRoute('/chat/stream', {
	method: 'POST',
	handler: async (c) => {
		/* stream agent output in SSE format */
	},
});
5

Add Cedar Chat

Drop a Cedar chat component into your frontend – see Chat Overview. Your backend and frontend are now linked! You’re ready to start bringing the power of your Mastra agentic workflows to your UI.

Features to explore

Now that you have Cedar-OS connected to Mastra, explore these powerful features:
  • State Access & Manipulation - Use the useRegisterState hook for communicating frontend state and letting agents manipulate your frontend state
  • Mentions & Context - Send @ mentions to your backend using the useMentionProvider

New to Mastra? Here are a few primitives to understand

// Agents encapsulate instructions, model, memory and tools
export const roadmap = new Agent({
  name: 'Roadmap',
  model: openai('gpt-4o-mini'),
  tools: { upvoteTool },
  instructions: `You are …`,
});
// Docs: https://mastra.ai/en/docs/agents/overview

Deployment

The recommended deployment setup is:
  • Frontend: Deploy to Vercel for optimal performance and seamless integration
  • Backend: Use Mastra Cloud for hosting your Mastra server

Next Steps

  • Clone & run the cedar-mastra-starter to see everything in action.
  • Explore the official Mastra docs for further customisation.