From 0b44de5f5d6d5aed79b74491a424821ebe6e96d8 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 17 Nov 2025 18:43:48 -0800 Subject: [PATCH] fix: Update sleeptime agent's persona block, not primary agent (#100) Co-authored-by: Letta Co-authored-by: cpacker --- src/agent/create.ts | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/agent/create.ts b/src/agent/create.ts index 7663a59..f1f555f 100644 --- a/src/agent/create.ts +++ b/src/agent/create.ts @@ -237,15 +237,35 @@ export async function createAgent( } } - // Update persona block for sleeptime agents (only if persona was newly created, not shared) - if (enableSleeptime && newGlobalBlockIds.persona) { - await client.agents.blocks.modify("memory_persona", { - agent_id: agent.id, - value: SLEEPTIME_MEMORY_PERSONA, - description: "Instructions for the sleep-time memory management agent", - }); + // Always retrieve the agent to ensure we get the full state with populated memory blocks + const fullAgent = await client.agents.retrieve(agent.id, { + include: ["agent.managed_group"], + }); + + // Update persona block for sleeptime agent (only if persona was newly created, not shared) + if (enableSleeptime && newGlobalBlockIds.persona && fullAgent.managed_group) { + // Find the sleeptime agent in the managed group by checking agent_type + for (const groupAgentId of fullAgent.managed_group.agent_ids) { + try { + const groupAgent = await client.agents.retrieve(groupAgentId); + if (groupAgent.agent_type === "sleeptime_agent") { + // Update the persona block on the SLEEPTIME agent, not the primary agent + await client.agents.blocks.modify("memory_persona", { + agent_id: groupAgentId, + value: SLEEPTIME_MEMORY_PERSONA, + description: + "Instructions for the sleep-time memory management agent", + }); + break; // Found and updated sleeptime agent + } + } catch (error) { + console.warn( + `Failed to check/update agent ${groupAgentId}:`, + error instanceof Error ? error.message : String(error), + ); + } + } } - // Always retrieve the agent to ensure we get the full state with populated memory blocks - return await client.agents.retrieve(agent.id); + return fullAgent; }