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:
viettranx
2026-04-02 11:04:56 +07:00
parent 9d74e39625
commit ecf6463d98
2 changed files with 26 additions and 2 deletions
+13 -1
View File
@@ -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 {
+13 -1
View File
@@ -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 {