feat: add assistant bot with LLM integration and configuration
- 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.
This commit is contained in:
+64
-38
@@ -1,4 +1,9 @@
|
||||
// Command launcher starts one or more agents from their config files.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// go run ./cmd/launcher # auto-discovers agents/*/config.yaml
|
||||
// go run ./cmd/launcher -c agents/assistant/config.yaml
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,30 +18,49 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/enmanuel/agents/agents"
|
||||
assistantagent "github.com/enmanuel/agents/agents/assistant"
|
||||
devopsagent "github.com/enmanuel/agents/agents/devops"
|
||||
"github.com/enmanuel/agents/internal/config"
|
||||
"github.com/enmanuel/agents/pkg/decision"
|
||||
)
|
||||
|
||||
// rulesRegistry maps agent IDs to their rule factories.
|
||||
// Add a new entry here when you create a new agent package.
|
||||
var rulesRegistry = map[string]func() []decision.Rule{
|
||||
"assistant-bot": assistantagent.Rules,
|
||||
"devops-bot": devopsagent.Rules,
|
||||
}
|
||||
|
||||
func main() {
|
||||
var configPaths []string
|
||||
var logLevel string
|
||||
var (
|
||||
configPaths []string
|
||||
logLevel string
|
||||
)
|
||||
|
||||
root := &cobra.Command{
|
||||
Use: "launcher",
|
||||
Short: "Start Matrix agents from config files",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
level := slog.LevelInfo
|
||||
if logLevel == "debug" {
|
||||
level = slog.LevelDebug
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(configPaths) == 0 {
|
||||
matches, _ := filepath.Glob("agents/*/config.yaml")
|
||||
configPaths = matches
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger := newLogger(logLevel)
|
||||
|
||||
if len(configPaths) == 0 {
|
||||
logger.Warn("no agent configs found — nothing to start")
|
||||
return nil
|
||||
}
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for _, path := range configPaths {
|
||||
path := path // capture
|
||||
path := path
|
||||
cfg, err := config.Load(path)
|
||||
if err != nil {
|
||||
logger.Error("failed to load config", "path", path, "err", err)
|
||||
@@ -47,10 +71,10 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Load agent-specific rules (extend here with your own rule builders)
|
||||
rules := loadRulesForAgent(cfg)
|
||||
rules := rulesFor(cfg.Agent.ID, logger)
|
||||
agentLogger := logger.With("agent", cfg.Agent.ID)
|
||||
|
||||
agent, err := agents.New(cfg, rules, logger.With("agent", cfg.Agent.ID))
|
||||
a, err := agents.New(cfg, rules, agentLogger)
|
||||
if err != nil {
|
||||
logger.Error("failed to create agent", "id", cfg.Agent.ID, "err", err)
|
||||
continue
|
||||
@@ -59,47 +83,49 @@ func main() {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := agent.Run(ctx); err != nil {
|
||||
logger.Error("agent stopped", "id", cfg.Agent.ID, "err", err)
|
||||
agentLogger.Info("agent running")
|
||||
if err := a.Run(ctx); err != nil {
|
||||
agentLogger.Error("agent stopped with error", "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
logger.Info("all agents stopped")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
root.Flags().StringSliceVarP(&configPaths, "config", "c", nil, "Agent config files (comma-separated or repeated flag)")
|
||||
root.Flags().StringVar(&logLevel, "log-level", "info", "Log level: debug|info|warn|error")
|
||||
|
||||
// Default: discover all config.yaml files under agents/
|
||||
root.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||
if len(configPaths) == 0 {
|
||||
matches, _ := filepath.Glob("agents/*/config.yaml")
|
||||
configPaths = matches
|
||||
}
|
||||
return nil
|
||||
}
|
||||
root.Flags().StringSliceVarP(&configPaths, "config", "c", nil,
|
||||
"Agent config file(s). If omitted, discovers all agents/*/config.yaml")
|
||||
root.Flags().StringVar(&logLevel, "log-level", "info",
|
||||
"Log level: debug | info | warn | error")
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// loadRulesForAgent returns the decision rules for a given agent config.
|
||||
// Extend this function (or use a registry) to wire up agent-specific rules.
|
||||
func loadRulesForAgent(cfg *config.AgentConfig) []decision.Rule {
|
||||
return []decision.Rule{
|
||||
{
|
||||
Name: "help",
|
||||
Match: decision.MatchCommand("help"),
|
||||
Actions: []decision.Action{{
|
||||
Kind: decision.ActionKindReply,
|
||||
Reply: &decision.ReplyAction{
|
||||
Content: "I'm " + cfg.Agent.Name + ". " + cfg.Agent.Description,
|
||||
},
|
||||
}},
|
||||
},
|
||||
func rulesFor(agentID string, logger *slog.Logger) []decision.Rule {
|
||||
factory, ok := rulesRegistry[agentID]
|
||||
if !ok {
|
||||
logger.Warn("no rules registered for agent, using empty ruleset", "id", agentID)
|
||||
return nil
|
||||
}
|
||||
return factory()
|
||||
}
|
||||
|
||||
func newLogger(level string) *slog.Logger {
|
||||
var lvl slog.Level
|
||||
switch level {
|
||||
case "debug":
|
||||
lvl = slog.LevelDebug
|
||||
case "warn":
|
||||
lvl = slog.LevelWarn
|
||||
case "error":
|
||||
lvl = slog.LevelError
|
||||
default:
|
||||
lvl = slog.LevelInfo
|
||||
}
|
||||
return slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: lvl}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user