1export function memoryTools(agent: Klippy) {
2 const remember = tool({
3 description:
4 'Remember a lasting fact about the user for future chats: their name, preferences, people and plans. Not for one-off questions or things only true today.',
5 inputSchema: z.object({ fact: z.string().trim().min(1).max(MAX_FACT).describe('One short fact, e.g. "Has a dog called Pip"') }),
6 execute: async ({ fact }) => {
7 if (facts(agent).length >= MAX_FACTS) return { error: `Memory is full (${MAX_FACTS} facts). Forget one first.` };
8 const [row] = agent.sql<{ id: number }>`INSERT INTO facts (fact) VALUES (${fact}) RETURNING id`;
9 return { remembered: { id: row.id, fact } };
10 },
11 });
12
13 const forget = tool({
14 description: 'Forget a fact you remembered, by its id from "What you know about the user". Use it when the user asks, or a fact is wrong.',
15 inputSchema: z.object({ id: z.number().int().describe('The id of the fact') }),
16 execute: async ({ id }) => {
17 facts(agent); // makes sure the table exists
18 agent.sql`DELETE FROM facts WHERE id = ${id}`;
19 return { forgot: id };
20 },
21 });
22
23 return { remember, forget };
24}