Skip to content
DocsDashboard

Install Page Systems in an OpenAI Agents SDK agent

Page Systems lets an OpenAI Agents 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 @openai/agents

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

TypeScript

With an OpenAI-compatible provider other than OpenAI, call setOpenAIAPI('chat_completions') (from @openai/agents) at startup.

// lib/agent.ts
import { Agent, MemorySession, run } from '@openai/agents';
import { getPageSystemsSkill } from 'pagesystems';
import { pageSystemsTools } from 'pagesystems/openai-agents';

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 sessions = new Map<string, MemorySession>(); // use a persistent session 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) {
  const session = sessions.get(conversationId) ?? new MemorySession();
  sessions.set(conversationId, session);
  const agent = new Agent({
    name: 'Assistant',
    instructions: [yourInstructions, skill].join('\n\n'),
    tools: pageSystemsTools({ callbackUrl: CALLBACK_URL, agentRef: { sessionId: conversationId } }),
  });
  // The note rides in the user message, never in instructions. The session stores both together; show userMessage to the person.
  const input = [userMessage, modelNote].filter(Boolean).join('\n\n');
  const result = await run(agent, input, { session });
  return result.finalOutput;
}
// 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 { sessionId } = e.agentRef as { sessionId: string };
    after(async () => {
      const reply = await runTurn(sessionId, e.visibleText, e.modelText);
      await sendToPerson(sessionId, 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 runs the agent again with the same session and the short line as the new input. 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 OpenAI Agents SDK takes one user input per run, so modelText follows the short line in that user message. It stays out of the agent's instructions. 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.