From c4dfc1b0d1948d498ca5a080bd063491e60f65e2 Mon Sep 17 00:00:00 2001 From: mingmxren Date: Wed, 4 Mar 2026 16:08:48 +0800 Subject: [PATCH] fix(agent): handle commands before route error check Move handleCommand() before the routeErr gate so global commands (/help, /show, /switch) remain available even when routing fails. Context-dependent commands that need a routed agent will report "unavailable" through their nil-Runtime guards. Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index f51f38f6a..c6cfd9604 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -532,16 +532,20 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage) return al.processSystemMessage(ctx, msg) } - route, agent, err := al.resolveMessageRoute(msg) - if err != nil { - return "", err - } + route, agent, routeErr := al.resolveMessageRoute(msg) - // Check for commands + // Commands are checked before requiring a successful route. + // Global commands (/help, /show, /switch) work even when routing fails; + // context-dependent commands check their own Runtime fields and report + // "unavailable" when the required capability is nil. if response, handled := al.handleCommand(ctx, msg); handled { return response, nil } + if routeErr != nil { + return "", routeErr + } + // Reset message-tool state for this round so we don't skip publishing due to a previous round. if tool, ok := agent.Tools.Get("message"); ok { if resetter, ok := tool.(interface{ ResetSentInRound() }); ok {