this.messages is the agent’s persistent conversation log. Messages are ordered by an
assigned monotonic seq (insertion order, not wall-clock), and the log is append-only —
there is no delete.
The log is the agent’s memory across turns. Append messages as they happen — user
input, assistant replies, tool results — and rebuild the next LLM request from
history: last(n) for a bounded window, or an adapter for a provider-shaped payload.
Because the log persists with the instance, a crash, a restart, or a week of idleness
doesn’t lose the thread. The Message History guide
walks the full loop.
Accessing the log
The log hangs off oneAgent property:
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.
new MessageLog()
You rarely construct one —this.messages is built for you — but a standalone log
over the actor’s storage is a plain constructor call:
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
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>
Adapters
Each adapter reads the full history and converts it. They differ in how they treatsystem and tool messages:
append() with plain roles, or rebuild framework state
from toOpenAI() output instead.
toOpenAI()
toOpenAI():The full history as OpenAI Chat Completions messages. All roles are included.Promise<object[]>
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():The full history as Anthropic Messages-API turns.Promise<object[]>
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():The full history as LangChain / LangGraph messages (accepted byPromise<object[]>
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[]>