fc644ecd6e
Reemplaza el scaffold del echobot por la plataforma completa de bots traida desde ~/DataProyects/Github/agents_and_robots tras la operacion Matrix-out: los bots ya no hablan por Matrix sino por el bus unibus (modelo todo-rooms + E2E via shell/transportunibus sobre github.com/enmanuel/unibus/pkg/client). - go.mod: replace de unibus -> ../unibus y de fn-registry -> ../../../.. (paths relativos reajustados a la nueva ubicacion dentro de fn_registry). - app.md: bump a 0.2.0, descripcion + arquitectura + comandos + gotchas reales. - modulo Go conservado como github.com/enmanuel/agents (sin reescribir imports). agents_and_robots queda archivado como museo de la era Matrix.
102 lines
2.7 KiB
Go
102 lines
2.7 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// Load reads and parses an agent config file from the given path.
|
|
func Load(path string) (*AgentConfig, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read config %s: %w", path, err)
|
|
}
|
|
|
|
// Expand environment variables in the raw YAML bytes.
|
|
expanded := os.ExpandEnv(string(data))
|
|
|
|
var cfg AgentConfig
|
|
if err := yaml.Unmarshal([]byte(expanded), &cfg); err != nil {
|
|
return nil, fmt.Errorf("parse config %s: %w", path, err)
|
|
}
|
|
|
|
if err := validate(&cfg); err != nil {
|
|
return nil, fmt.Errorf("invalid config %s: %w", path, err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// LoadMeta reads only the `agent:` block from a config file without expanding
|
|
// env vars or running full validation. Used by agentctl list to show all
|
|
// agents regardless of whether their env vars are configured.
|
|
func LoadMeta(path string) (*AgentConfig, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read config %s: %w", path, err)
|
|
}
|
|
var cfg AgentConfig
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("parse config %s: %w", path, err)
|
|
}
|
|
if cfg.Agent.ID == "" {
|
|
return nil, fmt.Errorf("agent.id is required")
|
|
}
|
|
return &cfg, nil
|
|
}
|
|
|
|
// LoadSpecial reads and parses a special agent config file.
|
|
// Special agents have no Matrix identity so validation is lighter.
|
|
func LoadSpecial(path string) (*SpecialConfig, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read special config %s: %w", path, err)
|
|
}
|
|
|
|
expanded := os.ExpandEnv(string(data))
|
|
|
|
var cfg SpecialConfig
|
|
if err := yaml.Unmarshal([]byte(expanded), &cfg); err != nil {
|
|
return nil, fmt.Errorf("parse special config %s: %w", path, err)
|
|
}
|
|
|
|
if err := validateSpecial(&cfg); err != nil {
|
|
return nil, fmt.Errorf("invalid special config %s: %w", path, err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// validateSpecial applies sanity checks for special agent configs.
|
|
func validateSpecial(cfg *SpecialConfig) error {
|
|
if cfg.Special.ID == "" {
|
|
return fmt.Errorf("special.id is required")
|
|
}
|
|
if cfg.Special.Type == "" {
|
|
return fmt.Errorf("special.type is required")
|
|
}
|
|
if cfg.LLM.Primary.Provider == "" {
|
|
return fmt.Errorf("llm.primary.provider is required")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// validate applies basic sanity checks.
|
|
func validate(cfg *AgentConfig) error {
|
|
if cfg.Agent.ID == "" {
|
|
return fmt.Errorf("agent.id is required")
|
|
}
|
|
if cfg.Bus.NatsURL == "" {
|
|
return fmt.Errorf("bus.nats_url is required")
|
|
}
|
|
if cfg.Bus.CtrlURL == "" {
|
|
return fmt.Errorf("bus.ctrl_url is required")
|
|
}
|
|
if cfg.LLM.Primary.Provider == "" {
|
|
return fmt.Errorf("llm.primary.provider is required")
|
|
}
|
|
return nil
|
|
}
|