mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(agent): fall back to first AGENT line for discovery
This commit is contained in:
+16
-2
@@ -99,14 +99,28 @@ func descriptorIdentity(agentID string, definition AgentContextDefinition) (stri
|
||||
}
|
||||
|
||||
if description == "" &&
|
||||
definition.Source == AgentDefinitionSourceAgents &&
|
||||
definition.Agent != nil {
|
||||
description = firstMeaningfulParagraph(definition.Agent.Body)
|
||||
if definition.Source == AgentDefinitionSourceAgent {
|
||||
description = firstNonEmptyLine(definition.Agent.Body)
|
||||
} else if definition.Source == AgentDefinitionSourceAgents {
|
||||
description = firstMeaningfulParagraph(definition.Agent.Body)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
content = strings.ReplaceAll(content, "\r\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)
|
||||
}
|
||||
}
|
||||
|
||||
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.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user