package agents import ( "fmt" "mmgame/internal/scripts" ) type NPCAgent struct { Role *scripts.Role Background string PublicInfo string memory []ChatMessage } func NewNPCAgent(role *scripts.Role, background, publicInfo string) *NPCAgent { return &NPCAgent{Role: role, Background: background, PublicInfo: publicInfo} } func (a *NPCAgent) Respond(phaseName string, recentMessages []map[string]string, playerMessage string, isPrivate bool, knownClues []string, phaseGoal string, allRoles []*scripts.Role) map[string]interface{} { if len(recentMessages) > 5 { recentMessages = recentMessages[len(recentMessages)-5:] } var recent []string for _, m := range recentMessages { sender := m["sender_name"] if sender == "" { sender = m["sender"] } recent = append(recent, fmt.Sprintf("%s: %s", sender, m["content"])) } result := NPCGenerate(a.Role, a.Background, phaseName, recent, playerMessage, isPrivate, knownClues, phaseGoal, allRoles) if content, ok := result["content"].(string); ok && content != "" { a.memory = append(a.memory, ChatMessage{Role: "assistant", Content: content}) return result } return map[string]interface{}{"content": a.Role.Name + "陷入了沉思……", "action": "speak"} }