Memory in Chat Applications

What is Chat Memory?

Message Types in Memory

// System message - Sets behavior
{
  role: 'system',
  content: 'You are a helpful assistant...'
}

// User messages - Human inputs
{
  role: 'user',
  content: 'What's the weather like?'
}

// Assistant messages - LLM responses
{
  role: 'assistant',
  content: 'Let me check the weather for you',
  tool_calls: [...]
}

// Tool messages - Function results
{
  role: 'tool',
  content: '{"temp": 72, "conditions": "sunny"}',
  tool_call_id: 'call_123'
}

Why Memory Matters

Context Awareness

Examples of Context

User: "What's the weather like?"
Assistant: "It's 72° and sunny"
User: "What about tomorrow?"
// Needs memory to know we're talking about weather

Task Continuity