Memory
How Memory Works
Section titled “How Memory Works”Agents use a sliding-window memory to maintain conversation context. The system message is always preserved. Older messages are dropped when the window is full.
[system] Always preserved[user] message 1 <- may be dropped if window full[assistant] reply 1 <- may be dropped if window full...[user] latest <- always kept[assistant] latest <- always keptConfiguration
Section titled “Configuration”const agent = new Agent({ name: "Chat Bot", instructions: "You are helpful.", memory: { maxMessages: 100 }, transport: schift.transport,});| Option | Type | Default | Description |
|---|---|---|---|
maxMessages | number | 50 | Maximum messages to retain |
Stateless by Default
Section titled “Stateless by Default”Each agent.run() call creates a fresh memory. The system message and user input are added automatically.
For multi-turn conversations, manage conversation state externally:
// Simple multi-turn patternconst messages: string[] = [];
async function chat(userMessage: string) { messages.push(userMessage); const result = await agent.run(messages.join("\n---\n")); return result.output;}Memory and Tool Calls
Section titled “Memory and Tool Calls”During a ReAct loop, tool calls and their results are stored in memory so the LLM can reference previous tool outputs:
[system] instructions[user] "What's the weather?"[assistant] [Tool call: get_weather({"city": "Seoul"})][tool] {"temperature": 22}[assistant] "It's 22C in Seoul." <- final answer