diff --git a/agent/agent.go b/agent/agent.go index 50b7d3e..30a7130 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -241,6 +241,13 @@ func (a *Agent) consumeJob(job *Job, role string) { } a.Unlock() + defer func() { + a.Lock() + a.actionContext.Cancel() + a.actionContext = nil + a.Unlock() + }() + if selfEvaluation { defer func() { a.Lock() @@ -711,6 +718,7 @@ func (a *Agent) Run() error { //todoTimer := time.NewTicker(a.options.periodicRuns) timer := time.NewTimer(a.options.periodicRuns) for { + xlog.Debug("Agent is waiting for a job", "agent", a.Character.Name) select { case job := <-a.jobQueue: // Consume the job and generate a response @@ -719,15 +727,18 @@ func (a *Agent) Run() error { if !timer.Stop() { <-timer.C } + xlog.Debug("Agent is consuming a job", "agent", a.Character.Name, "job", job) a.consumeJob(job, UserRole) timer.Reset(a.options.periodicRuns) case <-a.context.Done(): // Agent has been canceled, return error + xlog.Warn("Agent has been canceled", "agent", a.Character.Name) return ErrContextCanceled case <-timer.C: if !a.options.standaloneJob { continue } + xlog.Debug("Agent is running periodically", "agent", a.Character.Name) a.periodicallyRun() timer.Reset(a.options.periodicRuns) } diff --git a/agent/options.go b/agent/options.go index 22006a0..77590be 100644 --- a/agent/options.go +++ b/agent/options.go @@ -51,12 +51,12 @@ func defaultOptions() *options { periodicRuns: 15 * time.Minute, LLMAPI: llmOptions{ APIURL: "http://localhost:8080", - Model: "echidna", + Model: "gpt-4", }, character: Character{ - Name: "John Doe", + Name: "", Age: "", - Occupation: "Unemployed", + Occupation: "", Hobbies: []string{}, MusicTaste: []string{}, }, diff --git a/example/webui/actions.go b/example/webui/actions.go index c622be0..d0fd4c0 100644 --- a/example/webui/actions.go +++ b/example/webui/actions.go @@ -39,7 +39,7 @@ func (a *AgentConfig) availableActions(ctx context.Context) []Action { for _, action := range a.Actions { var config map[string]string if err := json.Unmarshal([]byte(action.Config), &config); err != nil { - xlog.Info("Error unmarshalling action config", err) + xlog.Info("Error unmarshalling action config", "error", err) continue } diff --git a/example/webui/agentpool.go b/example/webui/agentpool.go index bce6b07..37c3556 100644 --- a/example/webui/agentpool.go +++ b/example/webui/agentpool.go @@ -181,7 +181,14 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error WithTimeout(timeout), WithRAGDB(a.ragDB), WithAgentReasoningCallback(func(state ActionCurrentState) bool { - xlog.Info("Reasoning", state.Reasoning) + xlog.Info( + "Agent is thinking", + "agent", name, + "reasoning", state.Reasoning, + "action", state.Action.Definition().Name, + "params", state.Params, + ) + manager.Send( NewMessage( fmt.Sprintf(`Thinking: %s`, htmlIfy(state.Reasoning)), @@ -204,7 +211,14 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error a.agentStatus[name].addResult(state) a.Unlock() - xlog.Info("Reasoning", state.Reasoning) + xlog.Info( + "Agent executed an action", + "agent", name, + "reasoning", state.Reasoning, + "action", state.ActionCurrentState.Action.Definition().Name, + "params", state.ActionCurrentState.Params, + "result", state.Result, + ) text := fmt.Sprintf(`Reasoning: %s Action taken: %+v @@ -267,7 +281,7 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error go func() { if err := agent.Run(); err != nil { - xlog.Info("Agent stop: ", err.Error()) + xlog.Error("Agent stopped", "error", err.Error()) } }()