From ba196714cc2b59733e63229a914fda70884cb355 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 29 Jan 2026 18:06:49 -0800 Subject: [PATCH] Fix model being overwritten on every message (#32) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The model option was being passed to resumeSession on every message, causing the SDK to update the agent's model configuration each time. This resulted in the agent's model being reset to the config default (e.g., glm-4.7) on every incoming message. Now model is only passed when creating a new agent, not when resuming an existing one. Written by Cameron ◯ Letta Code "The best code is no code at all." - Jeff Atwood --- src/core/bot.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/bot.ts b/src/core/bot.ts index 04d51f6..67def88 100644 --- a/src/core/bot.ts +++ b/src/core/bot.ts @@ -165,11 +165,11 @@ export class LettaBot { // Create or resume session let session: Session; + // Base options for all sessions (model only included for new agents) const baseOptions = { permissionMode: 'bypassPermissions' as const, allowedTools: this.config.allowedTools, cwd: this.config.workingDir, - model: this.config.model, systemPrompt: SYSTEM_PROMPT, }; @@ -181,10 +181,12 @@ export class LettaBot { console.log(`[Bot] Resuming session for agent ${this.store.agentId}`); console.log(`[Bot] LETTA_BASE_URL=${process.env.LETTA_BASE_URL}`); console.log(`[Bot] LETTA_API_KEY=${process.env.LETTA_API_KEY ? '(set)' : '(not set)'}`); + // Don't pass model when resuming - agent already has its model configured session = resumeSession(this.store.agentId, baseOptions); } else { console.log('[Bot] Creating new session'); - session = createSession({ ...baseOptions, memory: loadMemoryBlocks(this.config.agentName) }); + // Only pass model when creating a new agent + session = createSession({ ...baseOptions, model: this.config.model, memory: loadMemoryBlocks(this.config.agentName) }); } console.log(`[Bot] Session object:`, Object.keys(session)); console.log(`[Bot] Session initialized:`, (session as any).initialized); @@ -362,19 +364,21 @@ export class LettaBot { text: string, _context?: TriggerContext ): Promise { + // Base options (model only for new agents) const baseOptions = { permissionMode: 'bypassPermissions' as const, allowedTools: this.config.allowedTools, cwd: this.config.workingDir, - model: this.config.model, systemPrompt: SYSTEM_PROMPT, }; let session: Session; if (this.store.agentId) { + // Don't pass model when resuming - agent already has its model configured session = resumeSession(this.store.agentId, baseOptions); } else { - session = createSession({ ...baseOptions, memory: loadMemoryBlocks(this.config.agentName) }); + // Only pass model when creating a new agent + session = createSession({ ...baseOptions, model: this.config.model, memory: loadMemoryBlocks(this.config.agentName) }); } try {