> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Message History

> A persistent, ordered conversation log per actor — with adapters for LangChain, OpenAI, and Anthropic.

`this.messages` is a persistent, ordered log of `AgentMessage` objects stored in the
actor's KV. It is per-actor — each `idFromName("user-123")` gets its own independent
history.

```ts theme={null}
// Append a message
await this.messages.add("user", "What's my account balance?");
await this.messages.add("assistant", "Your balance is $42.");

// Read history
const all = await this.messages.all();       // all messages, oldest first
const last = await this.messages.last();     // most recent message
const recent = await this.messages.last(10); // last 10 messages
```

## Framework adapters

`this.messages` can convert history to the format expected by popular LLM SDKs:

```ts theme={null}
// LangChain / LangGraph
const msgs = await this.messages.toLangChain();
await agent.invoke({ messages: msgs });

// OpenAI Chat Completions
const msgs = await this.messages.toOpenAI();
await openai.chat.completions.create({ model: "gpt-4o", messages: msgs });

// Anthropic Messages
const msgs = await this.messages.toAnthropic();
await anthropic.messages.create({ model: "claude-opus-4-5", max_tokens: 1024, messages: msgs });
```

<Note>
  `toAnthropic()` omits `system` messages: the Anthropic Messages API takes the system
  prompt as a top-level `system` parameter, not as a conversation message. Pass it on the
  request yourself.
</Note>

The `toOpenAI()` payload feeds Telnyx Inference directly —
`env.TELNYX.ai.openai.chat.createCompletion({ model, messages })` on the
pre-authenticated [Telnyx API binding](/docs/edge-compute/telnyx-api), or any
OpenAI-compatible endpoint over HTTP. See
[Calling LLMs](/docs/agent-sdk/concepts/calling-llms) for both wiring patterns.

## Message shape

```ts theme={null}
interface AgentMessage {
  role: "system" | "user" | "assistant" | "tool";
  content: string;
  name?: string;          // tool name for role:"tool", speaker label otherwise
  toolCalls?: ToolCall[]; // present on assistant turns that request tools
  toolCallId?: string;    // links a tool result back to a ToolCall
}
```
