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
Fixes for summarization and auto-continue issues, fixes #136
Dane Schneider1235f9f0c672
diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 0490dc4e..ff173933 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -219,7 +219,7 @@ func execTellPlan(return}- if !state.summarizeEarlyMessagesIfNeeded() {+ if !state.injectSummariesAsNeeded() {return}@@ -241,9 +241,13 @@ func execTellPlan(// if the user is continuing the plan, we need to check whether the previous message was a user message or assistant messagelastMessage := state.messages[len(state.messages)-1]+ log.Println("User is continuing plan. Last message:\n\n", lastMessage.Content)+if lastMessage.Role == openai.ChatMessageRoleUser {// if last message was a user message, we want to remove it from the messages array and then use that last message as the prompt so we can continue from where the user left off+ log.Println("User is continuing plan. Last message was user message. Using last user message as prompt")+state.messages = state.messages[:len(state.messages)-1]promptMessage = &openai.ChatCompletionMessage{Role: openai.ChatMessageRoleUser,@@ -252,6 +256,10 @@ func execTellPlan(state.userPrompt = lastMessage.Content} else {++ // if the last message was an assistant message, we'll use the user continue prompt+ log.Println("User is continuing plan. Last message was assistant message. Using user continue prompt")+// otherwise we'll use the continue promptpromptMessage = &openai.ChatCompletionMessage{Role: openai.ChatMessageRoleUser,diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 62ea23b8..9572d4f4 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -111,21 +111,6 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStlatestSummaryCh := active.LatestSummaryCh- log.Println("summarize convo")- envVar := settings.ModelPack.PlanSummary.BaseModelConfig.ApiKeyEnvVar- client := clients[envVar]-- // summarize in the background- go summarizeConvo(client, settings.ModelPack.PlanSummary, summarizeConvoParams{- planId: planId,- branch: branch,- convo: convo,- summaries: summaries,- userPrompt: state.userPrompt,- currentOrgId: currentOrgId,- currentReply: active.CurrentReplyContent,- }, active.SummaryCtx)-var generatedDescription *db.ConvoMessageDescriptionvar shouldContinue boolvar nextTask string@@ -223,7 +208,8 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionSt}}()- assistantMsg, convoCommitMsg, err := state.storeAssistantReply()+ assistantMsg, convoCommitMsg, err := state.storeAssistantReply() // updates state.convo+ convo = state.convoif err != nil {state.onError(fmt.Errorf("failed to store assistant message: %v", err), true, "", "")@@ -273,6 +259,22 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStreturn}+ // summarize convo needs to come *after* the reply is stored in order to correctly summarize the latest message+ log.Println("summarize convo")+ envVar := settings.ModelPack.PlanSummary.BaseModelConfig.ApiKeyEnvVar+ client := clients[envVar]++ // summarize in the background+ go summarizeConvo(client, settings.ModelPack.PlanSummary, summarizeConvoParams{+ planId: planId,+ branch: branch,+ convo: convo,+ summaries: summaries,+ userPrompt: state.userPrompt,+ currentOrgId: currentOrgId,+ currentReply: active.CurrentReplyContent,+ }, active.SummaryCtx)+log.Println("Sending active.CurrentReplyDoneCh <- true")active.CurrentReplyDoneCh <- true@@ -547,6 +549,9 @@ func (state *activeTellStreamState) storeAssistantReply() (*db.ConvoMessage, strap.StoredReplyIds = append(ap.StoredReplyIds, replyId)})+ convo = append(convo, &assistantMsg)+ state.convo = convo+return &assistantMsg, commitMsg, err}diff --git a/app/server/model/plan/tell_summary.go b/app/server/model/plan/tell_summary.goindex 8d7e74dc..f3388e32 100644--- a/app/server/model/plan/tell_summary.go+++ b/app/server/model/plan/tell_summary.go@@ -16,7 +16,7 @@ import ("github.com/sashabaranov/go-openai")-func (state *activeTellStreamState) summarizeEarlyMessagesIfNeeded() bool {+func (state *activeTellStreamState) injectSummariesAsNeeded() bool {convo := state.convosummaries := state.summariestokensBeforeConvo := state.tokensBeforeConvo@@ -170,36 +170,6 @@ func (state *activeTellStreamState) summarizeEarlyMessagesIfNeeded() bool {return true}-// func (state *activeTellStreamState) insertLatestSummary(){-// if len(state.summaries) == 0 {-// return-// }--// latestSummary := state.summaries[len(state.summaries)-1]-// var insertAtIndex int--// for i, convoMessage := range state.convo {-// if convoMessage.Id == latestSummary.LatestConvoMessageId {-// insertAtIndex = i-// break-// }-// }--// if insertAtIndex < 2 {-// return-// }--// state.convo = append(state.convo[:insertAtIndex], append([]*db.ConvoMessage{-// {-// Id: latestSummary.Id, // use summary id as message id-// Role: openai.ChatMessageRoleAssistant,-// Message: latestSummary.Summary,-// CreatedAt: latestSummary.CreatedAt,-// },-// }, state.convo[insertAtIndex:]...)...)--// }-type summarizeConvoParams struct {planId stringbranch string@@ -248,9 +218,12 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, paramsnumMessagesSummarized = latestSummary.NumMessages}- // log.Println("Latest summary:")+ // log.Println("Generating plan summary - latest summary:")// spew.Dump(latestSummary)+ // log.Println("Generating plan summary - convo:")+ // spew.Dump(convo)+if latestSummary == nil {for _, convoMessage := range convo {summaryMessages = append(summaryMessages, &openai.ChatCompletionMessage{@@ -287,6 +260,9 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, paramslatestMessageSummarizedAt = latestConvoMessage.CreatedAt}+ log.Println("generating summary - latestMessageId:", latestMessageId)+ log.Println("generating summary - latestMessageSummarizedAt:", latestMessageSummarizedAt)+if userPrompt != "" {active := GetActivePlan(planId, branch)if active == nil {@@ -319,7 +295,7 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, paramslog.Printf("Calling model for plan summary. Summarizing %d messages\n", len(summaryMessages))- // log.Println("Summary messages:")+ // log.Println("Generating summary - summary messages:")// spew.Dump(summaryMessages)latestSummaryCh := make(chan *db.ConvoSummary, 1)@@ -341,6 +317,9 @@ func summarizeConvo(client *openai.Client, config shared.ModelRoleConfig, paramslog.Printf("summarizeConvo: Summary generated and stored for plan %s\n", params.planId)+ // log.Println("Generated summary:")+ // spew.Dump(summary)+err = db.StoreSummary(summary)if err != nil {diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.goindex b46f4f41..6e2c3f41 100644--- a/app/server/model/prompts/exec_status.go+++ b/app/server/model/prompts/exec_status.go@@ -42,7 +42,7 @@ Between all of these sources, explain whether all subtasks have been implementedIf 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'. You MUST NOT state any subtasks that have been marked implemented in the summary or completed in the latest message or previous message from AI 1. You MUST only state what the next unimplemented subtask is and that should be done next.+If the plan should continue, you MUST state what the immediate next step should be in 'reasoning'. You MUST NOT state any subtasks that have been marked implemented in the summary or completed in the latest message or previous message from AI 1. You MUST only state what the next unimplemented subtask is and that should be done next. Subtasks MUST ALWAYS be completed in order. If subtask 3 was just completed in the latest message, and subtask 4 is the next unimplemented subtask in numerical order, you MUST state that subtask 4 should be done next. You MUST NOT skip any subtasks. You MUST NOT repeat any subtasks that have already been completed, either in the summary or in the latest or previous message from AI 1. If there is no immediate next subtask, you MUST state that the plan is complete.Set 'shouldContinue' to true if the plan should automatically continue based on your instructions above, or false otherwise.diff --git a/releases/server/versions/1.0.2.md b/releases/server/versions/1.0.2.mdindex 262dc08d..0150b9b6 100644--- a/releases/server/versions/1.0.2.md+++ b/releases/server/versions/1.0.2.md@@ -1 +1,2 @@-- Give notes added to context with `plandex load -n 'some note'` automatically generated names.\ No newline at end of file+- Give notes added to context with `plandex load -n 'some note'` automatically generated names.+- Fixes for summarization and auto-continue issues that could Plandex to lose track of where it is in the plan and repeat tasks or do tasks out of order, especially when using `tell` and `continue` after the initial `tell`.\ No newline at end of file