fix(agent): fall back to first AGENT line for discovery
This commit is contained in:
parent
f5f1dc9808
commit
abeb2d8e0a
2 changed files with 43 additions and 2 deletions
|
|
@ -99,14 +99,28 @@ func descriptorIdentity(agentID string, definition AgentContextDefinition) (stri
|
||||||
}
|
}
|
||||||
|
|
||||||
if description == "" &&
|
if description == "" &&
|
||||||
definition.Source == AgentDefinitionSourceAgents &&
|
|
||||||
definition.Agent != nil {
|
definition.Agent != nil {
|
||||||
|
if definition.Source == AgentDefinitionSourceAgent {
|
||||||
|
description = firstNonEmptyLine(definition.Agent.Body)
|
||||||
|
} else if definition.Source == AgentDefinitionSourceAgents {
|
||||||
description = firstMeaningfulParagraph(definition.Agent.Body)
|
description = firstMeaningfulParagraph(definition.Agent.Body)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return name, description
|
return name, description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func firstNonEmptyLine(content string) string {
|
||||||
|
content = strings.ReplaceAll(content, "\r\n", "\n")
|
||||||
|
for _, line := range strings.Split(content, "\n") {
|
||||||
|
trimmed := strings.TrimSpace(line)
|
||||||
|
if trimmed != "" {
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func firstMeaningfulParagraph(content string) string {
|
func firstMeaningfulParagraph(content string) string {
|
||||||
content = strings.ReplaceAll(content, "\r\n", "\n")
|
content = strings.ReplaceAll(content, "\r\n", "\n")
|
||||||
paragraphs := strings.Split(content, "\n\n")
|
paragraphs := strings.Split(content, "\n\n")
|
||||||
|
|
|
||||||
|
|
@ -178,3 +178,30 @@ Generalist.
|
||||||
t.Fatalf("did not expect discovery section for singleton registry, got %q", systemPrompt)
|
t.Fatalf("did not expect discovery section for singleton registry, got %q", systemPrompt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAgentRegistry_ListAgentsFallsBackToFirstNonEmptyAgentLine(t *testing.T) {
|
||||||
|
workspace := setupWorkspace(t, map[string]string{
|
||||||
|
"AGENT.md": `---
|
||||||
|
name: Research Agent
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
First useful line.
|
||||||
|
Second line.
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
defer cleanupWorkspace(t, workspace)
|
||||||
|
|
||||||
|
cfg := testCfg([]config.AgentConfig{
|
||||||
|
{ID: "research", Default: true, Workspace: workspace},
|
||||||
|
})
|
||||||
|
|
||||||
|
registry := NewAgentRegistry(cfg, &mockRegistryProvider{})
|
||||||
|
descriptor, ok := registry.GetAgentDescriptor("research")
|
||||||
|
if !ok || descriptor == nil {
|
||||||
|
t.Fatal("expected research descriptor lookup to succeed")
|
||||||
|
}
|
||||||
|
if descriptor.Description != "First useful line." {
|
||||||
|
t.Fatalf("descriptor.Description = %q, want %q", descriptor.Description, "First useful line.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue