Examples

Real integration patterns for Memcone. Same primitives, multiple languages:remember,recall,context.

Chatbot with user memory

The core pattern. Load compressed memory before the model responds, then store the new event after the interaction.

example.ts
const mem = (path: string, body: object) =>
  fetch(`https://api.memcone.com/v1/${path}`, {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  }).then((r) => r.json())

export async function POST(req: Request) {
  const { userId, message } = await req.json()
  const { result: memory } = await mem("context", { scopeId: userId, task: "reply to user" })

  const reply = await openai.responses.create({
    model: "gpt-4.1",
    input: [
      { role: "system", content: `About this user: ${memory}` },
      { role: "user", content: message },
    ],
  })

  void mem("remember", { scopeId: userId, event: message })
  return Response.json(reply)
}
const mem = (path: string, body: object) =>
  fetch(`https://api.memcone.com/v1/${path}`, {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  }).then((r) => r.json())

export async function POST(req: Request) {
  const { userId, message } = await req.json()
  const { result: memory } = await mem("context", { scopeId: userId, task: "reply to user" })

  const reply = await openai.responses.create({
    model: "gpt-4.1",
    input: [
      { role: "system", content: `About this user: ${memory}` },
      { role: "user", content: message },
    ],
  })

  void mem("remember", { scopeId: userId, event: message })
  return Response.json(reply)
}

Support agent with returning user context

Support flows benefit from the same pattern, but you usually scope memory per support user or ticket thread.

example.ts
async function handleSupportTicket(userId: string, message: string) {
  const { result: userContext } = await fetch("https://api.memcone.com/v1/context", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      scopeId: `support:${userId}`,
      task: "respond to support request",
    }),
  }).then((r) => r.json())

  const reply = await anthropic.messages.create({
    model: "claude-opus-4-5",
    max_tokens: 1024,
    system: userContext
      ? `You are a support agent. Context about this user: ${userContext}`
      : "You are a support agent.",
    messages: [{ role: "user", content: message }],
  })

  void fetch("https://api.memcone.com/v1/remember", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      scopeId: `support:${userId}`,
      event: { ticket: message, timestamp: new Date().toISOString() },
    }),
  })

  return reply.content[0].text
}
async function handleSupportTicket(userId: string, message: string) {
  const { result: userContext } = await fetch("https://api.memcone.com/v1/context", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      scopeId: `support:${userId}`,
      task: "respond to support request",
    }),
  }).then((r) => r.json())

  const reply = await anthropic.messages.create({
    model: "claude-opus-4-5",
    max_tokens: 1024,
    system: userContext
      ? `You are a support agent. Context about this user: ${userContext}`
      : "You are a support agent.",
    messages: [{ role: "user", content: message }],
  })

  void fetch("https://api.memcone.com/v1/remember", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      scopeId: `support:${userId}`,
      event: { ticket: message, timestamp: new Date().toISOString() },
    }),
  })

  return reply.content[0].text
}

Project memory for coding agents

Use project scopes when you want architectural decisions, stack choices, and past implementation context to persist across sessions.

example.ts
async function getCodingContext(projectId: string, task: string) {
  const { result } = await fetch("https://api.memcone.com/v1/context", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ scopeId: `project:${projectId}`, task }),
  }).then((r) => r.json())

  return result
}

async function rememberDecision(projectId: string, decision: string) {
  await fetch("https://api.memcone.com/v1/remember", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ scopeId: `project:${projectId}`, event: decision }),
  })
}
async function getCodingContext(projectId: string, task: string) {
  const { result } = await fetch("https://api.memcone.com/v1/context", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ scopeId: `project:${projectId}`, task }),
  }).then((r) => r.json())

  return result
}

async function rememberDecision(projectId: string, decision: string) {
  await fetch("https://api.memcone.com/v1/remember", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.MEMCONE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ scopeId: `project:${projectId}`, event: decision }),
  })
}

Related guides