AI SDK Module
The AI SDK module provides Vercel AI SDK helpers for integrating TekMemo memory tools into generateText, streamText, and agent workflows.
Installation
The AI SDK helpers live in the @tekbreed/tekmemo-adapter-ai-sdk adapter package. Install it alongside core and the Vercel AI SDK peer dependency:
npm install @tekbreed/tekmemo @tekbreed/tekmemo-adapter-ai-sdk aiImport
The AI SDK helpers are imported from the adapter package; Tekmemo and the TekMemoMemoryRuntime contract come from core:
import { Tekmemo } from "@tekbreed/tekmemo";
import {
buildRuntimeMemoryToolDefinition,
buildRuntimeMemoryContext,
runRuntimeMemoryTool,
createAiSdkRuntimeFromTekmemo,
buildAgentSessionInstructions,
} from "@tekbreed/tekmemo-adapter-ai-sdk";Purpose
Use this package to expose TekMemo memory as AI SDK tools. The module provides:
buildRuntimeMemoryToolDefinition()for a ready-to-use AI SDK tool with memory operationsrunRuntimeMemoryTool()for executing memory tool commands with scope enforcementcreateAiSdkRuntimeFromTekmemo()for adapting aTekmemoinstance to the AI SDK runtime contractbuildRuntimeMemoryContext()for building memory-aware context (system prompt)buildAgentSessionInstructions()for agent session instruction blocks- Scope enforcement for project, user, conversation, and participant memory
Quick start with Tekmemo
The Tekmemo class is the recommended way to set up memory. Pass the instance to createAiSdkRuntimeFromTekmemo() and every runtime call — recall, context, writes — is delegated back to the Tekmemo class, so you get the full hybrid engine rather than a naive search:
import { generateText, stepCountIs } from "ai";
import { openai } from "@ai-sdk/openai";
import { Tekmemo } from "@tekbreed/tekmemo";
import {
buildRuntimeMemoryContext,
buildRuntimeMemoryToolDefinition,
createAiSdkRuntimeFromTekmemo,
} from "@tekbreed/tekmemo-adapter-ai-sdk";
const memo = new Tekmemo({ rootDir: "./.tekmemo", projectId: "demo" });
const runtime = createAiSdkRuntimeFromTekmemo(memo);
const access = { projectId: "demo", userId: "user_123" };
const { text: system } = await buildRuntimeMemoryContext({
runtime,
access,
query: prompt,
baseInstructions: "You are a helpful assistant.",
});
await generateText({
model: openai("gpt-4.1-mini"),
system,
prompt,
tools: {
memory: buildRuntimeMemoryToolDefinition({ runtime, access, allowWrites: true }),
},
stopWhen: stepCountIs(6),
});Cloud-backed tools
For cloud-backed memory, construct a Tekmemo client in hybrid mode with a cloud client (the cloud is a file replica — there is no mode: "cloud") and pass it to the same factory. The agent code does not change:
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { Tekmemo, createTekMemoCloudClient } from "@tekbreed/tekmemo";
import {
createAiSdkRuntimeFromTekmemo,
buildRuntimeMemoryContext,
buildRuntimeMemoryToolDefinition,
} from "@tekbreed/tekmemo-adapter-ai-sdk";
const memo = new Tekmemo({
mode: "hybrid",
projectId: "proj_123",
rootDir: "./.tekmemo",
cloudClient: createTekMemoCloudClient({
baseUrl: "https://memo.tekbreed.com/api/v1",
apiKey: process.env.TEKMEMO_API_KEY!,
}),
});
const runtime = createAiSdkRuntimeFromTekmemo(memo);
const access = { projectId: "proj_123", userId: "user_123" };
const { text: system } = await buildRuntimeMemoryContext({
runtime,
access,
query: prompt,
baseInstructions: "You are a helpful assistant.",
});
await generateText({
model: openai("gpt-4.1-mini"),
system,
prompt,
tools: {
memory: buildRuntimeMemoryToolDefinition({ runtime, access, allowWrites: true }),
},
});Direct usage (advanced)
createAiSdkRuntimeFromTekmemo() is the supported entry point — it delegates recall and writes to the Tekmemo class. There is intentionally no lower-level "runtime from a raw store" factory: bypassing Tekmemo would lose the hybrid recall engine, so we recommend always constructing a Tekmemo instance first.
See also
Tekmemoclient for the primary API surface- AI SDK Tools guide for detailed tool configuration