The agent’s persistent conversation history. An append-only, per-instance log ordered by an assigned monotonicprotectedreadonlymessages:MessageLog
seq.
See MessageLog for reads, writes, and the LangChain / OpenAI /
Anthropic adapters.
add()
add(Append a message by role + content — shorthand forrole,content):Promise<number>
append({ role, content }).
Parameters
Returns
Promise<number>
The assigned seq of the new message.
append()
append(Append one message; atomically assigns and returns itsmsg):Promise<number>
seq (the counter
advance and the row write commit together).
Message fields must be storage-codec-safe; a value that cannot be encoded
throws a CodecError.
Parameters
Returns
Promise<number>
The assigned seq of the new message.
appendMany()
appendMany(Append a batch of messages atomically — all rows commit together. Parametersmsgs):Promise<number>
Returns
Promise<number>
The last assigned seq (or the current count for an empty
batch).
all()
all():The full history in chronological order (paginates internally — no length cap). Reads the entire history every time; on a long-lived conversation preferPromise<StoredMessage[]>
last(n) for a bounded context window.
Returns
Promise<StoredMessage[]>
last()
last():The single most-recent message, orPromise<StoredMessage|undefined>
undefined on an empty log.
Returns
Promise<StoredMessage | undefined>
Call Signature
last(The lastn):Promise<StoredMessage[]>
n messages, in chronological order.
Parameters
Returns
Promise<StoredMessage[]>
count()
count():Total messages ever appended — the currentPromise<number>
seq high-water mark. The log
is append-only, so this equals the number of stored messages.
Returns
Promise<number>
toOpenAI()
toOpenAI(): Promise<Array<{ role: string; content: string; name?: string; tool_call_id?: string; tool_calls?: Array<{ id: string; type: "function"; function: { name: string; arguments: string } }> }>>
The full history as OpenAI Chat Completions messages.
All roles are included. toolCalls on assistant turns map to
tool_calls (with args JSON-stringified into function.arguments),
and toolCallId maps to tool_call_id. The result feeds any
OpenAI-compatible chat-completions endpoint directly.
Returns
Promise<object[]>
toAnthropic()
toAnthropic(): Promise<Array<{ role: "user" | "assistant"; content: unknown }>>
The full history as Anthropic Messages-API turns.
system messages are dropped — the Anthropic API takes the system
prompt as a top-level system parameter, so pass it on the request
yourself. Assistant toolCalls become tool_use content blocks, and
tool messages become user turns carrying tool_result blocks.
Returns
Promise<object[]>
toLangChain()
toLangChain(): Promise<Array<{ role: "user" | "assistant" | "system"; content: string }>>
The full history as LangChain / LangGraph messages (accepted by
agent.invoke({ messages })).
Only user / assistant / system messages survive — tool messages
and toolCalls are dropped. If your loop needs tool history, persist
it via append() with plain roles or rebuild framework state from
toOpenAI() output instead.
Returns
Promise<object[]>
new MessageLog()
new MessageLog(Parametersstorage,onAppend?):MessageLog
Returns
MessageLog
AgentMessage
A framework-neutral chat message. Adapters map this to OpenAI / Anthropic. Extended by Properties content
content: string
The message text.
name?
Optional author label (tool name for role:“tool”, speaker for others).optionalname?:string
role
role:Who authored the message."system"|"user"|"assistant"|"tool"
toolCallId?
Present on role:“tool” turns, linking a result back to a ToolCall.id.optionaltoolCallId?:string
toolCalls?
Present on assistant turns that request tools.optionaltoolCalls?:ToolCall[]
ToolCall
A tool-call request emitted by the model (assistant turn). Properties args
args: unknown
Arguments for the tool, as the model produced them.
id
id: string
Model-assigned call id; a later tool message echoes it as toolCallId.
name
name: string
Name of the tool the model wants invoked.
StoredMessage
An AgentMessage as persisted: assigned a monotonic seq + wall-clock stamp. Extends Properties at
at: Date
Wall-clock stamp at append time; informational only (ordering is by seq).
content
content: string
The message text.
Inherited from
AgentMessage.content
name?
Optional author label (tool name for role:“tool”, speaker for others). Inherited fromoptionalname?:string
AgentMessage.name
role
role:Who authored the message. Inherited from"system"|"user"|"assistant"|"tool"
AgentMessage.role
seq
seq: number
Monotonic sequence number, assigned on append — the log’s order.
toolCallId?
Present on role:“tool” turns, linking a result back to a ToolCall.id. Inherited fromoptionaltoolCallId?:string
AgentMessage.toolCallId
toolCalls?
Present on assistant turns that request tools. Inherited fromoptionaltoolCalls?:ToolCall[]
AgentMessage.toolCalls