Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
fixed auto-continue issue
Dane Schneider81b32d2db3e6
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.goindex 59520435..e4c26dad 100644--- a/app/server/model/plan/exec_status.go+++ b/app/server/model/plan/exec_status.go@@ -13,28 +13,26 @@ import ("github.com/sashabaranov/go-openai")-func ExecStatusShouldContinue(client *openai.Client, config shared.TaskRoleConfig, message string, ctx context.Context) (bool, error) {+func ExecStatusShouldContinue(client *openai.Client, config shared.TaskRoleConfig, prompt, message string, ctx context.Context) (bool, error) {log.Println("Checking if plan should continue based on exec status")// First try to determine if the plan should continue based on the last paragraph without calling the modelparagraphs := strings.Split(message, "\n\n")- lastParagraphLower := strings.ToLower(paragraphs[len(paragraphs)-1])+ lastParagraph := paragraphs[len(paragraphs)-1]+ lastParagraphLower := strings.ToLower(lastParagraph)// log.Printf("Last paragraph: %s\n", lastParagraphLower)if lastParagraphLower != "" {if strings.Contains(lastParagraphLower, "all tasks have been completed") ||strings.Contains(lastParagraphLower, "plan cannot be continued") {-log.Println("Plan cannot be continued based on last paragraph")-return false, nil}- if strings.Index(lastParagraphLower, "next,") < 3 {-+ nextIdx := strings.Index(lastParagraph, "Next, ")+ if nextIdx >= 0 {log.Println("Plan can be continued based on last paragraph")-return true, nil}}@@ -42,7 +40,7 @@ func ExecStatusShouldContinue(client *openai.Client, config shared.TaskRoleConfimessages := []openai.ChatCompletionMessage{{Role: openai.ChatMessageRoleSystem,- Content: prompts.GetExecStatusShouldContinue(message), // Ensure this function is correctly defined in your package+ Content: prompts.GetExecStatusShouldContinue(prompt, message), // Ensure this function is correctly defined in your package},}@@ -82,7 +80,8 @@ func ExecStatusShouldContinue(client *openai.Client, config shared.TaskRoleConfivar strRes stringvar res struct {- ShouldContinue bool `json:"shouldContinue"`+ Reasoning string `json:"reasoning"`+ ShouldContinue bool `json:"shouldContinue"`}for _, choice := range resp.Choices {@@ -114,5 +113,7 @@ func ExecStatusShouldContinue(client *openai.Client, config shared.TaskRoleConfireturn false, nil}+ log.Printf("Plan exec status response: %v\n", res)+return res.ShouldContinue, nil}diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 7263a030..ab473ad2 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -265,6 +265,7 @@ func execTellPlan(}}+ state.promptMessage = promptMessagestate.messages = append(state.messages, *promptMessage)} else {log.Println("Missing file response:", missingFileResponse, "setting replyParser")diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 8b61b503..3a8b5a31 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -243,7 +243,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt}()go func() {- shouldContinue, err = ExecStatusShouldContinue(client, settings.ModelSet.ExecStatus, assistantMsg.Message, active.Ctx)+ shouldContinue, err = ExecStatusShouldContinue(client, settings.ModelSet.ExecStatus, promptMessage.Content, assistantMsg.Message, active.Ctx)if err != nil {state.onError(fmt.Errorf("failed to get exec status: %v", err), false, assistantMsg.Id, convoCommitMsg)errCh <- errdiff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.goindex d70d4d8f..702d7632 100644--- a/app/server/model/prompts/exec_status.go+++ b/app/server/model/prompts/exec_status.go@@ -9,20 +9,26 @@ const SysExecStatusShouldContinue = `You are tasked with evaluating a response gYour goal is to determine whether the plan created by AI 1 should automatically continue or if it is considered complete. To do this, you need to analyze the latest message of the plan from AI 1 carefully and decide based on the following criteria:-Assess whether AI 1 has indicated that all tasks and subtasks within the plan have been completed.+Assess whether the user has given the AI a task to do or whether the user is just chatting with the AI. If the user is just chatting, the plan should not continue. If the AI is not clearly working on a task in its response, the plan should not continue.++Assess whether AI 1 has indicated that all tasks and subtasks within the plan have been completed. If so, the plan should not continue.Assess whether AI 1 has concluded with a statement that indicates either the user needs to take specific actions before the plan can proceed, or that the plan can't automatically continue for any other reason. If so, the plan should not continue.If AI 1 has outlined a clear next step necessary to finish the plan but has not executed it, the plan should continue.-You *must* call the shouldAutoContinue function with a JSON object containing the key 'shouldContinue'.+You *must* call the shouldAutoContinue function with a JSON object containing the keys 'reasoning' and 'shouldContinue'.++Set 'reasoning' to a string briefly and succinctly explaining your reasoning for why the plan should or should not continue, based on your instructions above.-Set 'shouldContinue' to true if the plan should automatically continue based on the outlined criteria or false otherwise.+Set 'shouldContinue' to true if the plan should automatically continue based on your instructions above, or false otherwise.You must always call 'shouldAutoContinue'. Don't call any other function.`-func GetExecStatusShouldContinue(message string) string {- return SysExecStatusShouldContinue + "\n\n**Here is the latest message of the plan from AI 1:**\n" + message+func GetExecStatusShouldContinue(userPrompt, message string) string {+ return SysExecStatusShouldContinue ++ "\n\n**Here is the user's prompt:**\n" + userPrompt + "\n\n" ++ "\n\n**Here is the latest message of the plan from AI 1:**\n" + message}var ShouldAutoContinueFn = openai.FunctionDefinition{@@ -30,10 +36,13 @@ var ShouldAutoContinueFn = openai.FunctionDefinition{Parameters: &jsonschema.Definition{Type: jsonschema.Object,Properties: map[string]jsonschema.Definition{+ "reasoning": {+ Type: jsonschema.String,+ },"shouldContinue": {Type: jsonschema.Boolean,},},- Required: []string{"shouldContinue"},+ Required: []string{"reasoning", "shouldContinue"},},}