diff --git a/src/router.ts b/src/router.ts index 6ff75b9..93e6bd3 100644 --- a/src/router.ts +++ b/src/router.ts @@ -87,6 +87,7 @@ export class EventRouter { let collectedText = ''; for await (const msg of runAgent(prompt, { workDir: this.config.workDir, + sessionId: `task-${task.id}`, model: this.config.model, provider: this.config.provider, systemPrompt: this.config.prompt || undefined, @@ -155,9 +156,13 @@ export class EventRouter { this.log.info('│ MESSAGE from @%s: "%s"', authorSlug, content.slice(0, 200)); this.log.info('│ Context: %s | Mentioned: %s', taskId ? `task=${taskId}` : chatId ? `chat=${chatId}` : 'none', isMentioned); + // Stable session ID per chat/task context — preserves conversation history + const sessionId = chatId ? `chat-${chatId}` : taskId ? `task-${taskId}` : `msg-${Date.now()}`; + let collectedText = ''; for await (const msg of runAgent(content, { workDir: this.config.workDir, + sessionId, model: this.config.model, provider: this.config.provider, systemPrompt: this.config.prompt || undefined,