Skip to content
DocsDashboard

Install Page Systems in a Claude Agent SDK agent

Page Systems lets a Claude Agent SDK 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.

If the model keeps failing with invalid_spec: some models, OpenAI GPT models among them, call create_page with only page.type and get invalid_spec back. If yours does, use the MCP server instead: its create_page tool carries the full schema of every page type. Switching to MCP gives up the automatic new turn: the agent reads the answer only when asked, with get_page_result.

1. Install the package

npm install pagesystems @anthropic-ai/claude-agent-sdk

The 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_...

pageSystemsServer is an in-process MCP server with the Page Systems tools. Pass it in mcpServers under the name pages (so the tools are mcp__pages__*), with the callback URL and an agentRef: any small JSON object that names your conversation. It comes back unchanged in the callback event. The SDK gives every conversation a session id; keep it next to your conversation id and pass it as resume on the next turn.

Isolate the agent from your machine. By default the SDK loads the Claude settings and connectors of the user it runs as, so a server-side agent can try your local tools (a Google Calendar connector, for example) and ask clarifying questions instead of creating a page. The examples set settingSources: [] and strictMcpConfig: true so the agent sees only the Page Systems tools.

TypeScript

// lib/agent.ts
import { query } from '@anthropic-ai/claude-agent-sdk';
import { getPageSystemsSkill } from 'pagesystems';
import { pageSystemsServer } from 'pagesystems/claude-agent-sdk';

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 sessionIds = new Map<string, string>(); // conversation id -> SDK session id; use a database in production

// 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) {
  let reply = '';
  for await (const message of query({
    // The note rides in the prompt (a user message), never in the system prompt. Show userMessage to the person.
    prompt: [userMessage, modelNote].filter(Boolean).join('\n\n'),
    options: {
      resume: sessionIds.get(conversationId),
      systemPrompt: [yourInstructions, skill].join('\n\n'),
      mcpServers: { pages: pageSystemsServer({ callbackUrl: CALLBACK_URL, agentRef: { conversationId } }) },
      allowedTools: ['mcp__pages__*'],
      settingSources: [], // ignore local Claude settings
      strictMcpConfig: true, // use only the MCP servers above
    },
  })) {
    if (message.type === 'result') {
      sessionIds.set(conversationId, message.session_id);
      if (message.subtype === 'success') reply = message.result;
    }
  }
  return reply;
}
// 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 query again with resume set to that conversation's session id and the short line as the prompt. 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. The Claude Agent SDK has no separate channel for hidden user context: the prompt is the user message, so modelText follows the short line in the prompt of that query call. The system prompt stays the same on every turn and never contains the answer. 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.