From 86a6dd48ceb1c2949e29bba569070f8d3ca3f407 Mon Sep 17 00:00:00 2001 From: liugangjian Date: Wed, 4 Mar 2026 20:08:39 +0800 Subject: [PATCH] fix: correctly respect session flag in agent command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the session flag was ignored in the agent command, with custom session keys being replaced by the default routing session. The issue was caused by the code only honoring session keys that started with the prefix 'agent:'. This fix modifies the condition on how the session key is selected to honor any custom session key provided via command line --session flag, regardless of prefix. Now the custom session keys like "foobar" will generate "foobar.json" file instead of "agent_main_main.json". FIXES #1039 🤖 AI Assisted - Human designed the solution, AI helped implement it --- pkg/agent/loop.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index db9efa2cf..cd1b17ce5 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -485,11 +485,13 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage) } } - // Use routed session key, but honor pre-set agent-scoped keys (for ProcessDirect/cron) - sessionKey := route.SessionKey - if msg.SessionKey != "" && strings.HasPrefix(msg.SessionKey, "agent:") { - sessionKey = msg.SessionKey - } + // Use custom session key if provided directly via ProcessDirect, else use route's default + // Previously only honored agent: prefixed keys, now honors all custom keys + sessionKey := route.SessionKey + if msg.SessionKey != "" { + sessionKey = msg.SessionKey + } + logger.InfoCF("agent", "Routed message", map[string]any{