Skip to content

Commit 5d57b1a

Browse files
author
OpenClaw-User
committed
Merge PR sipeed#1401
2 parents 0c5d750 + e666a98 commit 5d57b1a

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

pkg/agent/loop.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ type processOptions struct {
6868

6969
const (
7070
defaultResponse = "I've completed processing but have no response to give. Increase `max_tool_iterations` in config.json."
71-
sessionKeyAgentPrefix = "agent:"
7271
metadataKeyAccountID = "account_id"
7372
metadataKeyGuildID = "guild_id"
7473
metadataKeyTeamID = "team_id"
@@ -774,7 +773,7 @@ func (al *AgentLoop) resolveMessageRoute(msg bus.InboundMessage) (routing.Resolv
774773
}
775774

776775
func resolveScopeKey(route routing.ResolvedRoute, msgSessionKey string) string {
777-
if msgSessionKey != "" && strings.HasPrefix(msgSessionKey, sessionKeyAgentPrefix) {
776+
if msgSessionKey != "" {
778777
return msgSessionKey
779778
}
780779
return route.SessionKey

pkg/agent/loop_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,59 @@ func TestProcessMessage_UsesRouteSessionKey(t *testing.T) {
439439
}
440440
}
441441

442+
func TestProcessDirectWithChannel_PreservesExplicitSessionKey(t *testing.T) {
443+
tmpDir, err := os.MkdirTemp("", "agent-test-*")
444+
if err != nil {
445+
t.Fatalf("Failed to create temp dir: %v", err)
446+
}
447+
defer os.RemoveAll(tmpDir)
448+
449+
cfg := &config.Config{
450+
Agents: config.AgentsConfig{
451+
Defaults: config.AgentDefaults{
452+
Workspace: tmpDir,
453+
Model: "test-model",
454+
MaxTokens: 4096,
455+
MaxToolIterations: 10,
456+
},
457+
},
458+
}
459+
460+
msgBus := bus.NewMessageBus()
461+
provider := &simpleMockProvider{response: "ok"}
462+
al := NewAgentLoop(cfg, msgBus, provider)
463+
464+
const sessionKey = "custom-session"
465+
response, err := al.ProcessDirectWithChannel(
466+
context.Background(),
467+
"hello",
468+
sessionKey,
469+
"cli",
470+
"direct",
471+
)
472+
if err != nil {
473+
t.Fatalf("ProcessDirectWithChannel() error = %v", err)
474+
}
475+
if response != "ok" {
476+
t.Fatalf("response = %q, want %q", response, "ok")
477+
}
478+
479+
defaultAgent := al.registry.GetDefaultAgent()
480+
if defaultAgent == nil {
481+
t.Fatal("No default agent found")
482+
}
483+
history := defaultAgent.Sessions.GetHistory(sessionKey)
484+
if len(history) != 2 {
485+
t.Fatalf("history len = %d, want 2", len(history))
486+
}
487+
if history[0].Role != "user" || history[0].Content != "hello" {
488+
t.Fatalf("unexpected user message: %+v", history[0])
489+
}
490+
if history[1].Role != "assistant" || history[1].Content != "ok" {
491+
t.Fatalf("unexpected assistant message: %+v", history[1])
492+
}
493+
}
494+
442495
func TestProcessMessage_CommandOutcomes(t *testing.T) {
443496
tmpDir, err := os.MkdirTemp("", "agent-test-*")
444497
if err != nil {

0 commit comments

Comments
 (0)