fix: route delegate session keys to correct agent loop (#127)

Delegate session keys (delegate:{uuid8}:{agentKey}:{delegationId}) were
not parsed by makeSchedulerRunFunc, causing fallback to default agent ID
which doesn't exist in managed-mode DBs. Add switch/case to handle both
agent: and delegate: prefixes.
This commit is contained in:
Viet Tran
2026-03-11 07:57:51 +07:00
committed by GitHub
parent 8ad580521d
commit cc00a6f193
+13 -3
View File
@@ -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)