joel memories

This commit is contained in:
2026-02-01 17:55:21 +01:00
parent c13ffc93c0
commit 0c0efa645a
22 changed files with 2463 additions and 304 deletions

199
src/services/ai/tools.ts Normal file
View File

@@ -0,0 +1,199 @@
/**
* AI Tool definitions for function calling
* These tools allow the AI to interact with the bot's systems
*/
import type { ChatCompletionTool } from "openai/resources/chat/completions";
/**
* Tool call result from execution
*/
export interface ToolResult {
name: string;
result: string;
}
/**
* Tool call request from the AI
*/
export interface ToolCall {
id: string;
name: string;
arguments: Record<string, unknown>;
}
/**
* Context provided to tool handlers
*/
export interface ToolContext {
userId: string;
guildId: string;
channelId: string;
authorName: string;
}
/**
* Tool handler function type
*/
export type ToolHandler = (
args: Record<string, unknown>,
context: ToolContext
) => Promise<string>;
/**
* Available tools for the AI to use
*/
export const JOEL_TOOLS: ChatCompletionTool[] = [
{
type: "function",
function: {
name: "lookup_user_memories",
description: "Look up what you remember about a specific user. Use this when you want to personalize your response with things you know about them, or when they ask if you remember something.",
parameters: {
type: "object",
properties: {
user_id: {
type: "string",
description: "The Discord user ID to look up memories for. Use the current user's ID if looking up the person you're talking to.",
},
category: {
type: "string",
enum: ["personal", "opinion", "fact", "preference", "event", "relationship", "general"],
description: "Filter by category (optional)",
},
limit: {
type: "number",
description: "Maximum number of memories to retrieve (default: 10)",
},
},
required: ["user_id"],
},
},
},
{
type: "function",
function: {
name: "save_memory",
description: "Save something important or interesting about a user for later. Use this when someone reveals personal information, preferences, embarrassing facts, or anything you can use against them later.",
parameters: {
type: "object",
properties: {
user_id: {
type: "string",
description: "The Discord user ID this memory is about",
},
content: {
type: "string",
description: "The fact or information to remember. Be concise but include context.",
},
category: {
type: "string",
enum: ["personal", "opinion", "fact", "preference", "event", "relationship", "general"],
description: "Category of the memory for organization",
},
importance: {
type: "number",
description: "How important this memory is from 1-10. Only memories 5+ will be saved.",
},
},
required: ["user_id", "content"],
},
},
},
{
type: "function",
function: {
name: "search_memories",
description: "Search through all memories for specific topics or keywords. Use this when you want to find if you know anything about a particular subject.",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Search query - keywords or topics to search for",
},
guild_id: {
type: "string",
description: "Limit search to a specific server (optional)",
},
category: {
type: "string",
enum: ["personal", "opinion", "fact", "preference", "event", "relationship", "general"],
description: "Filter by category (optional)",
},
min_importance: {
type: "number",
description: "Minimum importance score to include (1-10)",
},
},
required: ["query"],
},
},
},
{
type: "function",
function: {
name: "get_memory_stats",
description: "Get statistics about memories stored for a user - total count, breakdown by category, average importance.",
parameters: {
type: "object",
properties: {
user_id: {
type: "string",
description: "The Discord user ID to get stats for",
},
},
required: ["user_id"],
},
},
},
{
type: "function",
function: {
name: "forget_user",
description: "Delete all memories about a user. Only use if explicitly asked to forget someone.",
parameters: {
type: "object",
properties: {
user_id: {
type: "string",
description: "The Discord user ID to forget",
},
},
required: ["user_id"],
},
},
},
];
/**
* Subset of tools for memory extraction (lightweight)
*/
export const MEMORY_EXTRACTION_TOOLS: ChatCompletionTool[] = [
{
type: "function",
function: {
name: "extract_memory",
description: "Extract and save a memorable fact from the conversation. Only call this if there's something genuinely worth remembering.",
parameters: {
type: "object",
properties: {
content: {
type: "string",
description: "The fact to remember, written in third person (e.g., 'Loves pineapple on pizza')",
},
category: {
type: "string",
enum: ["personal", "opinion", "fact", "preference", "event", "relationship", "general"],
description: "What type of information this is",
},
importance: {
type: "number",
description: "How important/memorable this is from 1-10. Be honest - mundane chat is 1-3, interesting facts are 4-6, juicy secrets are 7-10.",
},
},
required: ["content", "category", "importance"],
},
},
},
];