mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-09-04 10:16:46 +00:00
fix(summon): preserve user's custom display_name during summon/regenerate
Previously, finishSummon() and RegenerateAgent() unconditionally overwrote display_name with the LLM-extracted name from IDENTITY.md. Now if the user already set a custom name, it is preserved and IDENTITY.md Name field is synced to match — keeping UI label and agent self-identity consistent.
This commit is contained in:
@@ -191,7 +191,19 @@ func (s *AgentSummoner) finishSummon(ctx context.Context, agentID, tenantID uuid
|
||||
updates["frontmatter"] = frontmatter
|
||||
}
|
||||
if name := extractIdentityName(identityContent); name != "" {
|
||||
updates["display_name"] = name
|
||||
agent, _ := s.agents.GetByID(ctx, agentID)
|
||||
if agent != nil && agent.DisplayName != "" {
|
||||
// User already set a custom name — preserve it, sync IDENTITY.md to match
|
||||
if name != agent.DisplayName {
|
||||
updated := bootstrap.UpdateIdentityField(identityContent, "Name", agent.DisplayName)
|
||||
if updated != identityContent {
|
||||
_ = s.agents.SetAgentContextFile(ctx, agentID, bootstrap.IdentityFile, updated)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No custom name — use LLM-generated name
|
||||
updates["display_name"] = name
|
||||
}
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := s.agents.Update(ctx, agentID, updates); err != nil {
|
||||
|
||||
@@ -56,7 +56,19 @@ func (s *AgentSummoner) RegenerateAgent(agentID uuid.UUID, tenantID uuid.UUID, p
|
||||
updates["frontmatter"] = fm
|
||||
}
|
||||
if name := extractIdentityName(files[bootstrap.IdentityFile]); name != "" {
|
||||
updates["display_name"] = name
|
||||
agent, _ := s.agents.GetByID(ctx, agentID)
|
||||
if agent != nil && agent.DisplayName != "" {
|
||||
// User already set a custom name — preserve it, sync IDENTITY.md to match
|
||||
if name != agent.DisplayName {
|
||||
updated := bootstrap.UpdateIdentityField(files[bootstrap.IdentityFile], "Name", agent.DisplayName)
|
||||
if updated != files[bootstrap.IdentityFile] {
|
||||
_ = s.agents.SetAgentContextFile(ctx, agentID, bootstrap.IdentityFile, updated)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No custom name — use LLM-generated name
|
||||
updates["display_name"] = name
|
||||
}
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := s.agents.Update(ctx, agentID, updates); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user