Unify agent topology and subagent memory logging

This commit is contained in:
lpf
2026-03-06 15:14:58 +08:00
parent 86691f75d0
commit cc04d9ab3a
27 changed files with 1408 additions and 791 deletions

View File

@@ -68,6 +68,9 @@ type AgentCommunicationConfig struct {
type SubagentConfig struct {
Enabled bool `json:"enabled"`
Type string `json:"type,omitempty"`
Transport string `json:"transport,omitempty"`
NodeID string `json:"node_id,omitempty"`
ParentAgentID string `json:"parent_agent_id,omitempty"`
DisplayName string `json:"display_name,omitempty"`
Role string `json:"role,omitempty"`
Description string `json:"description,omitempty"`

View File

@@ -301,6 +301,17 @@ func validateSubagents(cfg *Config) []error {
errs = append(errs, fmt.Errorf("agents.subagents.%s.type must be one of: router, worker, reviewer, observer", id))
}
}
transport := strings.TrimSpace(raw.Transport)
if transport != "" {
switch transport {
case "local", "node":
default:
errs = append(errs, fmt.Errorf("agents.subagents.%s.transport must be one of: local, node", id))
}
}
if transport == "node" && strings.TrimSpace(raw.NodeID) == "" {
errs = append(errs, fmt.Errorf("agents.subagents.%s.node_id is required when transport=node", id))
}
if raw.Runtime.TimeoutSec < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.runtime.timeout_sec must be >= 0", id))
}
@@ -322,7 +333,7 @@ func validateSubagents(cfg *Config) []error {
if raw.Tools.MaxParallelCalls < 0 {
errs = append(errs, fmt.Errorf("agents.subagents.%s.tools.max_parallel_calls must be >= 0", id))
}
if raw.Enabled && strings.TrimSpace(raw.SystemPromptFile) == "" {
if raw.Enabled && transport != "node" && strings.TrimSpace(raw.SystemPromptFile) == "" {
errs = append(errs, fmt.Errorf("agents.subagents.%s.system_prompt_file is required when enabled=true", id))
}
if promptFile := strings.TrimSpace(raw.SystemPromptFile); promptFile != "" {

View File

@@ -78,3 +78,26 @@ func TestValidateSubagentsRequiresPromptFileWhenEnabled(t *testing.T) {
t.Fatalf("expected validation errors")
}
}
func TestValidateNodeBackedSubagentAllowsMissingPromptFile(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
cfg.Agents.Router.Enabled = true
cfg.Agents.Router.MainAgentID = "main"
cfg.Agents.Subagents["main"] = SubagentConfig{
Enabled: true,
Type: "router",
SystemPromptFile: "agents/main/AGENT.md",
}
cfg.Agents.Subagents["node.edge.main"] = SubagentConfig{
Enabled: true,
Type: "worker",
Transport: "node",
NodeID: "edge",
}
if errs := Validate(cfg); len(errs) != 0 {
t.Fatalf("expected node-backed config to be valid, got %v", errs)
}
}