From 8d0cca5ae84cecec328df22b7e85cb8ed36267be Mon Sep 17 00:00:00 2001 From: p-sw Date: Thu, 25 Jun 2026 22:12:39 +0900 Subject: [PATCH] feat: implement initiate option in sendMessage --- src/brain/index.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/brain/index.ts b/src/brain/index.ts index 5efd5a4..76e665c 100644 --- a/src/brain/index.ts +++ b/src/brain/index.ts @@ -218,10 +218,11 @@ export class Brain { async sendMessage( history: ReadonlyArray, newMessages: ReadonlyArray, - options: { now?: Date; maxSteps?: number } = {}, + options: { now?: Date; maxSteps?: number; initiate?: boolean } = {}, ): Promise { const now = options.now ?? new Date(); const maxSteps = options.maxSteps ?? 8; + const initiate = options.initiate ?? false; const replyMessages: string[] = []; const tools: ChatFunctionTool[] = buildSendMessageTools(); @@ -237,16 +238,27 @@ export class Brain { const scheduleBlock = await this.buildScheduleBlock(now); const datetimeBlock = formatDatetime(now); - const instruction = await loadPrompt("SEND_MESSAGE"); - const userPrompt = [ - `Current date and time: ${datetimeBlock}`, - scheduleBlock, - memoryBlock, - `Conversation so far:`, - historyBlock.length > 0 ? historyBlock : "(no prior messages)", - `New user message(s) to which you must reply:`, - newBlock.length > 0 ? newBlock : "(none — open turn)", - ].join("\n\n"); + const instruction = initiate + ? await loadPrompt("START_CONVERSATION") + : await loadPrompt("SEND_MESSAGE"); + const userPrompt = initiate + ? [ + `Current date and time: ${datetimeBlock}`, + scheduleBlock, + memoryBlock, + `Conversation so far:`, + historyBlock.length > 0 ? historyBlock : "(no prior messages)", + `You are opening this chat. The user has not sent a message.`, + ].join("\n\n") + : [ + `Current date and time: ${datetimeBlock}`, + scheduleBlock, + memoryBlock, + `Conversation so far:`, + historyBlock.length > 0 ? historyBlock : "(no prior messages)", + `New user message(s) to which you must reply:`, + newBlock.length > 0 ? newBlock : "(none — open turn)", + ].join("\n\n"); const messages: ChatMessages[] = [ {