Skip to main content

Problem

Agents forget. Without somewhere to put it, everything a user said in a previous session is gone, and each conversation starts from zero. The fix is durable context the agent can write to as it learns and read from on every turn, so it builds on prior interactions instead of treating each one as isolated. Two kinds of context are worth keeping:
  • Working context - unstructured insights drawn from conversations: preferences, tone, recurring topics, and decisions. Updated after each interaction.
  • Durable context - stable facts about the user: profile, account tier, identifiers, long-standing preferences. Changes rarely.
Both live as documents in a Moss index and surface through the same semantic query.

The capture and recall loop

On each turn the agent recalls the most relevant context with a query, grounds its response in it, then captures new insights by writing them back. Over time the index becomes a compounding record the agent can draw on.

Code walkthrough (JavaScript)

import { MossClient } from '@moss-dev/moss'
const client = new MossClient(process.env.MOSS_PROJECT_ID!, process.env.MOSS_PROJECT_KEY!)

const index = 'agent-context'
await client.createIndex(index, [
  { id: 'user_profile', text: 'User prefers concise answers.' }
], { modelId: 'moss-minilm' })

// Load before querying.
await client.loadIndex(index)

// Recall: pull relevant context for this turn.
const context = await client.query(index, 'preferences for responses', { topK: 3 })

// Capture: write new insights back so the next turn can use them.
await client.addDocs(index, [
  { id: 'pref_format', text: 'User asked for bullet-point summaries.' }
], { upsert: true })

Result

Agents recall user preferences and prior context reliably, and each conversation adds to what they know rather than starting over.

Live-call context

Short-term + long-term context during a call.

Cross-agent handoff

Carry context across agents and channels.