Skip to main content
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 one Agent property:
protected readonly messages: MessageLog
The agent’s persistent conversation history. An append-only, per-instance log ordered by an assigned monotonic 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(storage, onAppend?): MessageLog
Parameters 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 name?: string
Optional author label (tool name for role:“tool”, speaker for others).
role
role: "system" | "user" | "assistant" | "tool"
Who authored the message.
toolCallId?
optional toolCallId?: string
Present on role:“tool” turns, linking a result back to a ToolCall.id.
toolCalls?
optional toolCalls?: ToolCall[]
Present on assistant turns that request tools.

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 name?: string
Optional author label (tool name for role:“tool”, speaker for others). Inherited from AgentMessage.name
role
role: "system" | "user" | "assistant" | "tool"
Who authored the message. Inherited from AgentMessage.role
seq
seq: number
Monotonic sequence number, assigned on append — the log’s order.
toolCallId?
optional toolCallId?: string
Present on role:“tool” turns, linking a result back to a ToolCall.id. Inherited from AgentMessage.toolCallId
toolCalls?
optional toolCalls?: ToolCall[]
Present on assistant turns that request tools. Inherited from AgentMessage.toolCalls

add()

add(role, content): Promise<number>
Append a message by role + content — shorthand for append({ role, content }). Parameters Returns Promise<number> The assigned seq of the new message.

append()

append(msg): Promise<number>
Append one message; atomically assigns and returns its 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(msgs): Promise<number>
Append a batch of messages atomically — all rows commit together. Parameters Returns Promise<number> The last assigned seq (or the current count for an empty batch).

all()

all(): Promise<StoredMessage[]>
The full history in chronological order (paginates internally — no length cap). Reads the entire history every time; on a long-lived conversation prefer last(n) for a bounded context window. Returns Promise<StoredMessage[]>

last()

last(): Promise<StoredMessage | undefined>
The single most-recent message, or undefined on an empty log. Returns Promise<StoredMessage | undefined> Call Signature
last(n): Promise<StoredMessage[]>
The last n messages, in chronological order. Parameters Returns Promise<StoredMessage[]>

count()

count(): Promise<number>
Total messages ever appended — the current 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 treat system and tool messages:
If you record tool calls in history and hand it to LangChain, note the drop: persist what the framework needs via append() with plain roles, or rebuild framework state from toOpenAI() output instead.

toOpenAI()

toOpenAI(): Promise<object[]>
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<object[]>
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<object[]>
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[]>