CortexDB Docs
Integrations

Mastra

Give Mastra agents long-term memory via the CortexDB TypeScript SDK.

Mastra is a TypeScript agent framework. Wire CortexDB in through the TypeScript SDK as a tool or in an agent's memory hooks.

Install

npm install cortexdbai

As a tool

import { V1Client } from "cortexdbai/v1";
import { createTool } from "@mastra/core";
import { z } from "zod";

const client = new V1Client({
  apiUrl: "https://api-v1.cortexdb.ai",
  actor: "agent:mastra",
  bearer: process.env.CORTEX_TOKEN!,
});
const scope = "org:acme/agent:mastra";

export const recallMemory = createTool({
  id: "recall-memory",
  description: "Recall long-term memory from CortexDB",
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ context }) => {
    const pack = await client.recall(scope, { view: "holistic", query: context.query,
                                              diagnostics: "none" });
    return { context: pack.context_block ?? "" };
  },
});

See also

On this page