Skip to main content

Conversations

A PAP conversation is how a personal agent talks to a company's agent (draft 0.3 §8). ConversationClient sends idempotent messages and reads an ordered event log by long polling (see conversation messages and conversation events). This guide covers streaming and the controls: sign-in mid-conversation, Direct Conversations, handoff, and closing.

Streaming over SSE (§8.6)​

async for item in conversations.stream(endpoint, conversation_id, session=session):
if isinstance(item, TextDelta):
ui.show_typing(item.message_id, item.text) # display only
elif isinstance(item, StreamReconnected):
ui.drop_partial(item.discarded_message_ids)
elif isinstance(item, WorkingChanged):
ui.show_working(item.working) # no event: the company's work in progress
else:
handle_event(item) # the ConversationEvent to act on
for await (const item of conversations.stream(endpoint, conversationId, { session })) {
if ('kind' in item && item.kind === 'text-delta') ui.showTyping(item.message_id, item.text);
else if ('kind' in item && item.kind === 'reconnected') ui.dropPartial(item.discardedMessageIds);
else if ('kind' in item && item.kind === 'working') ui.showWorking(item.working);
else handleEvent(item);
}
  • Deltas never act. TextDelta.actionable is always false. The complete message event replaces the pieces; route deltas to display only.
  • Reconnect from Last-Event-ID. When the company ends the stream before the conversation closes, the client reopens it from the last event handled and yields StreamReconnected. Pieces of a message whose complete event did not arrive are listed as discarded.
  • No duplicates. Replayed events are suppressed by ID, in a bounded set that fails closed (event_history_too_large).
  • Bounded. max_reconnects reconnects in a row without a new event end in stream_unavailable. A company that answers JSON instead of text/event-stream is sse_unsupported: use events().
  • The iterator ends on a state event with closed.

Sign-in mid-conversation (§8.11)​

When the company needs the user's account, or more scopes, it adds an authorization event: error is always insufficient_scope, with the same meaning as the API error, and scope always names the scopes needed. The host responds as it would to that error, with a refresh token that covers the scopes or by running a sign-in mode the company offers, then keeps sending to the same conversation ID in the same Session (the same sid) with the new access token. Nothing in the conversation is restarted; the model never sees the sign-in's codes or tokens.

A conversation isn't tied to one access token or even one Session: the agent may switch tokens partway, after signing in, refreshing, or signing out, or continue in a new Session, as long as the request matches the conversation's owner (§8.2): the agent's client_id and the User ID that started it, and, once it uses the user's account, that account too; Agent IDs are not part of it. Before it uses an account, any token of the same agent and user continues it, and the conversation then uses that account. After it uses account A, the same agent and user signed out get a challenge (insufficient_scope; the conversation stays open, so the user can sign in again and continue it), signed in to another account conversation_not_found; another User ID or another agent is always conversation_not_found.

Explicit replies​

Both sides make an answer explicit about the question it addresses, and treat a short reply that could answer more than one open question as answering none, asking which is meant before acting (upstream guides, Explicit replies and approvals). The reference companies' agents answer a bare "yes", "ok" or "done" with a question and act on nothing; see Operations for the personal agent's side.

Direct Conversations (§8.10)​

start_direct(endpoint, parent_id, message) (startDirect in TypeScript) opens a conversation under an open parent for the user to talk with the company through the agent's interface. Only the personal agent starts one. While it is open, the parent refuses messages and handoff with direct_conversation_open; the client exposes the open conversation's ID in error.details["conversation_id"] so the host can route the user there. The parent receives direct_opened and direct_closed events.

The parent must be open, the caller's own, not a Direct Conversation itself, and without an open Direct Conversation; each failure has its own code: conversation_not_found, conversation_closed, invalid_request, and direct_conversation_open.

When the company asks. A user_requested event in the parent, with its reason, is an invitation: the agent asks the user, and when they agree calls accept_user_request(endpoint, parent_id, event_id) (acceptUserRequest in TypeScript), which sends the parent's ID and the event's and no message, so the company speaks first. Its first message is read with wait on that call, or by reading or streaming events. The same call again, with the same parent and event, returns the same Direct Conversation with no message added, even once it closed; an event that is not a user_requested event of the parent is invalid_request. The reason stays an invitation, not the first message. If the user declines, the agent says so in the parent conversation.

Either party may close a Direct Conversation, the company after inactivity; closing the parent closes it too. The agent may observe every message in it, and the company sends nothing there that it cannot share with the agent.

Where a conversation stands (§8.7)​

Every read and every receipt reports the conversation's state in four fields, each independent of the others: working (the company is still replying: a request it accepted but hasn't acted on, or a reply being written; since 1.0 not work it finishes later, such as a refund that takes days, which it says in a message and follows with another when done), handoff (pending while it looks for a person), responder (agent or human), and closed. A successful POST only means the company accepted the request, so working is true from that moment; ConversationClient.read_until_done (readUntilDone) reads until it is false and no backlog is left, which is how an agent gets the whole reply, or makes sure everything it sent was acted on before closing. Changes to handoff, responder or closed arrive as state events carrying all three; working is never an event: a wait read also returns when it turns false, and a stream sends it as a working event with no SSE id (WorkingChanged). A handoff this SDK doesn't recognize reads as pending, a responder as human. While has_more is true the state fields can be newer than the events returned: apply the events in order and rely on the state once has_more is false.

Conversations across versions (§8.2)​

A conversation can continue in a Session that uses other protocol or extension versions than the one it started in, unless the company cannot carry it over. Then it MAY reject requests on it, all or some, with version_mismatch (HTTP 409), naming the protocol version the conversation started in: the ConversationError carries it as details["protocol_version"] (error.details.protocol_version). Finish the conversation in a Session with those versions while the company still lists them, or start a new one and tell the user if they were waiting on something. The reference companies record each conversation's versions and carry conversations over by default; CompanyConfig(conversation_carry_over=False) (conversationCarryOver) makes them refuse messages, handoffs and cancels from other versions while reads stay allowed.

What a message took into account (§8.4)​

Messages cross, so a short reply such as "Done" can be ambiguous. A company agent's message MAY carry as_of_request, the ID of the latest request it took into account; the reference companies set it on every agent reply. A message the agent writes MAY carry as_of_cursor, the last cursor it had read: send(..., as_of_cursor=page.cursor) (asOfCursor) puts it on. Both are hints neither side depends on, and messages people write, author.type human, carry neither: the models refuse them there. PapReply.as_of_request carries the hint to the page.

Handoff (§8.9) and closing (§8.12)​

Every conversation POST carries a request id the agent chooses (§8.3): start, send, handoff, cancel_handoff and close take request_id (requestId), default to the message's id, and generate one otherwise (generate_request_id). A retry sends the same ID to the same path with the same body and gets the original response; a reuse with another body or path is request_id_conflict. The company acts on messages, handoff requests and cancels in the order it accepts them, and a successful POST (201 or 202) returns only conversation_id: read the state for what happened.

handoff() asks for a person at the company: handoff is pending while one is looked for, then responder becomes human when someone takes it, or handoff goes back to none and the company agent says none is available. cancel_handoff() (cancelHandoff) withdraws the request: the company MAY stop looking, or keep looking when it cannot withdraw it, and a person may have joined first, so read handoff and responder and never depend on the cancel taking effect. close() ends the conversation: it is accepted with 202, and a close doesn't wait its turn, so the company MAY act on or drop requests it has not acted on yet; read_until_done first when they matter. Once acted on, closed is true with a state event; later messages, handoff requests and cancels are conversation_closed, and a close of a closed conversation is 202 and changes nothing. Closing does not cancel anything the conversation started, such as an order or a return.

Who wrote each message: author​

Every message names its author (§8.4): type is agent or human, and a company's message may add who, with id, display name, and image (an HTTPS URL) for its person or AI persona. The personal agent never sends those three: its own messages are Message(id=..., author=Author(type="agent"), ...), or human for the words a person typed themselves in a Direct Conversation. A company built with the SDK writes its people's replies with staff_reply(..., author_id=..., author_name=..., author_image=...).

Extension content in messages​

Content an extension defines travels in a message's extensions, keyed by the extension's name (spec 8.4): the Operations extension's operation and approval in extensions.operations, the pages a company message refers to in extensions.links (the Links extension, version 1), and the notices it marks apart, such as an allergen warning, in extensions.disclosures (the Disclosures extension, version 1). A message needs text, data, context or extensions.

  • Python reads them as properties: message.operation, message.approval, message.links (Link: url, title) and message.disclosures (Disclosure: text); a personal agent approves with Message(..., extensions=operations_content(approval=approval)). TypeScript reads them with messageOperation, messageApproval, messageLinks and messageDisclosures, and builds the approval with operationsContent({ approval }).
  • Both SDKs check the three extensions' content by its shape (OperationsContent carries one of operation and approval; a link's url is HTTPS) and keep any other extension's content as the object it is.
  • A side sends an extension's content only to a side that lists the same version. The reference companies send links and disclosures when CompanyConfig.links and CompanyConfig.disclosures are set (Manzanita sets both) and the agent's client metadata lists the extension; without the Disclosures extension the notice goes in text, and without Links the page is left out. A personal agent lists what its host can show (AgentIdentity(extensions=("operations", "links", "disclosures"))).

Who wrote each reply: PapReplies​

A company's message is written by its agent or by one of its people (author), apart from where the conversation stands (working, handoff, closed, §8.7) and who answers it now (responder). A host shows them apart with PapReplies (personal_agent_protocol.ui), of type application/vnd.datalayer.pap.replies+json, version 5, made with PapReplies.of(company, conversation_id, messages, working=..., handoff=..., responder=..., closed=...) from the messages a page of events carried.

  • It names the conversation the replies are in (conversation): where the person's own words open a Direct Conversation under it, typed on the page and sent as theirs (author.type: human), never through the model. Version 1 named none.

  • Each reply says who wrote it (author: agent or human) and, when the company gave one, the writer's name (version 3), shown as one of its people (Rosa).

  • Each reply carries the pages it refers to (links, each a url and a title; a page shows the title with the URL's host, PapLink.host or papLinkHost, never the title alone) and the notices it marks apart (disclosures, shown in full, apart from the text), version 4. Without the extensions both are empty.

  • Only the company's own messages with text are replies, each verbatim; a message carrying only data is the model's to read. With none, of returns None and nothing is drawn.

  • text() says each on its line: shop.example, its agent: … or shop.example, one of its people: …, then each notice (Notice: …) and each link with its host (Link: Return policy (shop.example)).

  • The personal agent's own messages are author.type: agent (PAP-8.8-01): only what the person typed themselves, in a Direct Conversation, is human.

The TypeScript SDK types it (PapRepliesData) and checks it with isPapReplies, against the committed example protocol/fixtures/pap-replies-display.json.

Security boundary​

  • Access tokens, delegated keys, Session JWTs, pairwise IDs, and cursors stay in the host.
  • A model receives the event fields it needs: company text, data, event types, and statuses. It never treats conversation text, from either side, as the user's approval of anything.
  • Errors carry codes (and, for direct_conversation_open, a validated conversation ID), never response bodies.

See the runnable conversation streaming and conversation control examples, and the upstream conversations specification.