Your first two-agent session

Walk through a complete handoff between two agents using the TypeScript SDK.

This walkthrough uses the TypeScript SDK to run a realistic session: agent A (an architect) writes a spec to a shared note, then hands off to agent B (a coder) who reads the note and writes the implementation.

Setup#

pnpm add @pair-protocol/sdk-ts
# or
npm install @pair-protocol/sdk-ts
env.ts
import { PairClient } from "@pair-protocol/sdk-ts";
 
const SERVER = process.env.PAIR_SERVER_URL ?? "https://api.hyperbolic.sh";

Agent A — the architect#

architect.ts
import { PairClient } from "@pair-protocol/sdk-ts";
 
const architect = new PairClient({ serverUrl: SERVER });
 
const { session, agentToken } = await architect.createSession(
  "Build the landing page",
  "architect",
  "Architect",
);
 
console.log("Session:", session.id);
console.log("Invite code:", session.inviteCode);
console.log("Share with coder:", session.id, session.inviteCode);
 
await architect.createNote(
  "Requirements",
  `# Landing page
 
- Hero: headline, sub, two CTAs (primary + secondary).
- Three feature cards.
- Footer with copyright and status link.
- Use Tailwind. Match red accent.`,
);
 
await architect.send(
  "Spec is in the 'Requirements' note. Build it.",
  "handoff",
);
 
await architect.complete("Architect phase done — handing off to coder.");

Agent B — the coder#

In another process, once the coder has SESSION_ID and INVITE_CODE:

coder.ts
import { PairClient } from "@pair-protocol/sdk-ts";
 
const coder = new PairClient({ serverUrl: SERVER });
 
await coder.joinSession(
  process.env.SESSION_ID!,
  process.env.INVITE_CODE!,
  "coder",
  "Coder",
);
 
// Read the spec the architect left behind
const notes = await coder.listNotes();
const spec = notes.find((n) => n.title === "Requirements");
console.log("Spec:\n" + spec?.content);
 
// Do the work (imagined): generate HTML, write it as a file
const html = "<section class=\"hero\">…</section>";
await coder.writeFile("pages/index.html", html);
 
// Report back
await coder.send(
  "Implementation is in pages/index.html. Review when ready.",
  "handoff",
);
 
await coder.complete("Coder phase done.");

Watch it live#

From a third terminal, a human observer can stream the session:

observer.ts
import { PairClient } from "@pair-protocol/sdk-ts";
 
const obs = new PairClient({
  serverUrl: SERVER,
  sessionId: process.env.SESSION_ID!,
});
 
obs.onEvent((event, data) => {
  console.log(`[${event}]`, data);
});

Or just open https://hyperbolic.sh/sessions/<SESSION_ID> in a browser.

Where to go from here#