bd8e1432e5
- Implemented the assistant bot with basic command handling and LLM routing. - Created configuration file for the assistant bot with personality, behavior, and LLM settings. - Added system prompt for the assistant bot to define its capabilities and limitations. - Developed registration script for creating Matrix bot users via Synapse admin API. - Introduced common development scripts for agent management (start, stop, list, logs). - Scaffolded new agent creation script to streamline the addition of new agents. - Implemented agent removal script to disable agents without deleting data.
66 lines
1.7 KiB
Go
66 lines
1.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
|
|
}
|
|
|
|
// validate applies basic sanity checks.
|
|
func validate(cfg *AgentConfig) error {
|
|
if cfg.Agent.ID == "" {
|
|
return fmt.Errorf("agent.id is required")
|
|
}
|
|
if cfg.Matrix.Homeserver == "" {
|
|
return fmt.Errorf("matrix.homeserver is required")
|
|
}
|
|
if cfg.Matrix.UserID == "" {
|
|
return fmt.Errorf("matrix.user_id is required")
|
|
}
|
|
if cfg.LLM.Primary.Provider == "" {
|
|
return fmt.Errorf("llm.primary.provider is required")
|
|
}
|
|
return nil
|
|
}
|