Skip to content

DefaultConversationState

Default conversation state implementation extracted from Runtime.

Handles:

  • Session load/create/save/delete via SessionStore
  • Message appending with normalization
  • Turn counting
  • Working memory access
new DefaultConversationState(config): DefaultConversationState;
Parameter Type

config

DefaultConversationStateConfig

DefaultConversationState

appendAssistantMessage(session, text): void;

Append an assistant message to the session history.

Parameter Type

session

Session

text

string

void

ConversationState.appendAssistantMessage


appendMessage(session, message): void;

Append a raw ModelMessage to the session history.

Parameter Type

session

Session

message

ModelMessage

void

ConversationState.appendMessage


appendUserMessage(session, text): void;

Append a user message to the session history.

Parameter Type

session

Session

text

string

void

ConversationState.appendUserMessage


bumpSessionTurn(session): number;

Increment and return the new turn number.

Parameter Type

session

Session

number

ConversationState.bumpSessionTurn


createSession(
id,
defaultAgentId,
userId?,
opts?): Session;

Create a fresh session with defaults.

Parameter Type

id

string

defaultAgentId

string

userId?

string

opts?

{ channelId?: ChannelId; conversationId?: string; }

opts.channelId?

ChannelId

opts.conversationId?

string

Session

ConversationState.createSession


delete(sessionId): Promise<void>;

Delete a session from the backing store.

Parameter Type

sessionId

string

Promise<void>

ConversationState.delete


getSessionTurn(session): number;

Get the current turn number for the session.

Parameter Type

session

Session

number

ConversationState.getSessionTurn


load(sessionId, userId?): Promise<Session>;

Load an existing session or create a new one.

Parameter Type

sessionId

string

userId?

string

Promise<Session>

ConversationState.load


save(session): Promise<void>;

Persist session to the backing store.

Parameter Type

session

Session

Promise<void>

ConversationState.save


touchSession(session): void;

Update the session’s updatedAt timestamp.

Parameter Type

session

Session

void

ConversationState.touchSession


workingMemory(session): WorkingMemory;

Get a WorkingMemory wrapper for the session.

Parameter Type

session

Session

WorkingMemory

ConversationState.workingMemory