From 34f6d821b9034602bb1f03a5103470a801e0dafe Mon Sep 17 00:00:00 2001 From: mudler Date: Fri, 19 Apr 2024 13:17:08 +0200 Subject: [PATCH] more logging --- Makefile | 5 ++- example/webui/agentpool.go | 4 ++ example/webui/connector/discord.go | 4 ++ example/webui/connector/githubissue.go | 54 ++++++++++++++++++-------- xlog/xlog.go | 1 - 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index ccf7b65..4e86fc4 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,7 @@ webui: cd example/webui && $(GOCMD) run ./ webui-image: - docker build -t $(IMAGE_NAME) -f Dockerfile.webui . \ No newline at end of file + docker build -t $(IMAGE_NAME) -f Dockerfile.webui . + +webui-push: + docker push $(IMAGE_NAME) diff --git a/example/webui/agentpool.go b/example/webui/agentpool.go index 821370e..bce6b07 100644 --- a/example/webui/agentpool.go +++ b/example/webui/agentpool.go @@ -10,6 +10,7 @@ import ( "sync" "time" + "github.com/mudler/local-agent-framework/agent" "github.com/mudler/local-agent-framework/xlog" . "github.com/mudler/local-agent-framework/agent" @@ -169,6 +170,9 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error WithContext(ctx), WithPeriodicRuns(config.PeriodicRuns), WithPermanentGoal(config.PermanentGoal), + WithCharacter(agent.Character{ + Name: name, + }), WithActions( actions..., ), diff --git a/example/webui/connector/discord.go b/example/webui/connector/discord.go index ffd1bd8..832c20f 100644 --- a/example/webui/connector/discord.go +++ b/example/webui/connector/discord.go @@ -13,6 +13,10 @@ type Discord struct { defaultChannel string } +// NewDiscord creates a new Discord connector +// with the given configuration +// - token: Discord token +// - defaultChannel: Discord channel to always answer even if not mentioned func NewDiscord(config map[string]string) *Discord { return &Discord{ token: config["token"], diff --git a/example/webui/connector/githubissue.go b/example/webui/connector/githubissue.go index 46325ca..3883869 100644 --- a/example/webui/connector/githubissue.go +++ b/example/webui/connector/githubissue.go @@ -13,27 +13,40 @@ import ( ) type GithubIssues struct { - token string - repository string - owner string - agent *agent.Agent - pollInterval time.Duration - client *github.Client + token string + repository string + owner string + replyIfNoReplies bool + agent *agent.Agent + pollInterval time.Duration + client *github.Client } +// NewGithubIssueWatcher creates a new GithubIssues connector +// with the given configuration +// - token: Github token +// - repository: Github repository name +// - owner: Github repository owner +// - replyIfNoReplies: If true, the bot will reply to issues with no comments func NewGithubIssueWatcher(config map[string]string) *GithubIssues { client := github.NewClient(nil).WithAuthToken(config["token"]) + replyIfNoReplies := false + if config["replyIfNoReplies"] == "true" { + replyIfNoReplies = true + } + interval, err := time.ParseDuration(config["pollInterval"]) if err != nil { - interval = 1 * time.Minute + interval = 10 * time.Minute } return &GithubIssues{ - client: client, - token: config["token"], - repository: config["repository"], - owner: config["owner"], - pollInterval: interval, + client: client, + token: config["token"], + repository: config["repository"], + owner: config["owner"], + replyIfNoReplies: replyIfNoReplies, + pollInterval: interval, } } @@ -144,12 +157,19 @@ func (g *GithubIssues) issuesService() { if len(comments) == 0 || !botAnsweredAlready { // if no comments, or bot didn't answer yet, we must answer - xlog.Info("No comments, or bot didn't answer yet") - xlog.Info("Comments:", len(comments)) - xlog.Info("Bot answered already", botAnsweredAlready) + xlog.Info("No comments, or bot didn't answer yet", + "comments", len(comments), + "botAnsweredAlready", botAnsweredAlready, + "agent", g.agent.Character.Name, + ) mustAnswer = true } + if len(comments) != 0 && g.replyIfNoReplies { + xlog.Info("Ignoring issue with comments", "issue", issue.GetNumber(), "agent", g.agent.Character.Name) + mustAnswer = false + } + if !mustAnswer { continue } @@ -158,7 +178,7 @@ func (g *GithubIssues) issuesService() { agent.WithConversationHistory(messages), ) if res.Error != nil { - xlog.Error("Error asking", "error", res.Error) + xlog.Error("Error asking", "error", res.Error, "agent", g.agent.Character.Name) return } @@ -170,7 +190,7 @@ func (g *GithubIssues) issuesService() { }, ) if err != nil { - xlog.Error("Error creating comment", "error", err) + xlog.Error("Error creating comment", "error", err, "agent", g.agent.Character.Name) } } } diff --git a/xlog/xlog.go b/xlog/xlog.go index e896c80..8a61f52 100644 --- a/xlog/xlog.go +++ b/xlog/xlog.go @@ -60,7 +60,6 @@ func Info(msg string, args ...any) { func Debug(msg string, args ...any) { _log(slog.LevelDebug, msg, args...) - logger.Debug(msg, args...) } func Error(msg string, args ...any) {