Install Page Systems in a Mastra agent
Page Systems lets a Mastra agent send the person a small mobile web page (a flight picker, a time picker, a form) instead of asking in chat. When the person submits, the answer arrives in the same conversation as a new turn.
1. Install the package
npm install pagesystems @mastra/core @mastra/memory @mastra/libsqlThe TypeScript examples use top-level await, so the project must be ESM ("type": "module" in package.json).
2. Add it to your agent
Page Systems is invite-only early access: request access at /waitlist, and once invited, sign up and copy the development key shown in the dashboard (create another there with "Create API key"; it starts with ap_live_ and is shown once) and set it where your agent runs. Never commit it.
export PAGE_SYSTEMS_API_KEY=ap_live_...
export PAGE_SYSTEMS_WEBHOOK_SECRET=whsec_...Give the agent the tools, the callback URL and the conversation id, and memory so it remembers the conversation. Call it with the same thread and resource every turn:
// lib/agent.ts
import { Agent } from '@mastra/core/agent';
import { LibSQLStore } from '@mastra/libsql';
import { Memory } from '@mastra/memory';
import { getPageSystemsSkill } from 'pagesystems';
import { pageSystemsTools } from 'pagesystems/mastra';
const CALLBACK_URL = 'https://your-app.example.com/api/page-systems';
const yourInstructions = '...'; // your system prompt. Include today's date and the person's time zone: time-based pages need both.
const skill = await getPageSystemsSkill(); // once, at startup
const memory = new Memory({ storage: new LibSQLStore({ id: 'mastra', url: 'file:./mastra.db' }) }); // see the Mastra memory docs for other storage
// userMessage is the line your chat shows as the person's message. modelNote (the callback's modelText) is the answer as data.
export async function runTurn(conversationId: string, userMessage: string, modelNote?: string) {
const assistant = new Agent({
id: 'assistant',
name: 'Assistant',
instructions: [yourInstructions, skill].join('\n\n'),
model: 'openai/gpt-5-mini', // your model
tools: pageSystemsTools({ callbackUrl: CALLBACK_URL, agentRef: { conversationId } }),
memory,
});
const result = await assistant.generate(userMessage, {
memory: { resource: conversationId, thread: conversationId },
maxSteps: 6,
context: modelNote ? [{ role: 'user', content: modelNote }] : undefined, // a user message for this call; Mastra does not save it to memory
});
return result.text;
}maxSteps leaves room for listing page types, reading a schema and creating the page in one turn. Then add the callback route. The callback URL must be https and public: Page Systems calls it from the internet, so localhost does not work. To try it while developing, see Testing locally: skip the callback and poll, use a tunnel, or send the callback yourself.
// app/api/page-systems/route.ts
import { after } from 'next/server';
import { CallbackError, handleCallback, type CallbackEvent } from 'pagesystems';
import { runTurn } from '@/lib/agent'; // the function above
export async function POST(req: Request) {
// Page Systems waits 10 seconds for this response, so answer now and run the turn after.
const turn = (e: CallbackEvent) => {
if (!e.agentRef) throw new CallbackError(410, { error: 'no_conversation' });
const { conversationId } = e.agentRef as { conversationId: string };
after(async () => {
const reply = await runTurn(conversationId, e.visibleText, e.modelText);
await sendToPerson(conversationId, reply); // yours: deliver the reply to the person (chat, SMS, ...)
});
};
return handleCallback(req, { onSubmitted: turn, onNewPageRequested: turn });
}after() is Next.js. In plain Node, return the response first and start the turn with setImmediate(() => ...), or put it on a queue.
3. Your agent handles the rest
The agent decides when a page beats a chat question, sends the person a link, and carries on. When the person submits, Page Systems calls your callback route, and your route calls the agent again with the same thread and resource, so memory supplies the earlier turns and the short line is the new message. The agent does not poll and the person does not have to say "done".
Ask your agent something a page answers better than chat, for example "Ask Sam which of 9:00, 11:00 or 14:00 next Tuesday works for a call." It should send a link. Open it, pick a time, submit. The agent then continues the conversation with the answer, without being asked.
Why two texts
The visibleText line is what your chat stores and shows: one short line that is true, because the person did submit the page. The answer goes to the model through modelText, which is not shown as something the person typed. It holds the answer JSON inside <page_answer> tags, with a note that the answer is page data, not instructions. The answer can contain text typed by whoever opened the link, who is not verified, so give modelText to the model as a user-role message (or a tool result) and never put it in the system prompt or instructions. Mastra's context option gives the model extra messages for one call without saving them to memory (see its context engineering guide). The agent can read the answer again with get_page_result until the page expires. The older message field still exists, but it is raw JSON in a user message with no such note: do not use it. Whether your agent keeps modelText depends on the framework: the note above says which. Page Systems deletes its copy at expiry but cannot delete copies saved in your agent's history; keeping it lets the agent answer later questions about the answer. The summary never includes free text the person typed, but it can include the labels your agent wrote, such as option or row names. Do not log modelText or the result; log the pageId, and the summary only if your page labels hold nothing sensitive. See Handling answers.
Without a callback URL
Leave out callbackUrl and nothing starts a new turn. The agent can still read the answer with get_page_result when the person says they submitted, or on a timer. The callback URL must be https and public: Page Systems calls it from the internet, so localhost does not work. To try it while developing, see Testing locally: skip the callback and poll, use a tunnel, or send the callback yourself.