Cleanup context, more logging
This commit is contained in:
@@ -241,6 +241,13 @@ func (a *Agent) consumeJob(job *Job, role string) {
|
|||||||
}
|
}
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
a.Lock()
|
||||||
|
a.actionContext.Cancel()
|
||||||
|
a.actionContext = nil
|
||||||
|
a.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
if selfEvaluation {
|
if selfEvaluation {
|
||||||
defer func() {
|
defer func() {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
@@ -711,6 +718,7 @@ func (a *Agent) Run() error {
|
|||||||
//todoTimer := time.NewTicker(a.options.periodicRuns)
|
//todoTimer := time.NewTicker(a.options.periodicRuns)
|
||||||
timer := time.NewTimer(a.options.periodicRuns)
|
timer := time.NewTimer(a.options.periodicRuns)
|
||||||
for {
|
for {
|
||||||
|
xlog.Debug("Agent is waiting for a job", "agent", a.Character.Name)
|
||||||
select {
|
select {
|
||||||
case job := <-a.jobQueue:
|
case job := <-a.jobQueue:
|
||||||
// Consume the job and generate a response
|
// Consume the job and generate a response
|
||||||
@@ -719,15 +727,18 @@ func (a *Agent) Run() error {
|
|||||||
if !timer.Stop() {
|
if !timer.Stop() {
|
||||||
<-timer.C
|
<-timer.C
|
||||||
}
|
}
|
||||||
|
xlog.Debug("Agent is consuming a job", "agent", a.Character.Name, "job", job)
|
||||||
a.consumeJob(job, UserRole)
|
a.consumeJob(job, UserRole)
|
||||||
timer.Reset(a.options.periodicRuns)
|
timer.Reset(a.options.periodicRuns)
|
||||||
case <-a.context.Done():
|
case <-a.context.Done():
|
||||||
// Agent has been canceled, return error
|
// Agent has been canceled, return error
|
||||||
|
xlog.Warn("Agent has been canceled", "agent", a.Character.Name)
|
||||||
return ErrContextCanceled
|
return ErrContextCanceled
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
if !a.options.standaloneJob {
|
if !a.options.standaloneJob {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
xlog.Debug("Agent is running periodically", "agent", a.Character.Name)
|
||||||
a.periodicallyRun()
|
a.periodicallyRun()
|
||||||
timer.Reset(a.options.periodicRuns)
|
timer.Reset(a.options.periodicRuns)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ func defaultOptions() *options {
|
|||||||
periodicRuns: 15 * time.Minute,
|
periodicRuns: 15 * time.Minute,
|
||||||
LLMAPI: llmOptions{
|
LLMAPI: llmOptions{
|
||||||
APIURL: "http://localhost:8080",
|
APIURL: "http://localhost:8080",
|
||||||
Model: "echidna",
|
Model: "gpt-4",
|
||||||
},
|
},
|
||||||
character: Character{
|
character: Character{
|
||||||
Name: "John Doe",
|
Name: "",
|
||||||
Age: "",
|
Age: "",
|
||||||
Occupation: "Unemployed",
|
Occupation: "",
|
||||||
Hobbies: []string{},
|
Hobbies: []string{},
|
||||||
MusicTaste: []string{},
|
MusicTaste: []string{},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
|||||||
for _, action := range a.Actions {
|
for _, action := range a.Actions {
|
||||||
var config map[string]string
|
var config map[string]string
|
||||||
if err := json.Unmarshal([]byte(action.Config), &config); err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,14 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
|
|||||||
WithTimeout(timeout),
|
WithTimeout(timeout),
|
||||||
WithRAGDB(a.ragDB),
|
WithRAGDB(a.ragDB),
|
||||||
WithAgentReasoningCallback(func(state ActionCurrentState) bool {
|
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(
|
manager.Send(
|
||||||
NewMessage(
|
NewMessage(
|
||||||
fmt.Sprintf(`Thinking: %s`, htmlIfy(state.Reasoning)),
|
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.agentStatus[name].addResult(state)
|
||||||
a.Unlock()
|
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
|
text := fmt.Sprintf(`Reasoning: %s
|
||||||
Action taken: %+v
|
Action taken: %+v
|
||||||
@@ -267,7 +281,7 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := agent.Run(); err != nil {
|
if err := agent.Run(); err != nil {
|
||||||
xlog.Info("Agent stop: ", err.Error())
|
xlog.Error("Agent stopped", "error", err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user