Skip to main content

Start signed-out sessions

The runnable session-lifecycle Pydantic AI example drives the real SessionClient through start, a Session JWT on each request, and one restart after session_ended over a deterministic local HTTP transport. It returns only lifecycle evidence to the model; identifiers and credentials remain inside the host.

The Python and TypeScript SessionClient implementations cover the personal-agent side of starting a Session (PAP §5). A Session needs nothing from the company's authorization server: start makes a PapSession locally and sends no request.

A random sid names a Session​

The personal agent chooses each Session's sid: at least 128 random bits, in URL-safe characters. PapSession keeps it with sub (the User ID), the optional agent_id, issuer (the Company's identifier: its issuer, or its HTTPS domain without one), client_id, and tenant_id; its handle, ses_ and the sid, is its name for a person or a CLI.

Every request to a company's APIs, conversations, feedback, browser-session /authorize, MCP, and extension endpoints carries a Session JWT in the Poppy-Session header, signed for that one request. The destinations come from the company's poppy.json: the request URLs its listed APIs describe and the protocol endpoints listed there or derived from them (§5.2); sharing a hostname with one of them makes no other URL a destination, and a web alternative's page, which may be any HTTPS site, gets no Session JWT or token either. Discovery and description documents, OAuth endpoints and web pages get none: the SDKs' discovery and OAuth clients send no Session header, and SessionHttpClient is used only for the endpoints above. The company keeps Sessions by client_id and sid, and learns of a new one from the first request that names it. Its Session records need not be durable: conversations are stored apart and outlast their Sessions, and servers behind a load balancer share whatever Session state they keep, as with server-side cookie sessions (the reference companies keep it in the company store).

  • Start (start): a new sid, and no request.
  • Signed in: sign-in names no Session. A request is signed in when it carries an access token beside the Session header, with that token's account and scopes, so one sign-in can serve several Sessions (§5.4).
  • Ended: a company answers session_ended (HTTP 400) when a Session header names a Session it ended, or changes accounts in one when it refuses that (§5.4, §5.5). SessionHttpClient and SessionFetchClient then start a new Session once (session.restart(): a new sid, the same User ID and Agent ID) and send the request again; a second refusal goes to the caller. To end a Session yourself, stop using its sid. Its refresh tokens are unaffected.

Sign-in and refresh are plain OAuth and give an AccessToken: access_token, a token_type of Bearer or DPoP, expires_in, scope, and resource when it was issued for one service. The specification says a personal agent SHOULD support DPoP. Both SDKs do: they send a proof with token requests when the issuer lists ES256, and with every request that carries a DPoP token. A DPoP token type with no proof sent is refused (unsupported_token_type). See DPoP.

A personal agent that acts for a user through several agents MAY name which one a Session is for with an Agent ID (agent_id, agentId). It follows the same rules as the User ID: stable, opaque, different for each company, never derived from personal information. A Session keeps the Agent ID it started with, and a restart keeps it too. Agent IDs cover only agents the personal agent's operator runs; an agent another company runs connects under its own client_id, and the user signs it in separately (§5.1). Agent IDs are not part of a conversation's ownership (§8.2).

The client is intentionally not a key-management system. Before sending requests, the host must register exactly one active pap.signer and pap.sessionSigner contribution in its Reactor platform. Those providers must keep private keys in protected custody and return only compact signed values. DelegatedSessionSigner is the reference session signer: one delegated P-256 key per tenant, issuer, and User ID, never shared across User IDs, with a delegation of at most 24 hours from the pap.signer key in the agent's jwks_uri. It rotates the key before the delegation expires and never signs past it. InMemoryDelegatedKeys is the in-memory custody, and a host supplies its own DelegatedKeyCustody for durable, protected keys. Missing or equal-priority providers fail closed.

The pairwise user ID is the User ID of §5.1: a pairwise subject identifier, as in OpenID Connect Core §8, except that the personal agent assigns it, one for each pair of user and company. It is not a profile identifier, must not contain or be derived from personal information (not even through a keyed hash), and must not be regenerated per process. Resolve it through the pap.pairwiseUserIdStore contribution using the local tenant/application, local user ID, and the verified Company identifier (company.identifier). Different identifiers must receive unlinkable values.

Python​

import httpx

from personal_agent_protocol import SessionClient, resolve_pairwise_user_id

async with httpx.AsyncClient() as http:
pairwise_user_id = await resolve_pairwise_user_id(
reactor,
tenant_id="application-42",
local_user_id="local-user-42",
company_issuer="https://auth.company.example",
)
sessions = SessionClient(reactor=reactor, http_client=http)
session = await sessions.start(
client_id="https://agent.example/agent.json",
pairwise_user_id=pairwise_user_id,
issuer="https://auth.company.example",
tenant_id="application-42",
)

The application owns an injected HTTPX client's lifecycle. start sends no request: a Session is local, its sid chosen at random, and it starts signed out. Each request then carries a Session JWT from pap.sessionSigner.

TypeScript​

import {
SessionClient,
resolvePairwiseUserId,
} from '@datalayer/personal-agent-protocol';

const pairwiseUserId = await resolvePairwiseUserId(reactor, {
tenantId: 'application-42',
localUserId: 'local-user-42',
companyIssuer: 'https://auth.company.example',
});

const sessions = new SessionClient({ reactor });
const session = await sessions.start({
clientId: 'https://agent.example/agent.json',
pairwiseUserId,
issuer: 'https://auth.company.example',
tenantId: 'application-42',
});

start sends no request here either: a PapSession is local, and each request carries a Session JWT from pap.sessionSigner (SessionSigners in TypeScript).

Enforced request boundary​

For each attempt, the transport (SessionHttpClient, SessionFetchClient):

  • asks pap.sessionSigner for a fresh Session JWT, bound to the request's method and URL, the Company's identifier, and the access token's hash (ath) when one is sent;
  • sends it in Poppy-Session, with the Session's protocol version in Poppy-Version (§3.4) and any access token in Authorization, and refuses every redirect;
  • with a DPoP token, asks pap.dpopProver for a fresh proof, whose ath covers the same token, and sends it in DPoP;
  • with a pap.operatorSigner contributed, last, asks it for an operator signature over the Session JWT and any token, and sends Signature-Agent, Signature-Input and Signature;
  • rejects a caller-supplied Authorization, DPoP, Poppy-Session, or signature header;
  • on session_ended, starts a new Session once and sends the request again, and on invalid_session returns the refusal at once, since a new Session would fail the same way (§5.3); and
  • on a use_dpop_nonce challenge, sends the request again once with the nonce, and keeps the latest DPoP-Nonce per origin for later requests.

Each token request gets a fresh client assertion from pap.signer, a DPoP proof when the issuer lists ES256, and no Session header. It is a form-encoded POST without browser credentials or redirects, and accepts only bounded application/json responses parsed with duplicate member rejection.

Remote error descriptions and response bodies are not copied into public errors. The stable OAuth error code, HTTP status, and optional Retry-After value remain available for policy and retry decisions.

Deliberate limits​

The SDK ships JOSE signing plus Session JWT creation and verification, but it does not ship managed key custody, a durable replay cache, or a company-side token service. An application must supply those host capabilities before using real credentials. Direct, Device, and Mediated Sign-In name no Session, so they can happen at any time after one starts: the same sid and the same conversations continue, signed in once requests carry the access token.

Python includes SqlitePairwiseUserIdStore as a file-backed, atomic reference implementation for local deployments and tests. It rejects in-memory SQLite so the mapping cannot disappear on restart. Distributed production hosts should contribute a transactional database implementation; Datalayer maps tenant_id to the stable application identity and owns retention and erasure in IAM.

See the upstream session specification and the local protocol status for the current coverage boundary.