From d46cde8345f3ef0ead2150974fb05b69f118eb4d Mon Sep 17 00:00:00 2001 From: wangyanfu2 Date: Thu, 5 Mar 2026 14:12:48 +0800 Subject: [PATCH] fix(agent): respect --session flag value when routing messages (#1039) When starting the interactive agent with --session , the provided session key was being ignored during routing. The router always fell back to 'agent:main:main' because plain names (without a colon) were not recognized as valid session keys. Root cause: the session key passed via --session flag (e.g. 'foobar') had no namespace prefix, so the routing logic treated it as unresolvable and defaulted to the hardcoded 'agent:main:main' session, causing all conversation history to accumulate in agent_main_main.json regardless of the --session value. Fix: before routing, check if the session key contains a colon; if not, prefix it with 'agent:main:' so that '--session foobar' correctly resolves to 'agent:main:foobar' and the session file is created as expected. --- cmd/picoclaw/internal/agent/helpers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/picoclaw/internal/agent/helpers.go b/cmd/picoclaw/internal/agent/helpers.go index f754abc65..1706fa2eb 100644 --- a/cmd/picoclaw/internal/agent/helpers.go +++ b/cmd/picoclaw/internal/agent/helpers.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/chzyer/readline" - "github.com/sipeed/picoclaw/cmd/picoclaw/internal" "github.com/sipeed/picoclaw/pkg/agent" "github.com/sipeed/picoclaw/pkg/bus" @@ -23,6 +22,11 @@ func agentCmd(message, sessionKey, model string, debug bool) error { sessionKey = "cli:default" } + // If the user provides a plain name (no colon), treat it as a session label + if !strings.Contains(sessionKey, ":") { + sessionKey = fmt.Sprintf("agent:main:%s", sessionKey) + } + if debug { logger.SetLevel(logger.DEBUG) fmt.Println("🔍 Debug mode enabled")