Installation
pnpm add @aimform/ai @aimform/core
First Chat
import { AI } from "@aimform/ai";
import { D1DatabaseAdapter } from "@aimform/core";
const ai = new AI({
model: "deepseek-v4-flash",
apiKeys: { deepseekApiKey: env.DEEPSEEK_API_KEY },
db: new D1DatabaseAdapter(env.DB),
transport: new DirectTransport(), // see Transport docs
});
const result = await ai.chat({
runId: crypto.randomUUID(),
conversationId: "conv-1",
messages: [
{ role: "user", content: "Hello! What tools do you have?" }
],
toolContext: {
userId: "user-1",
profileId: "profile-1",
sessionId: crypto.randomUUID(),
env: {},
},
});
console.log(result.assistantMessage.content);
Registering Custom Tools
ai.registry.register(
{
name: "get_weather",
description: "Get current weather for a city",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "City name" },
},
required: ["city"],
},
},
async (args, ctx) => {
const weather = await fetchWeather(args.city as string);
return {
toolCallId: ctx.toolCallId ?? "",
name: "get_weather",
result: JSON.stringify(weather),
};
},
"custom",
);
Now the AI can call get_weather when users ask about weather.
Enabling Memory
const ai = new AI({
// ... other config
enableMemory: true,
});
// After each chat turn, extract memories
await ai.memory.conversation.updateSummary("conv-1", messages);
await ai.memory.profile.extractAndSave("user-1", latestUserMessage);
Adding Plugins
const ai = new AI({
// ... other config
plugins: {
files: new AimformFilesPlugin({ uploadFile, listFiles, getFile, deleteFile }),
webSearch: new TavilySearchPlugin(process.env.TAVILY_API_KEY),
vision: new GeminiVisionPlugin(process.env.GEMINI_API_KEY),
},
});
// These plugins auto-register tools: list_files, web_search, analyze_image, etc.