Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

improvements to core planning, summarization, auto-continue logic--adapted prompts for gpt-4o

Dane Schneider0769df88b575
diff --git a/app/server/model/plan/build_finish.go b/app/server/model/plan/build_finish.go
index c726f5c5..acbc5332 100644
--- a/app/server/model/plan/build_finish.go
+++ b/app/server/model/plan/build_finish.go
@@ -374,12 +374,10 @@ func (fileState *activeBuildStreamFileState) onBuildFileError(err error) {
activeBuild.Success = false
activeBuild.Error = err
- if activePlan != nil {
- activePlan.StreamDoneCh <- &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: err.Error(),
- }
+ activePlan.StreamDoneCh <- &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: err.Error(),
}
if err != nil {
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index 3b981e88..9933d066 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -3,7 +3,9 @@ package plan
import (
"context"
"encoding/json"
+ "fmt"
"log"
+ "plandex-server/db"
"plandex-server/model"
"plandex-server/model/prompts"
"strings"
@@ -12,7 +14,7 @@ import (
"github.com/sashabaranov/go-openai"
)
-func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx context.Context) (bool, error) {
+func (state *activeTellStreamState) execStatusShouldContinue(message string, latestSummaryCh chan *db.ConvoSummary, ctx context.Context) (bool, string, error) {
settings := state.settings
clients := state.clients
config := settings.ModelPack.ExecStatus
@@ -30,25 +32,13 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
// 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
- }
-
nextIdx := strings.Index(lastParagraph, "Next, ")
if nextIdx >= 0 {
log.Println("Plan can be continued based on last paragraph")
- return true, nil
+ return true, lastParagraph, nil
}
}
- var latestSummary string
-
- if len(state.summaries) > 0 {
- latestSummary = state.summaries[len(state.summaries)-1].Summary
- }
-
var prevAssistantMsg string
if len(state.convo) > 1 {
// iterate backwards from len(state.convo) - 2 to 0
@@ -60,15 +50,33 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
}
}
+ var latestSummary *db.ConvoSummary
+
+ if latestSummaryCh != nil {
+ log.Println("Waiting for latest summary")
+ select {
+ case <-ctx.Done():
+ log.Println("Context cancelled while waiting for latest summary")
+ return false, "", fmt.Errorf("context cancelled while waiting for latest summary")
+ case latestSummary = <-latestSummaryCh:
+ log.Println("Got latest summary")
+ }
+ }
+
+ var summary string
+ if latestSummary != nil {
+ summary = latestSummary.Summary
+ }
+
messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
- Content: prompts.GetExecStatusShouldContinue(latestSummary, prevAssistantMsg, state.userPrompt, message),
+ Content: prompts.GetExecStatusShouldContinue(summary, prevAssistantMsg, state.userPrompt, message),
},
}
log.Println("Calling model to check if plan should continue")
- log.Println("Has latest summary:", latestSummary != "")
+ log.Println("Has latest summary:", summary != "")
log.Println("Has prev assistant msg:", prevAssistantMsg != "")
// log.Println("messages:")
@@ -108,11 +116,15 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
// return false, fmt.Errorf("error during plan exec status check model call: %v", err)
// Instead of erroring out, just don't continue the plan
- return false, nil
+ return false, "", nil
}
var strRes string
var res struct {
+ Comments []struct {
+ Txt string `json:"txt"`
+ IsTodoPlaceholder bool `json:"isTodoPlaceholder"`
+ } `json:"comments"`
Reasoning string `json:"reasoning"`
ShouldContinue bool `json:"shouldContinue"`
}
@@ -133,7 +145,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
// return false, fmt.Errorf("no shouldAutoContinue function call found in response")
// Instead of erroring out, just don't continue the plan
- return false, nil
+ return false, "", nil
}
err = json.Unmarshal([]byte(strRes), &res)
@@ -143,10 +155,10 @@ func (state *activeTellStreamState) execStatusShouldContinue(message string, ctx
// return false, fmt.Errorf("error unmarshalling plan exec status response: %v", err)
// Instead of erroring out, just don't continue the plan
- return false, nil
+ return false, "", nil
}
log.Printf("Plan exec status response: %v\n", res)
- return res.ShouldContinue, nil
+ return res.ShouldContinue, res.Reasoning, nil
}
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.go
index 1cf9a2b2..0490dc4e 100644
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@ -36,6 +36,7 @@ func Tell(clients map[string]*openai.Client, plan *db.Plan, branch string, auth
0,
"",
req.BuildMode == shared.BuildModeAuto,
+ "",
)
log.Printf("Tell: Tell operation completed successfully for plan ID %s on branch %s\n", plan.Id, branch)
@@ -51,6 +52,7 @@ func execTellPlan(
iteration int,
missingFileResponse shared.RespondMissingFileChoice,
shouldBuildPending bool,
+ autoContinueNextTask string,
) {
log.Printf("execTellPlan: Called for plan ID %s on branch %s, iteration %d\n", plan.Id, branch, iteration)
currentUserId := auth.User.Id
@@ -264,6 +266,16 @@ func execTellPlan(
prompt = req.Prompt
} else {
prompt = prompts.AutoContinuePrompt
+
+ if autoContinueNextTask != "" {
+ prompt += `
+ Here is the next task:
+
+ ` + autoContinueNextTask + `
+
+ Continue seamlessly with this task.
+ `
+ }
}
state.userPrompt = prompt
diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.go
index 33a8351f..5c2f2117 100644
--- a/app/server/model/plan/tell_stream.go
+++ b/app/server/model/plan/tell_stream.go
@@ -15,7 +15,7 @@ import (
"github.com/sashabaranov/go-openai"
)
-const MaxAutoContinueIterations = 50
+const MaxAutoContinueIterations = 100
func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStream) {
defer stream.Close()
@@ -108,7 +108,8 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
state.onError(fmt.Errorf("failed to set plan status to describing: %v", err), true, "", "")
return
}
- // log.Println("summarize convo:", spew.Sdump(convo))
+
+ latestSummaryCh := active.LatestSummaryCh
log.Println("summarize convo")
envVar := settings.ModelPack.PlanSummary.BaseModelConfig.ApiKeyEnvVar
@@ -152,6 +153,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
log.Println("Locked repo for assistant reply and description")
var shouldContinue bool
+ var nextTask string
err = func() error {
defer func() {
if err != nil {
@@ -234,9 +236,8 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
}()
go func() {
- // One of the below is nil occasionally, causing crash
log.Println("Getting exec status")
- shouldContinue, err = state.execStatusShouldContinue(assistantMsg.Message, active.Ctx)
+ shouldContinue, nextTask, err = state.execStatusShouldContinue(assistantMsg.Message, latestSummaryCh, active.Ctx)
if err != nil {
state.onError(fmt.Errorf("failed to get exec status: %v", err), false, assistantMsg.Id, convoCommitMsg)
errCh <- err
@@ -286,7 +287,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
if req.AutoContinue && shouldContinue && iteration < MaxAutoContinueIterations {
log.Println("Auto continue plan")
// continue plan
- execTellPlan(clients, plan, branch, auth, req, iteration+1, "", false)
+ execTellPlan(clients, plan, branch, auth, req, iteration+1, "", false, nextTask)
} else {
var buildFinished bool
UpdateActivePlan(planId, branch, func(ap *types.ActivePlan) {
@@ -439,6 +440,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt
iteration, // keep the same iteration
userChoice,
false,
+ "",
)
return
}
diff --git a/app/server/model/plan/tell_summary.go b/app/server/model/plan/tell_summary.go
index 406542ac..8d7e74dc 100644
--- a/app/server/model/plan/tell_summary.go
+++ b/app/server/model/plan/tell_summary.go
@@ -220,6 +220,12 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
userPrompt := params.userPrompt
currentOrgId := params.currentOrgId
currentReply := params.currentReply
+ active := GetActivePlan(planId, branch)
+
+ if active == nil {
+ log.Printf("Active plan not found for plan ID %s and branch %s\n", planId, branch)
+ return fmt.Errorf("active plan not found for plan ID %s and branch %s", planId, branch)
+ }
log.Println("Generating plan summary for planId:", planId)
@@ -316,6 +322,9 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
// log.Println("Summary messages:")
// spew.Dump(summaryMessages)
+ latestSummaryCh := make(chan *db.ConvoSummary, 1)
+ active.LatestSummaryCh = latestSummaryCh
+
summary, err := model.PlanSummary(client, config, model.PlanSummaryParams{
Conversation: summaryMessages,
LatestConvoMessageId: latestMessageId,
@@ -339,5 +348,7 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, params
return err
}
+ latestSummaryCh <- summary
+
return nil
}
diff --git a/app/server/model/prompts/create.go b/app/server/model/prompts/create.go
index c35e6cc5..d17bee0f 100644
--- a/app/server/model/prompts/create.go
+++ b/app/server/model/prompts/create.go
@@ -99,7 +99,7 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
**You MUST NEVER give up and say the task is too large or complex for you to do.** Do your best to break the task down into smaller steps and then implement those steps. If a task is very large, the smaller steps can later be broken down into even smaller steps and so on. You can use as many responses as needed to complete a large task. Also don't shorten the task or only implement it partially even if the task is very large. Do your best to break up the task and then implement each step fully, breaking each step into further smaller steps as needed.
- **You MUST NOT create only the basic structure of the plan and then stop, or leave any gaps or placeholders.** You must *fully* implement every task and subtask, create or update every necessary file, and provide *all* necessary code, leaving no gaps or placeholders. You must be thorough and exhaustive in your implementation of the plan, and use as many responses as needed to complete the task to a high standard. In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated.
+ **You MUST NOT create only the basic structure of the plan and then stop, or leave any gaps or placeholders.** You must *fully* implement every task and subtask, create or update every necessary file, and provide *all* necessary code, leaving no gaps or placeholders. You must be thorough and exhaustive in your implementation of the plan, and use as many responses as needed to complete the task to a high standard. In the list of subtasks, be sure you are including *every* task needed to complete the plan. Make sure that EVERY file that needs to be created or updated to complete the task is included in the plan. Do NOT leave out any files that need to be created or updated. You are tireless and will finish the *entire* task no matter how many responses it takes.
## Focus on what the user has asked for and don't add extra code or features
@@ -119,17 +119,15 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
After implementing a task or subtask with code, and before moving on to another task or subtask, you MUST *explicitly mark it done*. You can do this by explicitly stating "[subtask] has been completed". For example, "**Adding the update function** has been completed." It's extremely important to mark subtasks as done so that you can keep track of what has been completed and what is remaining. Never move on to a new subtask. Never end a response without marking the current subtask as done if it has been completed during the response. You MUST NOT omit marking a subtask as done when it has been completed.
- ` + CommentPlaceholderInstructions + `
+ Next, move on to the next task or subtask if any are remaining. Otherwise, if no subtasks are remaining then stop there.
- Next, move on to the next task or subtask if any are remaining. Otherwise, if no subtasks are remaining output "All tasks have been completed." and stop there.
-
- If all subtasks are completed, then consider the plan complete. DO NOT repeat or re-implement a subtask that has already been implemented during the conversation.
+ If all subtasks are completed, then consider the plan complete and stop there. DO NOT repeat or re-implement a subtask that has already been implemented during the conversation.
If the latest summary states that a subtask has not yet been implemented in code, but it *has* been implemented in code earlier in he conversation, you MUST NOT re-implement the subtask. In can take some time for the latest summary to be updated, so always consider the current state of the conversation as well when deciding which subtasks to implement.
You should only implement each subtask once. If a subtask has already been implemented in code, you should consider it complete and move on to the next subtask.
- You MUST ALWAYS work on subtasks IN ORDER. You must not skip a subtask or work on subtasks out of order. You must work on subtasks in the order they were listed when breaking up the task into subtasks. You must never go backwards and work on an earlier subtask than the current one. After finishing a subtask, you must always either work on the next subtask or, if there are no remaining subtasks, end the plan with "All tasks have been completed.".
+ You MUST ALWAYS work on subtasks IN ORDER. You must not skip a subtask or work on subtasks out of order. You must work on subtasks in the order they were listed when breaking up the task into subtasks. You must never go backwards and work on an earlier subtask than the current one. After finishing a subtask, you must always either work on the next subtask or, if there are no remaining subtasks, stop there.".
## Things you can't do
@@ -156,39 +154,31 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
## Ending a response
Before ending a response, first mark the current subtask as done as described above if it has been completed during the response.
-
- ` + CommentPlaceholderInstructions + `
- At the *very* end of your response, in a final, separate paragraph, you *must* decide whether the plan is completed and if not, whether it should be automatically continued.
- - If all the subtasks in a plan have been completed, you *MUST* explicitly say "All tasks have been completed."
- - If any summaries of the plan have been included in the conversation that list all the subtasks and mark each one 'Done' or 'Not done', consider only the *latest* summary. If the latest summary shows that all subtasks are marked 'Done', OR you have *just completed* all the remaining 'Not done' subtasks in the responses following the summary, then the plan is done and you must explicitly say "All tasks have been completed."
+ At the *very* end of your response, in a final, separate paragraph:
+
+ - If any summaries of the plan have been included in the conversation that list all the subtasks and mark each one 'Implemented' or 'Not implemented', consider only the *latest* summary. If the latest summary shows that all subtasks are marked 'Implemented', OR you have *just completed* all the remaining 'Not implemented' subtasks in the responses following the summary, then stop there."
Otherwise:
- If there is a clear next subtask that definitely needs to be done to finish the plan (and has not already been completed), output a sentence starting with "Next, " and then give a brief description of the next subtask.
- - If there is no clear next subtask, or the user needs to take some action before you can continue, explicitly say "The plan cannot be continued." Then finish with a brief description of what the user needs to do for the plan to proceed.
+ - If the user needs to take some action before you can continue, say so explicitly, then finish with a brief description of what the user needs to do for the plan to proceed.
- - You must not output any other text after this final paragraph. It *must* be the last thing in your response, and it *must* begin with one of the options above ("All tasks have been completed.", "Next, ", or "The plan cannot be continued.").
+ - You must not output any other text after this final paragraph. It *must* be the last thing in your response
- - If last paragraph in the response does not begin with one of the options listed above, you MUST continue the response and include a paragraph that DOES begin with one of the options listed above.
-
- - You should consider the plan complete if all the subtasks are completed to a decent standard. Even if there are additional steps that *could* be taken, if you have completed all the subtasks, you should consider the plan complete, output "All tasks have been completed.", and stop there.
+ - Don't consider the user verifying, testing, or deploying the code as a next step. If all that's left is for the user to verify, test, deploy, or run the code, consider the plan complete and then stop there.
- - Don't consider the user verifying, testing, or deploying the code as a next step. If all that's left is for the user to verify, test, deploy, or run the code, consider the plan complete and output "All tasks have been completed." and then stop there.
+ - It's not up to you to determine whether the plan is finished or not. Another AI will assess the plan and determine if it is complete or not. Only state that the plan cannot continue if the user needs to take some action before you can continue. Don't say it for any other reason. You are *tireless* and will not give up until the plan is complete.
- ## EXTREMELY IMPORTANT Rules for responses
+ - If you think the plan is done, say so, but remember that you don't have the final word on the matter. Explain why you think the plan is done.
- You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next," or "The plan cannot be continued.".
-
- You MUST NEVER **reply with just a single paragraph that contains only "All tasks have been completed."**.
+ ## EXTREMELY IMPORTANT Rules for responses
- You MUST NEVER begin any response with "The plan cannot be continued." or "All tasks have been completed.".
+ You *must never respond with just a single paragraph.* Every response should include at least a few paragraphs that try to move a plan forward. You *especially must never* reply with just a single paragraph that begins with "Next,".
Every response must start by considering the previous responses and latest context and then attempt to move the plan forward.
You MUST NEVER duplicate, restate, or summarize the most recent response or *any* previous response. Start from where the previous response left off and continue seamlessly from there. Continue smoothly from the end of the last response as if you were replying to the user with one long, continuous response. If the previous response ended with a paragraph that began with "Next,", proceed to implement ONLY THAT TASK OR SUBTASK in your response.
-
- If any paragraph begins with "Next,", it *must never* be followed by a paragraph containing "All tasks have been completed." or "The plan cannot be continued." *Only* if the task described in the "Next," paragraph has *BEEN COMPLETED* can you ever follow it with "All tasks have been completed.".
- If the previous response ended with a paragraph that began with "Next," and you are continuing the plan, you must *not* begin your response with "Next,". Instead, continue seamlessly from where the previous response left off. If you are not able to complete the task described in the "Next," paragraph, you must explicitly say either "All tasks have been completed" if that was the last remianing task, or describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.
+ If the previous response ended with a paragraph that began with "Next," and you are continuing the plan, you must *not* begin your response with "Next,". Instead, continue seamlessly from where the previous response left off. If you are not able to complete the task described in the preceding message's "Next," paragraph, you must explicitly describe what the user needs to do for the plan to proceed and then output "The plan cannot be continued." and stop there.
Never ask a user to do something manually if you can possibly do it yourself with a code block. Never ask the user to do or anything that isn't strictly necessary for completing the plan to a decent standard.
@@ -196,6 +186,8 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
DO NOT include "fluffy" additional subtasks when breaking a task up. Only include subtasks and steps that are strictly in the realm of coding and doable ONLY through creating and updating files. Remember, you are listing these subtasks and steps so that you can execute them later. Only list things that YOU can do yourself with NO HELP from the user. Your goal is to *fully complete* the *exact task* the user has given you in as few tokens and responses as you can. This means only including *necessary* steps that *you can complete yourself*.
+ DO NOT summarize the state of the plan. Another AI will do that. Your job is to move the plan forward, not to summarize it. State which subtask you are working on, complete the subtask, state that you have completed the subtask, and then move on to the next subtask.
+
## Continuing the plan
NEVER repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
@@ -209,7 +201,13 @@ const SysCreate = Identity + ` A plan is a set of files with an attached context
## Consider the latest context
- Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context. For example, if you are working on a plan that has been broken up into subtasks, and you've reached the point of implementing a particular subtask, first consider whether the subtask is still necessary looking at the files in context. If it has already been implemented or is no longer necessary, say so, revise the plan as needed, and move on. Do NOT make an update that is no longer necessary based on the current state of the context. Otherwise, implement the subtask.
+ Be aware that since the plan started, the context may have been updated. It may have been updated by the user implementing your suggestions, by the user implementing their own work, or by the user adding more files or information to context. Be sure to consider the current state of the context when continuing with the plan, and whether the plan needs to be updated to reflect the latest context.
+
+ If the latest state of the context makes the current subtask you are working on redundant or unnecessary, say so, mark that subtask as done, and move on to the next subtask. Say something like "the latest updates to ` + "`file_path`" + ` make this subtask unnecessary." I'll mark it as done and move on to the next subtask." and then mark the subtask as done and move on to the next subtask.
+
+ If the latest state of the context makes the current plan you are working on redundant, say so, mark the plan as complete, and stop there.
+
+ Otherwise, implement the subtask.
## Responding to user questions
@@ -236,14 +234,12 @@ Do not implement a task partially and then give up even if it's very large or co
If a high quality, well-respected open source library is available that can simplify a task or subtask, use it.
-If you're making a plan, end every response with either "All tasks have been completed.", "Next, " (plus a brief description of the next step), or "The plan cannot be continued." according to your instructions for ending a response. Do NOT repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
+Do NOT repeat any part of your previous response. Always continue seamlessly from where your previous response left off.
Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
-` + CommentPlaceholderInstructions + `
-
If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.`
@@ -258,14 +254,12 @@ const UserContinuePrompt = "Continue the plan."
const AutoContinuePrompt = `Continue the plan from where you left off in the previous response. Don't repeat any part of your previous response. Don't begin your response with 'Next,'.
-Continue seamlessly from where your previous response left off. Never begin your response with 'The plan cannot be continued.' or 'All tasks have been completed.'.
+Continue seamlessly from where your previous response left off.
Always name the subtask you are working on before starting it, and mark it as done before moving on to the next subtask.
ALWAYS complete subtasks in order and never go backwards in the list of subtasks. Never skip a subtask or work on subtasks out of order. Never repeat a subtask that has been marked implemented in the latest summary or that has already been implemented during conversation.
-` + CommentPlaceholderInstructions + `
-
If you break up a task into subtasks, only include subtasks that can be implemented directly in code by creating or updating files. Do not include subtasks that require executing code or commands. Do not include subtasks that require user testing, deployment, or other tasks that go beyond coding.
Do NOT include tests or documentation in the subtasks unless the user has specifically asked for them. Do not include extra code or features beyond what the user has asked for. Focus on the user's request and implement only what is necessary to fulfill it.`
@@ -273,7 +267,3 @@ Do NOT include tests or documentation in the subtasks unless the user has specif
const SkippedPathsPrompt = "\n\nSome files have been skipped by the user and *must not* be generated. The user will handle any updates to these files themselves. Skip any parts of the plan that require generating these files. You *must not* generate a file block for any of these files.\nSkipped files:\n"
// - If the plan is in progress, this is not your *first* response in the plan, the user's task or tasks have already been broken down into subtasks if necessary, and the plan is *not yet complete* and should be continued, you MUST ALWAYS start the response with "Now I'll" and then proceed to describe and implement the next step in the plan.
-
-const CommentPlaceholderInstructions = `
-Immediately after EVERY code block, consider whether the code that implemented it contains one or more placeholders in comments for functionality that *has not been implemented*, like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish impelementation" or any similar placeholder comments that describe tasks that still remain to be implemented. If comments like these are not followed by the *actual implementation in code*, and this task described in the placeholder comment is not *already* in the list of subtasks, you *must immediately* state that some tasks have been left unimplemented in the preceding code, then output a heading like "## Adding subtask 7: " (while using the appropriate number) followed by a brief description of the subtask that should be added based on the comment placeholder. If there are NO comment placeholders that were left unimplemtented, then mark the current subtask as done according to your instructions. You MUST ALWAYS either mark the current subtask as done or state that some tasks have been left unimplemented and then add them as additional subtasks. This is EXTREMELY IMPORTANT--if you skip this step, the plan will not be fully completed. You MUST NOT end the plan while placeholder comments remain unimplemented. When introducing a new subtask baced on a placeholder comment, it MUST be added to the END of the current list of subtasks as a new numbered subtask. You MUST NEVER output "All tasks have been completed" and end the plan without adding ALL unimplemented comment placeholders as subtasks and *fully implementing* every subtask that has been added based on a placeholder comment.
-`
diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.go
index a351e4bc..94d3ec2b 100644
--- a/app/server/model/prompts/exec_status.go
+++ b/app/server/model/prompts/exec_status.go
@@ -11,22 +11,37 @@ Your goal is to determine whether the plan created by AI 1 should automatically
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.
+You might be supplied with a summary of the plan if one is available. If the summary is available, it will include a list of tasks to be done in the plan and whether each one has been implemented in code yet or not. If the summary is available and all tasks have been completed, the plan should not continue. If the summary is available and there are still tasks to be done, the plan should continue *unless* *all* the remaining unfinished tasks have been *fully* implemented in the latest message from AI 1. If between the latest summary and the latest message from AI 1 all tasks have been fully implemented, 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 a summary is not available, the message from AI 1 that came prior to the user's prompt might also be provided. If it is provided, consider it when determining whether the plan should continue or is complete.
-If AI 1 has outlined a clear next step necessary to finish the plan but has not executed it, the plan should continue.
+If any new subtasks have been added to plan that haven't been implemented yet, either in the latest summary, the latest message from AI 1, or the previous message from AI 1, the plan should continue.
-You might also be supplied with a summary of the plan if one is available. If the summary is available, it will include a list of tasks to be done in the plan and whether each one has been implemented in code yet or not. If the summary is available and all tasks have been completed, the plan should not continue. If the summary is available and there are still tasks to be done, the plan should continue.
+If A1 1 has indicated that the plan is complete, but there are still subtasks remaining that have not been implemented, the plan should continue despite AI 1's statement that the plan is complete. The plan should only be considered complete if all tasks and subtasks have been fully implemented.
-If a summary is not available, the message from AI 1 that came prior to the user's prompt might also be provided. If it is provided, consider it when determining whether the plan should continue or is complete.
+If no subtasks are remaining to be implemented:
+ - 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 keys 'comments', 'reasoning', and 'shouldContinue'.
+
+The 'comments' key is an array of objects with two properties: 'txt' and 'isTodoPlaceholder'. 'txt' is the exact text of a code comment. 'isTodoPlaceholder' is a boolean that indicates whether the comment is a placeholder for a task that has not yet been implemented. This includes comments like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish implementation" or any similar placeholder comments that describe tasks that still remain to be implemented. A todo placeholder does NOT have to exactly match any of the previous examples. Use your judgment to determine whether a comment is a todo placeholder.
-You *must* call the shouldAutoContinue function with a JSON object containing the keys 'reasoning' and 'shouldContinue'.
+In 'comments', you must list EVERY comment included in any code blocks within AI 1's latest response. Only list *code comments* that are valid comments for the programming language being used. Do not list logging statements or any other non-comment text that is not a valid code comment. If are no code blocks in AI 1's response or there are no comments within code blocks, 'comments' must be an empty array.
+
+If any of the comments in the 'comments' array are todo placeholders, the plan MUST continue.
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.
+If there are any todo placeholders in the 'comments' array, list them ALL in 'reasoning'.
+
+If the plan should continue, also state what the immediate next step should be in 'reasoning'.
+
Set 'shouldContinue' to true if the plan should automatically continue based on your instructions above, or false otherwise.
+If any of the comments in the 'comments' array are todo placeholders, 'shouldContinue' must be true.
+
You must always call 'shouldAutoContinue'. Don't call any other function.`
func GetExecStatusShouldContinue(summary, prevAssistantMsg, userPrompt, message string) string {
@@ -50,6 +65,21 @@ var ShouldAutoContinueFn = openai.FunctionDefinition{
Parameters: &jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
+ "comments": {
+ Type: jsonschema.Array,
+ Items: &jsonschema.Definition{
+ Type: jsonschema.Object,
+ Properties: map[string]jsonschema.Definition{
+ "txt": {
+ Type: jsonschema.String,
+ },
+ "isTodoPlaceholder": {
+ Type: jsonschema.Boolean,
+ },
+ },
+ Required: []string{"txt", "isTodoPlaceholder"},
+ },
+ },
"reasoning": {
Type: jsonschema.String,
},
@@ -57,6 +87,6 @@ var ShouldAutoContinueFn = openai.FunctionDefinition{
Type: jsonschema.Boolean,
},
},
- Required: []string{"reasoning", "shouldContinue"},
+ Required: []string{"comments", "reasoning", "shouldContinue"},
},
}
diff --git a/app/server/model/prompts/missing_file.go b/app/server/model/prompts/missing_file.go
index 0e946a2b..9c987eac 100644
--- a/app/server/model/prompts/missing_file.go
+++ b/app/server/model/prompts/missing_file.go
@@ -3,7 +3,7 @@ package prompts
import "fmt"
func GetSkipMissingFilePrompt(path string) string {
- return fmt.Sprintf(`You *must not* generate content for the file %s. Skip this file and continue with the plan according to the 'Your instructions' section if there are any remaining tasks or subtasks. Don't repeat any part of the previous message. If there are no remaining tasks or subtasks, say "All tasks have been completed." per your instructions`, path)
+ return fmt.Sprintf(`You *must not* generate content for the file %s. Skip this file and continue with the plan according to the 'Your instructions' section if there are any remaining tasks or subtasks. Don't repeat any part of the previous message. If there are no remaining tasks or subtasks, stop there.`, path)
}
-const MissingFileContinueGeneratingPrompt = "Continue generating exactly where you left off in the previous message. Don't produce any other output before continuing or repeat any part of the previous message. Do *not* duplicate the last line of the previous response before continuing. Do *not* include triple backticks and a language name like '```python' or '```yaml' at the start of the response, since these have already been included in the previous message. Continue from where you left off seamlessly to generate the rest of the file block. You must include closing triple backticks at the end of the file block. When the file block is finished, continue with the plan according to the 'Your instructions' sections if there are any remaining tasks or subtasks. If there are no remaining tasks or subtasks, say 'All tasks have been completed.' per your instructions."
+const MissingFileContinueGeneratingPrompt = "Continue generating exactly where you left off in the previous message. Don't produce any other output before continuing or repeat any part of the previous message. Do *not* duplicate the last line of the previous response before continuing. Do *not* include triple backticks and a language name like '```python' or '```yaml' at the start of the response, since these have already been included in the previous message. Continue from where you left off seamlessly to generate the rest of the file block. You must include closing triple backticks at the end of the file block. When the file block is finished, continue with the plan according to the 'Your instructions' sections if there are any remaining tasks or subtasks. If there are no remaining tasks or subtasks, stop there."
diff --git a/app/server/model/prompts/summary.go b/app/server/model/prompts/summary.go
index 50d26c87..e407e78b 100644
--- a/app/server/model/prompts/summary.go
+++ b/app/server/model/prompts/summary.go
@@ -57,7 +57,7 @@ Based on the existing summary and the conversation so far, make a summary of the
- Treat the summary as *append-only*. Keep as much information as possible from the existing summary and add the new information from the latest messages. The summary is meant to be a record of the entire plan as it evolves over time.
-- If a subtask has been implemented in code, but the code contains one or more placeholders in comments for functionality that *has not been implemented*, like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish impelementation", or any similar placeholder comments that describe tasks that still remain to be implemented. If comments like these are not followed by the *actual implementation in code*, and this task described in the placeholder comment is not *already* in the list of subtasks, then you MUST append a new subtask to the end of the list for each placeholder comment that has not been implemented, and mark it as not implemented in code. If the task described in the placeholder comment is already in the list of subtasks, then you MUST NOT add it again. When introducing a new subtask baced on a placeholder comment, it should be added as a FULL subtask, not a sub-subtask. It MUST be added to the end of the list.
+- If a subtask has been implemented in code, but the code contains one or more todo placeholders in comments for functionality that *has not been implemented*, like "// Add logic here" or "// Implement the function", or "# Update the state" or " # Finish impelementation", or any similar todo placeholder comments that describe tasks that still remain to be implemented. A todo placeholder does NOT need to match one of the previous examples--use your judgement to identify them. If todo placeholder comments are not followed by the *actual implementation in code*, and this task described in the placeholder comment (or a functionally equivalent task) is not *already* in the list of subtasks, then you MUST append a new subtask to the end of the list for each todo placeholder comment that has not been implemented, and mark it as not implemented in code. If the task described in the todo placeholder comment (or a functionally equivalent task) is already in the list of subtasks, then you MUST NOT add it again. When introducing a new subtask baced on a todo placeholder comment, it should be added as a FULL subtask, not a sub-subtask. It MUST be added to the end of the list and given a number.
- If a new subtask is introduced during the plan, and it is not already in the list of subtasks, and it has not already been implemented in code, then you MUST add it to the list of subtasks and mark it as not implemented in code.
diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.go
index a7bbdbab..27feaa2b 100644
--- a/app/server/types/active_plan.go
+++ b/app/server/types/active_plan.go
@@ -59,6 +59,7 @@ type ActivePlan struct {
CancelModelStreamFn context.CancelFunc
SummaryCtx context.Context
SummaryCancelFn context.CancelFunc
+ LatestSummaryCh chan *db.ConvoSummary
Contexts []*db.Context
ContextsByPath map[string]*db.Context
Files []string
diff --git a/test/test_prompts/pong.txt b/test/test_prompts/pong.txt
index 821fb18a..70d216d4 100644
--- a/test/test_prompts/pong.txt
+++ b/test/test_prompts/pong.txt
@@ -1,2 +1,2 @@
-let's create a basic pong game using C and OpenGL. create all the files for
- the project so that it will be ready to compile and run
+let's create a basic pong game using C and OpenGL. create all the necessary functionality
+ the project so that it will be ready to compile and run. create the whole thing in as few files as you can.