diff --git a/src/agents/tools/sessions-spawn-tool.ts b/src/agents/tools/sessions-spawn-tool.ts index 6fe582c52..d73b8c4a0 100644 --- a/src/agents/tools/sessions-spawn-tool.ts +++ b/src/agents/tools/sessions-spawn-tool.ts @@ -231,6 +231,10 @@ export function createSessionsSpawnTool(opts?: { message: task, sessionKey: childSessionKey, channel: requesterOrigin?.channel, + to: requesterOrigin?.to ?? undefined, + accountId: requesterOrigin?.accountId ?? undefined, + threadId: + requesterOrigin?.threadId != null ? String(requesterOrigin.threadId) : undefined, idempotencyKey: childIdem, deliver: false, lane: AGENT_LANE_SUBAGENT, diff --git a/src/commands/agent/run-context.ts b/src/commands/agent/run-context.ts index 445e03a5d..cf8dacd71 100644 --- a/src/commands/agent/run-context.ts +++ b/src/commands/agent/run-context.ts @@ -42,5 +42,14 @@ export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext merged.currentThreadTs = String(opts.threadId); } + // Populate currentChannelId from the outbound target so that + // resolveTelegramAutoThreadId can match the originating chat. + if (!merged.currentChannelId && opts.to) { + const trimmedTo = opts.to.trim(); + if (trimmedTo) { + merged.currentChannelId = trimmedTo; + } + } + return merged; }