Reply when skipping loops

This commit is contained in:
mudler
2025-04-09 19:49:39 +02:00
parent 0eb68b6c20
commit bc7f6f059c

View File

@@ -502,7 +502,8 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
}
if count[chosenAction.Definition().Name.String()] > a.options.loopDetectionSteps {
xlog.Info("Loop detected, stopping agent", "agent", a.Character.Name, "action", chosenAction.Definition().Name)
chosenAction = nil
a.reply(job, role, conv, actionParams, chosenAction, reasoning)
return
}
}
@@ -570,13 +571,6 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
job.AddPastAction(chosenAction, &actionParams)
var err error
conv, err = a.handlePlanning(job.GetContext(), job, chosenAction, actionParams, reasoning, pickTemplate, conv)
if err != nil {
job.Result.Finish(fmt.Errorf("error running action: %w", err))
return
}
if !job.Callback(types.ActionCurrentState{
Job: job,
Action: chosenAction,
@@ -595,6 +589,13 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
return
}
var err error
conv, err = a.handlePlanning(job.GetContext(), job, chosenAction, actionParams, reasoning, pickTemplate, conv)
if err != nil {
job.Result.Finish(fmt.Errorf("error running action: %w", err))
return
}
if selfEvaluation && a.options.initiateConversations &&
chosenAction.Definition().Name.Is(action.ConversationActionName) {
@@ -625,8 +626,11 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
return
}
// If we don't have to reply , run the action!
if !chosenAction.Definition().Name.Is(action.ReplyActionName) {
// if we have a reply action, we need to run it
if chosenAction.Definition().Name.Is(action.ReplyActionName) {
a.reply(job, role, conv, actionParams, chosenAction, reasoning)
return
}
if !chosenAction.Definition().Name.Is(action.PlanActionName) {
result, err := a.runAction(job.GetContext(), chosenAction, actionParams)
@@ -698,8 +702,11 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
return
}
}
}
a.reply(job, role, conv, actionParams, chosenAction, reasoning)
}
func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams types.ActionParams, chosenAction types.Action, reasoning string) {
job.Result.Conversation = conv
// At this point can only be a reply action
@@ -760,8 +767,8 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
// },
// )
if !a.options.forceReasoning {
xlog.Info("No reasoning, return reply message", "reply", replyResponse.Message, "agent", a.Character.Name)
if replyResponse.Message != "" {
xlog.Info("Return reply message", "reply", replyResponse.Message, "agent", a.Character.Name)
msg := openai.ChatCompletionMessage{
Role: "assistant",