Get early access
Copilot Kit Logo

How CopilotKit + Mastra Enable Real-Time Agent Interaction

By Nathan Tarbert
September 18, 2025
How CopilotKit + Mastra Enable Real-Time Agent Interaction

One of the strongest use cases for copilots is co-creation-working side by side with a user to draft, edit, or build something interactively. The other major use case we see talking to developers, and even large teams are, workflow copilots, which is really just a series of co-creation steps chained together.
Together, these two patterns represent the majority of what developers are building with agents today.

That’s why we we built the AG-UI Canvas Template, powered by CopilotKit + Mastra.

We'll get back to the Canvas but let's talk about agentic apps and where you should start.

Mastra, The TypeScript Agent Framework

Mastra is an open-source agent framework with an agentic backend.

It gives developers the building blocks to go from simple LLM calls to full agent workflows. Some of the core capabilities include:

  • Multi-LLM support: Easily switch between providers like OpenAI, Anthropic, Gemini, and local models. Stream responses with type-safe APIs.
  • Agents with tools: Extend agents with typed functions and external API integrations. Agents can reason, then call into your systems to get work done.
  • Workflows: Durable, graph-based workflows with branching, looping, and error handling. Workflows persist state across steps and can even pause for human input.
  • RAG support: Out-of-the-box chunking, embedding, and vector search for retrieval-augmented generation.
  • Observability: Built-in OpenTelemetry tracing for debugging and monitoring agents in production.
  • Evaluations: Automated evals (model-graded, rule-based, statistical) so you can test and trust your agent outputs.

This makes Mastra a strong foundation for reasoning, execution, and orchestration at scale.

But reasoning is only half the story. For agents to feel useful to end users, they need a way to collaborate in real time, inside the product itself.

The UI Layer-Where CopilotKit Comes In

CopilotKit provides the AG-UI (Agent–User Interaction protocol), a standard way to bring backend agents into the front end.

Instead of showing Mastra’s outputs in a static chat bubble, CopilotKit renders them as interactive React components: editable, clickable, and collaborative. Users can guide, correct, and co-create with the agent, all inside the app.

Getting Started in Under 2 Minutes

The fastest way to try Mastra + CopilotKit together is with our starter template.

Just run:‍

‍This scaffolds a full example app- Mastra agents on the backend, CopilotKit + AG-UI on the frontend in less than two minutes.

You’ll have an interactive agent running locally with no extra setup.

Developers can now pair Mastra’s robust agent framework with CopilotKit’s interaction layer to ship agents that feel natural to work with.

Zero to AG-UI Canvas Template

The Canvas template shows this in action: a Mastra agent reasoning in the background while CopilotKit streams updates to the frontend, letting the user interact, adjust, and co-create continuously.

This template alone covers two-thirds of the most common copilot use cases-and it’s the fastest way to see how Mastra + CopilotKit fit together in practice.

Check it out on GitHub:https://go.copilotkit.ai/ag-ui-canvas-mastra

Start building your first interactive Mastra-powered agentic app today!

Want to learn more?

Happy Building!

‍

Top posts

See All
Build Generative UI Agents on Amazon Bedrock AgentCore with AG-UI and CopilotKit
Anmol Baranwal and Nathan TarbertJune 30, 2026
Build Generative UI Agents on Amazon Bedrock AgentCore with AG-UI and CopilotKitAmazon Bedrock AgentCore now runs AG-UI agents natively, so auth, scaling, and session isolation come managed. We build one agent that renders charts inline, syncs a todo canvas both ways, and pauses for human input. Pick Strands or LangGraph at deploy time, and the same frontend runs against either.
Switching to Fable 5: The Tuesday That Cost $22,000
Jordan Ritter June 12, 2026
Switching to Fable 5: The Tuesday That Cost $22,000CopilotKit swapped their coding agents to a new model (fable-5) on a Tuesday, and by Wednesday had run up a ~$22,000 Anthropic bill. No bug or runaway script caused it — five engineers doing normal work triggered it, because the new model interpreted their English-prose behavioral rules ("keep sub-agents small," "converge to zero") far more loosely than older models did. The result was four simultaneous drift modes: bloated sub-agents, runaway review loops, exploding fanout, and oversized single turns. What kept it from being far worse was their "skills" system — small, named instruction packs that agents auto-load to encode team conventions. Their instrumentation caught the runaway in 12 hours instead of 12 days, isolated worktrees contained the blast radius, and the fix lived at the rules layer (swapping vague adjectives for hard numeric budgets and machine-checkable gates) rather than in application code. The takeaway: if you let AI agents do real work, you need a guardrails layer that encodes desired behavior separately from the agents — small, composable, and faster to change than a model. Because models will change, and the team with a rules layer pays $22K and writes a blog post; the team without one pays more and writes a press release.
Build AI Agents That Live Inside Your App — CopilotKit Explained
Nathan Tarbert June 12, 2026
Build AI Agents That Live Inside Your App — CopilotKit ExplainedCopilotKit is a complete set of building blocks for developers and teams who want to add agents to their app and assemble, debug, and ship the interface layer between their agents and users. It's also framework-agnostic and supports any LLM and every popular agent framework. There are two options for chat. Pre-built components, if you want something already built or Headless UI, which allows anyone to build custom agent interfaces.
Are you ready?

Stay in the know

Subscribe to our blog and get updates on CopilotKit in your inbox.