UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

81 lines (80 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadMemoryTool = exports.LoadMemoryTool = void 0; exports.loadMemory = loadMemory; const FunctionTool_1 = require("./FunctionTool"); /** * Function to load memory by executing a search query * * @param params Parameters for the function * @param params.query The query to search memory for * @param context The tool context * @returns Array of memory results */ async function loadMemory(params, context) { const query = params.query; // Call the search_memory function on the context if (context.searchMemory) { const response = await context.searchMemory(query); return response.memories || []; } else if (typeof context.searchMemory === 'function') { const response = await context.searchMemory(query); return response.memories || []; } // If no memory search function is available, return empty result console.warn('No memory search function available in the context'); return []; } /** * Tool for loading memory based on a query */ class LoadMemoryTool extends FunctionTool_1.FunctionTool { /** * Creates a new load memory tool */ constructor() { super({ name: 'load_memory', description: 'Loads the memory for the current user based on a query', fn: loadMemory, functionDeclaration: { name: 'load_memory', description: 'Loads the memory for the current user based on a query', parameters: { type: 'object', properties: { query: { type: 'string', description: 'The query to search memory for' } }, required: ['query'] } } }); } /** * Process the LLM request to inform the model about memory * * @param params Parameters for processing * @param params.toolContext The tool context * @param params.llmRequest The LLM request to process */ async processLlmRequest({ toolContext, llmRequest }) { // Call the parent class implementation await super.processLlmRequest({ toolContext, llmRequest }); // Tell the model about the memory capability if (llmRequest.appendInstructions) { llmRequest.appendInstructions([` You have memory. You can use it to answer questions. If any questions need you to look up the memory, you should call load_memory function with a query. `]); } } } exports.LoadMemoryTool = LoadMemoryTool; /** * Singleton instance of the Load Memory tool */ exports.loadMemoryTool = new LoadMemoryTool();