feat: implement initiate option in sendMessage

This commit is contained in:
2026-06-25 22:12:39 +09:00
parent eafb21617d
commit 8d0cca5ae8

View File

@@ -218,10 +218,11 @@ export class Brain {
async sendMessage( async sendMessage(
history: ReadonlyArray<MessageHistoryEntry>, history: ReadonlyArray<MessageHistoryEntry>,
newMessages: ReadonlyArray<MessageHistoryEntry>, newMessages: ReadonlyArray<MessageHistoryEntry>,
options: { now?: Date; maxSteps?: number } = {}, options: { now?: Date; maxSteps?: number; initiate?: boolean } = {},
): Promise<string[]> { ): Promise<string[]> {
const now = options.now ?? new Date(); const now = options.now ?? new Date();
const maxSteps = options.maxSteps ?? 8; const maxSteps = options.maxSteps ?? 8;
const initiate = options.initiate ?? false;
const replyMessages: string[] = []; const replyMessages: string[] = [];
const tools: ChatFunctionTool[] = buildSendMessageTools(); const tools: ChatFunctionTool[] = buildSendMessageTools();
@@ -237,8 +238,19 @@ export class Brain {
const scheduleBlock = await this.buildScheduleBlock(now); const scheduleBlock = await this.buildScheduleBlock(now);
const datetimeBlock = formatDatetime(now); const datetimeBlock = formatDatetime(now);
const instruction = await loadPrompt("SEND_MESSAGE"); const instruction = initiate
const userPrompt = [ ? 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}`, `Current date and time: ${datetimeBlock}`,
scheduleBlock, scheduleBlock,
memoryBlock, memoryBlock,