more logging

This commit is contained in:
mudler
2024-04-19 13:17:08 +02:00
parent e2aa3bedd7
commit 34f6d821b9
5 changed files with 49 additions and 19 deletions

View File

@@ -12,3 +12,6 @@ webui:
webui-image: webui-image:
docker build -t $(IMAGE_NAME) -f Dockerfile.webui . docker build -t $(IMAGE_NAME) -f Dockerfile.webui .
webui-push:
docker push $(IMAGE_NAME)

View File

@@ -10,6 +10,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/mudler/local-agent-framework/agent"
"github.com/mudler/local-agent-framework/xlog" "github.com/mudler/local-agent-framework/xlog"
. "github.com/mudler/local-agent-framework/agent" . "github.com/mudler/local-agent-framework/agent"
@@ -169,6 +170,9 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
WithContext(ctx), WithContext(ctx),
WithPeriodicRuns(config.PeriodicRuns), WithPeriodicRuns(config.PeriodicRuns),
WithPermanentGoal(config.PermanentGoal), WithPermanentGoal(config.PermanentGoal),
WithCharacter(agent.Character{
Name: name,
}),
WithActions( WithActions(
actions..., actions...,
), ),

View File

@@ -13,6 +13,10 @@ type Discord struct {
defaultChannel string 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 { func NewDiscord(config map[string]string) *Discord {
return &Discord{ return &Discord{
token: config["token"], token: config["token"],

View File

@@ -13,27 +13,40 @@ import (
) )
type GithubIssues struct { type GithubIssues struct {
token string token string
repository string repository string
owner string owner string
agent *agent.Agent replyIfNoReplies bool
pollInterval time.Duration agent *agent.Agent
client *github.Client 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 { func NewGithubIssueWatcher(config map[string]string) *GithubIssues {
client := github.NewClient(nil).WithAuthToken(config["token"]) client := github.NewClient(nil).WithAuthToken(config["token"])
replyIfNoReplies := false
if config["replyIfNoReplies"] == "true" {
replyIfNoReplies = true
}
interval, err := time.ParseDuration(config["pollInterval"]) interval, err := time.ParseDuration(config["pollInterval"])
if err != nil { if err != nil {
interval = 1 * time.Minute interval = 10 * time.Minute
} }
return &GithubIssues{ return &GithubIssues{
client: client, client: client,
token: config["token"], token: config["token"],
repository: config["repository"], repository: config["repository"],
owner: config["owner"], owner: config["owner"],
pollInterval: interval, replyIfNoReplies: replyIfNoReplies,
pollInterval: interval,
} }
} }
@@ -144,12 +157,19 @@ func (g *GithubIssues) issuesService() {
if len(comments) == 0 || !botAnsweredAlready { if len(comments) == 0 || !botAnsweredAlready {
// if no comments, or bot didn't answer yet, we must answer // if no comments, or bot didn't answer yet, we must answer
xlog.Info("No comments, or bot didn't answer yet") xlog.Info("No comments, or bot didn't answer yet",
xlog.Info("Comments:", len(comments)) "comments", len(comments),
xlog.Info("Bot answered already", botAnsweredAlready) "botAnsweredAlready", botAnsweredAlready,
"agent", g.agent.Character.Name,
)
mustAnswer = true 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 { if !mustAnswer {
continue continue
} }
@@ -158,7 +178,7 @@ func (g *GithubIssues) issuesService() {
agent.WithConversationHistory(messages), agent.WithConversationHistory(messages),
) )
if res.Error != nil { if res.Error != nil {
xlog.Error("Error asking", "error", res.Error) xlog.Error("Error asking", "error", res.Error, "agent", g.agent.Character.Name)
return return
} }
@@ -170,7 +190,7 @@ func (g *GithubIssues) issuesService() {
}, },
) )
if err != nil { if err != nil {
xlog.Error("Error creating comment", "error", err) xlog.Error("Error creating comment", "error", err, "agent", g.agent.Character.Name)
} }
} }
} }

View File

@@ -60,7 +60,6 @@ func Info(msg string, args ...any) {
func Debug(msg string, args ...any) { func Debug(msg string, args ...any) {
_log(slog.LevelDebug, msg, args...) _log(slog.LevelDebug, msg, args...)
logger.Debug(msg, args...)
} }
func Error(msg string, args ...any) { func Error(msg string, args ...any) {