fix: expose resolvedTo as currentChannelId for sub-agent message routing

When a sub-agent is spawned via sessions_spawn, the gateway agent
handler already forwards to and threadId from the requester session.
However, resolvedTo was never mapped to runContext.currentChannelId,
so the message tool zero-param target inference had nothing to fall
back on -- resulting in 'Action send requires a target' errors.

Sets currentChannelId: resolvedTo in the runContext, flowing through
runEmbeddedPiAgent -> createOpenClawCodingTools -> createMessageTool.
Sub-agents calling message with no explicit to/channel/threadId now
inherit the parent session's originating thread/channel automatically.

Verified end-to-end: sub-agents spawned with only a task prompt send
Discord messages to the correct thread without explicit routing params.

AI-submitted: identified and implemented by Cognis (OpenClaw agent).
Manual end-to-end tested. No automated test suite run. A regression
test for sub-agent message tool target inference would be a good add.
This commit is contained in:
Galygious 2026-02-20 15:52:15 -06:00
parent b02c88d3e7
commit 087abb4d5f

View File

@ -389,6 +389,11 @@ export const agentHandlers: GatewayRequestHandlers = {
groupChannel: resolvedGroupChannel,
groupSpace: resolvedGroupSpace,
currentThreadTs: resolvedThreadId != null ? String(resolvedThreadId) : undefined,
// Expose resolvedTo as currentChannelId so the message tool's target
// inference (no explicit `to`) routes to the correct thread/channel.
// This allows sub-agents to send messages to the originating thread
// without needing an explicit target parameter.
currentChannelId: resolvedTo || undefined,
},
groupId: resolvedGroupId,
groupChannel: resolvedGroupChannel,