fix: preserve subagent thread routing (#1241)

Thanks @gnarco.

Co-authored-by: gnarco <gnarco@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-20 17:22:07 +00:00
parent ae1c6f4313
commit 02ca148583
32 changed files with 195 additions and 32 deletions

View File

@@ -57,6 +57,7 @@ export const AgentParamsSchema = Type.Object(
replyChannel: Type.Optional(Type.String()),
accountId: Type.Optional(Type.String()),
replyAccountId: Type.Optional(Type.String()),
threadId: Type.Optional(Type.String()),
timeout: Type.Optional(Type.Integer({ minimum: 0 })),
lane: Type.Optional(Type.String()),
extraSystemPrompt: Type.Optional(Type.String()),

View File

@@ -71,6 +71,7 @@ export const agentHandlers: GatewayRequestHandlers = {
replyChannel?: string;
accountId?: string;
replyAccountId?: string;
threadId?: string;
lane?: string;
extraSystemPrompt?: string;
idempotencyKey: string;
@@ -257,10 +258,15 @@ export const agentHandlers: GatewayRequestHandlers = {
: typeof request.to === "string" && request.to.trim()
? request.to.trim()
: undefined;
const explicitThreadId =
typeof request.threadId === "string" && request.threadId.trim()
? request.threadId.trim()
: undefined;
const deliveryPlan = resolveAgentDeliveryPlan({
sessionEntry,
requestedChannel: request.replyChannel ?? request.channel,
explicitTo,
explicitThreadId,
accountId: request.replyAccountId ?? request.accountId,
wantsDelivery,
});
@@ -298,6 +304,8 @@ export const agentHandlers: GatewayRequestHandlers = {
});
respond(true, accepted, undefined, { runId });
const resolvedThreadId = explicitThreadId ?? deliveryPlan.resolvedThreadId;
void agentCommand(
{
message,
@@ -310,9 +318,11 @@ export const agentHandlers: GatewayRequestHandlers = {
deliveryTargetMode,
channel: resolvedChannel,
accountId: resolvedAccountId,
threadId: resolvedThreadId,
runContext: {
messageChannel: resolvedChannel,
accountId: resolvedAccountId,
currentThreadTs: resolvedThreadId != null ? String(resolvedThreadId) : undefined,
},
timeout: request.timeout?.toString(),
bestEffortDeliver,