using System.Text.Json.Serialization; namespace MoneyMap.Services.AITools { /// /// Provider-agnostic tool definition for AI function calling. /// public class AIToolDefinition { public string Name { get; set; } = ""; public string Description { get; set; } = ""; public List Parameters { get; set; } = new(); } public class AIToolParameter { public string Name { get; set; } = ""; public string Type { get; set; } = "string"; // string, number, integer public string Description { get; set; } = ""; public bool Required { get; set; } } /// /// Represents a tool call from the AI model. /// public class AIToolCall { public string Id { get; set; } = ""; public string Name { get; set; } = ""; public Dictionary Arguments { get; set; } = new(); public string? GetString(string key) { if (Arguments.TryGetValue(key, out var val) && val != null) return val.ToString(); return null; } public decimal? GetDecimal(string key) { if (Arguments.TryGetValue(key, out var val) && val != null) { if (decimal.TryParse(val.ToString(), out var d)) return d; } return null; } public int? GetInt(string key) { if (Arguments.TryGetValue(key, out var val) && val != null) { if (int.TryParse(val.ToString(), out var i)) return i; } return null; } } /// /// Result of executing a tool, returned to the AI. /// public class AIToolResult { public string ToolCallId { get; set; } = ""; public string Content { get; set; } = ""; public bool IsError { get; set; } } /// /// Static registry of all tools available to the receipt parsing AI. /// public static class AIToolRegistry { public static List GetAllTools() => new() { new AIToolDefinition { Name = "search_categories", Description = "Search existing expense categories in the system. Returns category names with their matching patterns and associated merchants. Use this to find the correct category name for line items and the overall receipt instead of inventing new ones.", Parameters = new() { new AIToolParameter { Name = "query", Type = "string", Description = "Optional filter text to search category names (e.g., 'grocery', 'utility'). Omit to get all categories.", Required = false } } }, new AIToolDefinition { Name = "search_transactions", Description = "Search bank transactions to find one that matches this receipt. Returns transaction ID, date, amount, name, merchant, and category. Use this to suggest which transaction this receipt belongs to.", Parameters = new() { new AIToolParameter { Name = "merchant", Type = "string", Description = "Merchant or store name to search for (partial match)", Required = false }, new AIToolParameter { Name = "minDate", Type = "string", Description = "Earliest transaction date (YYYY-MM-DD format)", Required = false }, new AIToolParameter { Name = "maxDate", Type = "string", Description = "Latest transaction date (YYYY-MM-DD format)", Required = false }, new AIToolParameter { Name = "minAmount", Type = "number", Description = "Minimum absolute transaction amount", Required = false }, new AIToolParameter { Name = "maxAmount", Type = "number", Description = "Maximum absolute transaction amount", Required = false }, new AIToolParameter { Name = "limit", Type = "integer", Description = "Maximum results to return (default 10, max 20)", Required = false } } }, new AIToolDefinition { Name = "search_merchants", Description = "Search known merchants by name. Returns merchant name, transaction count, and most common category. Use this to find the correct merchant name and see what category is typically used for them.", Parameters = new() { new AIToolParameter { Name = "query", Type = "string", Description = "Merchant name to search for (partial match)", Required = true } } } }; } }