@@ -818,29 +818,7 @@ func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams t
818818 // At this point can only be a reply action
819819 xlog .Info ("Computing reply" , "agent" , a .Character .Name )
820820
821- // decode the response
822- replyResponse := action.ReplyResponse {}
823-
824- if err := actionParams .Unmarshal (& replyResponse ); err != nil {
825- job .Result .Conversation = conv
826- job .Result .Finish (fmt .Errorf ("error unmarshalling reply response: %w" , err ))
827- return
828- }
829-
830- // If we have already a reply from the action, just return it.
831- // Otherwise generate a full conversation to get a proper message response
832- // if chosenAction.Definition().Name.Is(action.ReplyActionName) {
833- // replyResponse := action.ReplyResponse{}
834- // if err := params.actionParams.Unmarshal(&replyResponse); err != nil {
835- // job.Result.Finish(fmt.Errorf("error unmarshalling reply response: %w", err))
836- // return
837- // }
838- // if replyResponse.Message != "" {
839- // job.Result.SetResponse(replyResponse.Message)
840- // job.Result.Finish(nil)
841- // return
842- // }
843- // }
821+ forceResponsePrompt := "Reply to the user without using any tools or function calls. Just reply with the message."
844822
845823 // If we have a hud, display it when answering normally
846824 if a .options .enableHUD {
@@ -856,39 +834,19 @@ func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams t
856834 Role : "system" ,
857835 Content : prompt ,
858836 },
837+ {
838+ Role : "system" ,
839+ Content : forceResponsePrompt ,
840+ },
859841 }, conv ... )
860842 }
861- }
862-
863- // Generate a human-readable response
864- // resp, err := a.client.CreateChatCompletion(ctx,
865- // openai.ChatCompletionRequest{
866- // Model: a.options.LLMAPI.Model,
867- // Messages: append(conv,
868- // openai.ChatCompletionMessage{
869- // Role: "system",
870- // Content: "Assistant thought: " + replyResponse.Message,
871- // },
872- // ),
873- // },
874- // )
875-
876- if replyResponse .Message != "" {
877- xlog .Info ("Return reply message" , "reply" , replyResponse .Message , "agent" , a .Character .Name )
878-
879- msg := openai.ChatCompletionMessage {
880- Role : "assistant" ,
881- Content : a .cleanupLLMResponse (replyResponse .Message ),
882- }
883-
884- conv = append (conv , msg )
885- job .Result .Conversation = conv
886- job .Result .SetResponse (msg .Content )
887- job .Result .AddFinalizer (func (conv []openai.ChatCompletionMessage ) {
888- a .saveCurrentConversation (conv )
889- })
890- job .Result .Finish (nil )
891- return
843+ } else {
844+ conv = append ([]openai.ChatCompletionMessage {
845+ {
846+ Role : "system" ,
847+ Content : forceResponsePrompt ,
848+ },
849+ }, conv ... )
892850 }
893851
894852 xlog .Info ("Reasoning, ask LLM for a reply" , "agent" , a .Character .Name )
@@ -901,16 +859,22 @@ func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams t
901859 return
902860 }
903861
904- // If we didn't got any message, we can use the response from the action
905- if chosenAction .Definition ().Name .Is (action .ReplyActionName ) && msg .Content == "" {
906- xlog .Info ("No output returned from conversation, using the action response as a reply " + replyResponse .Message )
862+ msg .Content = a .cleanupLLMResponse (msg .Content )
907863
908- msg = openai.ChatCompletionMessage {
909- Role : "assistant" ,
910- Content : a .cleanupLLMResponse (replyResponse .Message ),
864+ if msg .Content == "" {
865+ // If we didn't got any message, we can use the response from the action (it should be a reply)
866+
867+ replyResponse := action.ReplyResponse {}
868+ if err := actionParams .Unmarshal (& replyResponse ); err != nil {
869+ job .Result .Conversation = conv
870+ job .Result .Finish (fmt .Errorf ("error unmarshalling reply response: %w" , err ))
871+ return
872+ }
873+
874+ if chosenAction .Definition ().Name .Is (action .ReplyActionName ) && replyResponse .Message != "" {
875+ xlog .Info ("No output returned from conversation, using the action response as a reply " + replyResponse .Message )
876+ msg .Content = a .cleanupLLMResponse (replyResponse .Message )
911877 }
912- } else {
913- msg .Content = a .cleanupLLMResponse (msg .Content )
914878 }
915879
916880 conv = append (conv , msg )
0 commit comments