Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/agent/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type processOptions struct {

const (
defaultResponse = "I've completed processing but have no response to give. Increase `max_tool_iterations` in config.json."
sessionKeyAgentPrefix = "agent:"
metadataKeyAccountID = "account_id"
metadataKeyGuildID = "guild_id"
metadataKeyTeamID = "team_id"
Expand Down Expand Up @@ -753,7 +752,7 @@ func (al *AgentLoop) resolveMessageRoute(msg bus.InboundMessage) (routing.Resolv
}

func resolveScopeKey(route routing.ResolvedRoute, msgSessionKey string) string {
if msgSessionKey != "" && strings.HasPrefix(msgSessionKey, sessionKeyAgentPrefix) {
if msgSessionKey != "" {
return msgSessionKey
}
return route.SessionKey
Expand Down
53 changes: 53 additions & 0 deletions pkg/agent/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,59 @@ func TestProcessMessage_UsesRouteSessionKey(t *testing.T) {
}
}

func TestProcessDirectWithChannel_PreservesExplicitSessionKey(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "agent-test-*")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)

cfg := &config.Config{
Agents: config.AgentsConfig{
Defaults: config.AgentDefaults{
Workspace: tmpDir,
Model: "test-model",
MaxTokens: 4096,
MaxToolIterations: 10,
},
},
}

msgBus := bus.NewMessageBus()
provider := &simpleMockProvider{response: "ok"}
al := NewAgentLoop(cfg, msgBus, provider)

const sessionKey = "custom-session"
response, err := al.ProcessDirectWithChannel(
context.Background(),
"hello",
sessionKey,
"cli",
"direct",
)
if err != nil {
t.Fatalf("ProcessDirectWithChannel() error = %v", err)
}
if response != "ok" {
t.Fatalf("response = %q, want %q", response, "ok")
}

defaultAgent := al.registry.GetDefaultAgent()
if defaultAgent == nil {
t.Fatal("No default agent found")
}
history := defaultAgent.Sessions.GetHistory(sessionKey)
if len(history) != 2 {
t.Fatalf("history len = %d, want 2", len(history))
}
if history[0].Role != "user" || history[0].Content != "hello" {
t.Fatalf("unexpected user message: %+v", history[0])
}
if history[1].Role != "assistant" || history[1].Content != "ok" {
t.Fatalf("unexpected assistant message: %+v", history[1])
}
}

func TestProcessMessage_CommandOutcomes(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "agent-test-*")
if err != nil {
Expand Down