Skip to content

sessions_get_viewer

Signed-in state and identity. Safe to call anonymously.

Discoveryread-only

When to use it

  • Before any tool marked "sign-in required", so the agent can offer to open sign-in instead of hitting a refusal.

  • To personalise a reply — the viewer’s name is here.

Parameters

This tool takes no arguments.

Returns

Every tool returns two things: text for the model to read, and a structuredContent object beside it for code that would rather branch on a field.

Whether anyone is signed in on the page, and if so their name and email. Never errors when signed out: it reports the signed-out state as a normal result.

Example

Run this from any agent or script executing in the page.

javascript
const tools =
  await document.modelContext.getTools();

const tool = tools.find(
  (t) => t.name === 'sessions_get_viewer',
);

const result = await document.modelContext
  .executeTool(tool);
content
Signed in as Dana Whitfield
(dana@example.com).
structuredContent
{
  "signedIn": true,
  "user": {
    "id": "<id>",
    "email": "dana@example.com",
    "name": {
      "full": "Dana Whitfield"
    }
  }
}

What the agent is told

The description the model reads when deciding whether to call this. It is the only thing that decides whether the tool fires at the right moment, so it is worth knowing what it says.

sessions_get_viewer
Whether anyone is signed in on this page, and if so their name and email. Call this before any tool that acts on the viewer, so you can offer sessions_start_sign_in instead of failing.

See also