This commit is contained in:
lpf
2026-02-17 00:14:12 +08:00
parent ff3ae92acd
commit e5a3ea6863
3 changed files with 93 additions and 40 deletions

View File

@@ -800,6 +800,10 @@ func isAutonomySyntheticMessage(msg bus.InboundMessage) bool {
return strings.EqualFold(strings.TrimSpace(msg.Metadata["source"]), "autonomy") return strings.EqualFold(strings.TrimSpace(msg.Metadata["source"]), "autonomy")
} }
func shouldHandleControlIntents(msg bus.InboundMessage) bool {
return !isSyntheticMessage(msg)
}
func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) { func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) {
msg := bus.InboundMessage{ msg := bus.InboundMessage{
Channel: "cli", Channel: "cli",
@@ -827,18 +831,25 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
defer al.finishAutonomyRound(msg.SessionKey) defer al.finishAutonomyRound(msg.SessionKey)
} }
controlEligible := shouldHandleControlIntents(msg)
// Route system messages to processSystemMessage // Route system messages to processSystemMessage
if msg.Channel == "system" { if msg.Channel == "system" {
return al.processSystemMessage(ctx, msg) return al.processSystemMessage(ctx, msg)
} }
// Built-in slash commands (deterministic, no LLM roundtrip) // Built-in slash commands (deterministic, no LLM roundtrip)
if controlEligible {
if handled, result, err := al.handleSlashCommand(msg); handled { if handled, result, err := al.handleSlashCommand(msg); handled {
return result, err return result, err
} }
}
if controlEligible {
al.noteAutonomyUserActivity(msg) al.noteAutonomyUserActivity(msg)
}
if controlEligible {
if intent, ok := al.detectAutonomyIntent(ctx, msg.Content); ok { if intent, ok := al.detectAutonomyIntent(ctx, msg.Content); ok {
switch intent.action { switch intent.action {
case "start": case "start":
@@ -879,6 +890,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
return al.autoLearnerStatus(msg.SessionKey), nil return al.autoLearnerStatus(msg.SessionKey), nil
} }
} }
}
directives := parseTaskExecutionDirectives(msg.Content) directives := parseTaskExecutionDirectives(msg.Content)
if inferred, ok := al.inferTaskExecutionDirectives(ctx, msg.Content); ok { if inferred, ok := al.inferTaskExecutionDirectives(ctx, msg.Content); ok {
@@ -891,7 +903,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
if strings.TrimSpace(userPrompt) == "" { if strings.TrimSpace(userPrompt) == "" {
userPrompt = msg.Content userPrompt = msg.Content
} }
if al.isAutonomyEnabled(msg.SessionKey) && !isSyntheticMessage(msg) { if al.isAutonomyEnabled(msg.SessionKey) && controlEligible {
directives.stageReport = true directives.stageReport = true
userPrompt = buildAutonomyTaskPrompt(userPrompt) userPrompt = buildAutonomyTaskPrompt(userPrompt)
} }

View File

@@ -3,6 +3,8 @@ package agent
import ( import (
"testing" "testing"
"time" "time"
"clawgo/pkg/bus"
) )
func TestParseTaskExecutionDirectives_RunCommand(t *testing.T) { func TestParseTaskExecutionDirectives_RunCommand(t *testing.T) {
@@ -152,3 +154,36 @@ func TestExtractJSONObject_Invalid(t *testing.T) {
t.Fatalf("expected empty json, got: %q", raw) t.Fatalf("expected empty json, got: %q", raw)
} }
} }
func TestShouldHandleControlIntents_UserMessage(t *testing.T) {
msg := bus.InboundMessage{
SenderID: "user",
Content: "请进入自主模式",
}
if !shouldHandleControlIntents(msg) {
t.Fatalf("expected user message to be control-eligible")
}
}
func TestShouldHandleControlIntents_AutonomySyntheticSender(t *testing.T) {
msg := bus.InboundMessage{
SenderID: "autonomy",
Content: "自主模式第 1 轮推进",
}
if shouldHandleControlIntents(msg) {
t.Fatalf("expected autonomy synthetic message to be ignored for control intents")
}
}
func TestShouldHandleControlIntents_AutoLearnSyntheticMetadata(t *testing.T) {
msg := bus.InboundMessage{
SenderID: "gateway",
Content: "自动学习第 1 轮",
Metadata: map[string]string{
"source": "autolearn",
},
}
if shouldHandleControlIntents(msg) {
t.Fatalf("expected autolearn synthetic metadata message to be ignored for control intents")
}
}

View File

@@ -328,6 +328,12 @@ func (c *TelegramChannel) handleMessage(runCtx context.Context, message *telego.
if user == nil { if user == nil {
return return
} }
if user.IsBot {
logger.DebugCF("telegram", "Ignoring bot-originated message", map[string]interface{}{
"user_id": user.ID,
})
return
}
senderID := fmt.Sprintf("%d", user.ID) senderID := fmt.Sprintf("%d", user.ID)