sessions_get_viewer
Signed-in state and identity. Safe to call anonymously.
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.
const tools =
await document.modelContext.getTools();
const tool = tools.find(
(t) => t.name === 'sessions_get_viewer',
);
const result = await document.modelContext
.executeTool(tool);Signed in as Dana Whitfield
(dana@example.com).{
"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.