Skip to main content
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.

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>

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(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