liveBook · Manning

Dialogue

As explained in Designing AI Systems

A conversation is a structured sequence of messages exchanged between a user, an assistant, and the system instructions governing the interaction.

Dialogue gives an assistant continuity across exchanges. A conversation is a sequence of messages with roles and content; a model request combines relevant history with the current user message and system instructions. Without that history, a follow-up such as “What about for my child?” loses the context needed to interpret it. section 3.1.1 section 4.0

Keep conversation storage separate from model generation. A workflow obtains a session, retrieves its messages, assembles the model request, and stores the new exchange afterward. A persistent session lets a client resume the conversation after routine infrastructure disruptions. section 10.3

A session service exposes the lifecycle and message operations needed by the workflow:

  • GetOrCreateSession accepts a user ID and optional session ID, creating a session or resuming one. ListSessions lets a client display a user's sessions; the product decides which session is active. section 4.2
  • AddMessages records messages, GetMessages retrieves history, and DeleteSession cleans up conversations. Retrieval can specify a limit, offset, and strategy. section 4.2
  • Messages carry a role and optional content, and can also represent tool calls, tool-call IDs, names, and timestamps. section 4.2
Listing 4.3 Protocol Buffer service definition for the Session Service
syntax = "proto3";
 
package sessions;
 
service SessionService {
    rpc GetOrCreateSession(GetOrCreateSessionRequest) 
        returns (GetOrCreateSessionResponse);
    rpc ListSessions(ListSessionsRequest)
        returns (ListSessionsResponse);
    rpc AddMessages(AddMessagesRequest) 
        returns (AddMessagesResponse);
    rpc GetMessages(GetMessagesRequest) 
        returns (GetMessagesResponse);
    rpc DeleteSession(DeleteSessionRequest) 
        returns (DeleteSessionResponse);
}
 

The service contract separates session lifecycle operations from recording and retrieving conversation messages. section 4.2

Stored history and model context are not the same thing. A conversation can grow beyond the model's token limit, particularly when tool calls and their results add verbose content. A sliding window can send only the most recent messages while retaining the rest in storage, but the assistant then loses access to earlier details in that request. section 4.0 section 10.3

A contextual return-policy answer

A customer asks about electronics returns after discussing a laptop purchase. The workflow retrieves the earlier conversation, validates the input, searches company policy documents, and supplies the context to the model. The earlier exchange helps make the answer relevant to the laptop rather than a generic policy response. section 1.5

Capture the model and token usage alongside the generated response. Recording usage at the Model Service supports cost attribution and avoids reconstructing counts later from estimates or logs. section 3.1.1

How Designing AI Systems covers it

How deep it goes
Defines session and message contracts and implements a session-backed workflow, including a sliding-window trade-off.
Examples
Uses a patient intake follow-up, a retail return-policy question, and an assistant's restaurant recommendations.
What it assumes
Assumes familiarity with backend systems that store user data when introducing relational session storage.
What you can do after
Build a session-backed workflow that retrieves history, sends a conversation to a model, and stores each exchange.
How it connects
Connects conversation history to session management, context windows, tool calls, and retrieval-augmented generation.

Also explained in

Compare how 12 books explain dialogue →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.