diff --git a/cmd/gateway_consumer_process.go b/cmd/gateway_consumer_process.go index f67143ef..4b5f5439 100644 --- a/cmd/gateway_consumer_process.go +++ b/cmd/gateway_consumer_process.go @@ -14,10 +14,20 @@ import ( // It extracts the agentID from the session key and routes to the correct agent loop. func makeSchedulerRunFunc(agents *agent.Router, cfg *config.Config) scheduler.RunFunc { return func(ctx context.Context, req agent.RunRequest) (*agent.RunResult, error) { - // Extract agentID from session key (format: agent:{agentId}:{rest}) + // Extract agentID from session key. + // Supported formats: + // agent:{agentId}:{rest} + // delegate:{sourceUUID8}:{targetAgentKey}:{delegationId} agentID := cfg.ResolveDefaultAgentID() - if parts := strings.SplitN(req.SessionKey, ":", 3); len(parts) >= 2 && parts[0] == "agent" { - agentID = parts[1] + if parts := strings.SplitN(req.SessionKey, ":", 4); len(parts) >= 2 { + switch parts[0] { + case "agent": + agentID = parts[1] + case "delegate": + if len(parts) >= 3 { + agentID = parts[2] + } + } } loop, err := agents.Get(agentID)