Skip to content

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

🤖 Plandex → Add XML support for commit message generation and related features

Dane Schneider9fecff80bdd0
diff --git a/app/server/model/name.go b/app/server/model/name.go
index d9a7cace..3d9f0354 100644
--- a/app/server/model/name.go
+++ b/app/server/model/name.go
@@ -1,3 +1,4 @@
+
package model
import (
@@ -25,6 +26,29 @@ func GenPlanName(
ctx context.Context,
) (string, error) {
config := settings.ModelPack.Namer
+ var sysPrompt string
+ var tools []openai.Tool
+ var toolChoice *openai.ToolChoice
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ sysPrompt = prompts.SysPlanNameXml
+ } else {
+ sysPrompt = prompts.SysPlanName
+ tools = []openai.Tool{
+ {
+ Type: "function",
+ Function: &prompts.PlanNameFn,
+ },
+ }
+ choice := openai.ToolChoice{
+ Type: "function",
+ Function: openai.ToolFunction{
+ Name: prompts.PlanNameFn.Name,
+ },
+ }
+ toolChoice = &choice
+ }
+
content := prompts.GetPlanNamePrompt(planContent)
messages := []types.ExtendedChatMessage{
@@ -54,25 +78,20 @@ func GenPlanName(
return "", fmt.Errorf("error executing hook: %v", apiErr)
}
+ reqStarted := time.Now()
req := types.ExtendedChatCompletionRequest{
- Model: config.BaseModelConfig.ModelName,
- Tools: []openai.Tool{
- {
- Type: "function",
- Function: &prompts.PlanNameFn,
- },
- },
- ToolChoice: openai.ToolChoice{
- Type: "function",
- Function: openai.ToolFunction{
- Name: prompts.PlanNameFn.Name,
- },
- },
+ Model: config.BaseModelConfig.ModelName,
+ Messages: messages,
Temperature: config.Temperature,
TopP: config.TopP,
- Messages: messages,
}
- reqStarted := time.Now()
+
+ if tools != nil {
+ req.Tools = tools
+ }
+ if toolChoice != nil {
+ req.ToolChoice = *toolChoice
+ }
resp, err := CreateChatCompletionWithRetries(
clients,
@@ -81,21 +100,43 @@ func GenPlanName(
req,
)
- var res string
- var nameRes prompts.PlanNameRes
+ var planName string
if err != nil {
fmt.Printf("Error during plan name model call: %v\n", err)
return "", err
}
- for _, choice := range resp.Choices {
- if len(choice.Message.ToolCalls) == 1 &&
- choice.Message.ToolCalls[0].Function.Name == prompts.PlanNameFn.Name {
- fnCall := choice.Message.ToolCalls[0].Function
- res = fnCall.Arguments
- break
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ content := resp.Choices[0].Message.Content
+ planName = GetXMLContent(content, "planName")
+ if planName == "" {
+ return "", fmt.Errorf("No planName tag found in XML response")
+ }
+ } else {
+ var res string
+ for _, choice := range resp.Choices {
+ if len(choice.Message.ToolCalls) == 1 &&
+ choice.Message.ToolCalls[0].Function.Name == prompts.PlanNameFn.Name {
+ fnCall := choice.Message.ToolCalls[0].Function
+ res = fnCall.Arguments
+ break
+ }
+ }
+
+ if res == "" {
+ fmt.Println("no namePlan function call found in response")
+ return "", fmt.Errorf("No namePlan function call found in response. This usually means the model failed to generate a valid response.")
+ }
+
+ var nameRes prompts.PlanNameRes
+ bytes := []byte(res)
+ err = json.Unmarshal(bytes, &nameRes)
+ if err != nil {
+ fmt.Printf("Error unmarshalling plan description response: %v\n", err)
+ return "", err
}
+ planName = nameRes.PlanName
}
var inputTokens int
@@ -105,7 +146,7 @@ func GenPlanName(
outputTokens = resp.Usage.CompletionTokens
} else {
inputTokens = numTokens
- outputTokens = shared.GetNumTokensEstimate(res)
+ outputTokens = shared.GetNumTokensEstimate(planName)
}
go func() {
@@ -113,16 +154,15 @@ func GenPlanName(
Auth: auth,
Plan: plan,
DidSendModelRequestParams: &hooks.DidSendModelRequestParams{
- InputTokens: inputTokens,
- OutputTokens: outputTokens,
- ModelName: config.BaseModelConfig.ModelName,
- ModelProvider: config.BaseModelConfig.Provider,
- ModelPackName: settings.ModelPack.Name,
- ModelRole: shared.ModelRolePlanSummary,
- Purpose: "Generated plan name",
- GenerationId: resp.ID,
- PlanId: plan.Id,
-
+ InputTokens: inputTokens,
+ OutputTokens: outputTokens,
+ ModelName: config.BaseModelConfig.ModelName,
+ ModelProvider: config.BaseModelConfig.Provider,
+ ModelPackName: settings.ModelPack.Name,
+ ModelRole: shared.ModelRolePlanSummary,
+ Purpose: "Generated plan name",
+ GenerationId: resp.ID,
+ PlanId: plan.Id,
RequestStartedAt: reqStarted,
Streaming: false,
Req: &req,
@@ -136,21 +176,7 @@ func GenPlanName(
}
}()
- if res == "" {
- fmt.Println("no namePlan function call found in response")
- return "", fmt.Errorf("No namePlan function call found in response. This usually means the model failed to generate a valid response.")
- }
-
- bytes := []byte(res)
-
- err = json.Unmarshal(bytes, &nameRes)
- if err != nil {
- fmt.Printf("Error unmarshalling plan description response: %v\n", err)
- return "", err
- }
-
- return nameRes.PlanName, nil
-
+ return planName, nil
}
func GenPipedDataName(
@@ -163,6 +189,29 @@ func GenPipedDataName(
) (string, error) {
config := settings.ModelPack.Namer
+ var sysPrompt string
+ var tools []openai.Tool
+ var toolChoice *openai.ToolChoice
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ sysPrompt = prompts.SysPipedDataNameXml
+ } else {
+ sysPrompt = prompts.SysPipedDataName
+ tools = []openai.Tool{
+ {
+ Type: "function",
+ Function: &prompts.PipedDataNameFn,
+ },
+ }
+ choice := openai.ToolChoice{
+ Type: "function",
+ Function: openai.ToolFunction{
+ Name: prompts.PipedDataNameFn.Name,
+ },
+ }
+ toolChoice = &choice
+ }
+
content := prompts.GetPipedDataNamePrompt(pipedContent)
messages := []types.ExtendedChatMessage{
@@ -193,31 +242,20 @@ func GenPipedDataName(
}
log.Println("calling piped data name model")
- // log.Printf("model: %s\n", config.BaseModelConfig.ModelName)
- // log.Printf("temperature: %f\n", config.Temperature)
- // log.Printf("topP: %f\n", config.TopP)
-
- // log.Printf("messages: %v\n", messages)
- // log.Println(spew.Sdump(messages))
reqStarted := time.Now()
req := types.ExtendedChatCompletionRequest{
- Model: config.BaseModelConfig.ModelName,
- Tools: []openai.Tool{
- {
- Type: "function",
- Function: &prompts.PipedDataNameFn,
- },
- },
- ToolChoice: openai.ToolChoice{
- Type: "function",
- Function: openai.ToolFunction{
- Name: prompts.PipedDataNameFn.Name,
- },
- },
+ Model: config.BaseModelConfig.ModelName,
+ Messages: messages,
Temperature: config.Temperature,
TopP: config.TopP,
- Messages: messages,
+ }
+
+ if tools != nil {
+ req.Tools = tools
+ }
+ if toolChoice != nil {
+ req.ToolChoice = *toolChoice
}
resp, err := CreateChatCompletionWithRetries(
@@ -227,21 +265,43 @@ func GenPipedDataName(
req,
)
- var res string
- var nameRes prompts.PipedDataNameRes
+ var name string
if err != nil {
fmt.Printf("Error during piped data name model call: %v\n", err)
return "", err
}
- for _, choice := range resp.Choices {
- if len(choice.Message.ToolCalls) == 1 &&
- choice.Message.ToolCalls[0].Function.Name == prompts.PipedDataNameFn.Name {
- fnCall := choice.Message.ToolCalls[0].Function
- res = fnCall.Arguments
- break
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ content := resp.Choices[0].Message.Content
+ name = GetXMLContent(content, "name")
+ if name == "" {
+ return "", fmt.Errorf("No name tag found in XML response")
+ }
+ } else {
+ var res string
+ for _, choice := range resp.Choices {
+ if len(choice.Message.ToolCalls) == 1 &&
+ choice.Message.ToolCalls[0].Function.Name == prompts.PipedDataNameFn.Name {
+ fnCall := choice.Message.ToolCalls[0].Function
+ res = fnCall.Arguments
+ break
+ }
+ }
+
+ if res == "" {
+ fmt.Println("no namePipedData function call found in response")
+ return "", fmt.Errorf("No namePipedData function call found in response. This usually means the model failed to generate a valid response.")
}
+
+ var nameRes prompts.PipedDataNameRes
+ bytes := []byte(res)
+ err = json.Unmarshal(bytes, &nameRes)
+ if err != nil {
+ fmt.Printf("Error unmarshalling piped data name response: %v\n", err)
+ return "", err
+ }
+ name = nameRes.Name
}
var inputTokens int
@@ -251,7 +311,7 @@ func GenPipedDataName(
outputTokens = resp.Usage.CompletionTokens
} else {
inputTokens = numTokens
- outputTokens = shared.GetNumTokensEstimate(res)
+ outputTokens = shared.GetNumTokensEstimate(name)
}
go func() {
@@ -259,16 +319,15 @@ func GenPipedDataName(
Auth: auth,
Plan: plan,
DidSendModelRequestParams: &hooks.DidSendModelRequestParams{
- InputTokens: inputTokens,
- OutputTokens: outputTokens,
- ModelName: config.BaseModelConfig.ModelName,
- ModelProvider: config.BaseModelConfig.Provider,
- ModelPackName: settings.ModelPack.Name,
- ModelRole: shared.ModelRolePlanSummary,
- Purpose: "Generated name for data piped into context",
- GenerationId: resp.ID,
- PlanId: plan.Id,
-
+ InputTokens: inputTokens,
+ OutputTokens: outputTokens,
+ ModelName: config.BaseModelConfig.ModelName,
+ ModelProvider: config.BaseModelConfig.Provider,
+ ModelPackName: settings.ModelPack.Name,
+ ModelRole: shared.ModelRolePlanSummary,
+ Purpose: "Generated name for data piped into context",
+ GenerationId: resp.ID,
+ PlanId: plan.Id,
RequestStartedAt: reqStarted,
Streaming: false,
Req: &req,
@@ -282,21 +341,7 @@ func GenPipedDataName(
}
}()
- if res == "" {
- fmt.Println("no namePipedData function call found in response")
- return "", fmt.Errorf("No namePipedData function call found in response. This usually means the model failed to generate a valid response.")
- }
-
- bytes := []byte(res)
-
- err = json.Unmarshal(bytes, &nameRes)
- if err != nil {
- fmt.Printf("Error unmarshalling piped data name response: %v\n", err)
- return "", err
- }
-
- return nameRes.Name, nil
-
+ return name, nil
}
func GenNoteName(
@@ -309,6 +354,29 @@ func GenNoteName(
) (string, error) {
config := settings.ModelPack.Namer
+ var sysPrompt string
+ var tools []openai.Tool
+ var toolChoice *openai.ToolChoice
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ sysPrompt = prompts.SysNoteNameXml
+ } else {
+ sysPrompt = prompts.SysNoteName
+ tools = []openai.Tool{
+ {
+ Type: "function",
+ Function: &prompts.NoteNameFn,
+ },
+ }
+ choice := openai.ToolChoice{
+ Type: "function",
+ Function: openai.ToolFunction{
+ Name: prompts.NoteNameFn.Name,
+ },
+ }
+ toolChoice = &choice
+ }
+
content := prompts.GetNoteNamePrompt(note)
messages := []types.ExtendedChatMessage{
@@ -338,32 +406,21 @@ func GenNoteName(
return "", fmt.Errorf("error executing hook: %v", apiErr)
}
- log.Println("calling piped data name model")
- // log.Printf("model: %s\n", config.BaseModelConfig.ModelName)
- // log.Printf("temperature: %f\n", config.Temperature)
- // log.Printf("topP: %f\n", config.TopP)
-
- // log.Printf("messages: %v\n", messages)
- // log.Println(spew.Sdump(messages))
+ log.Println("calling note name model")
reqStarted := time.Now()
req := types.ExtendedChatCompletionRequest{
- Model: config.BaseModelConfig.ModelName,
- Tools: []openai.Tool{
- {
- Type: "function",
- Function: &prompts.NoteNameFn,
- },
- },
- ToolChoice: openai.ToolChoice{
- Type: "function",
- Function: openai.ToolFunction{
- Name: prompts.NoteNameFn.Name,
- },
- },
+ Model: config.BaseModelConfig.ModelName,
+ Messages: messages,
Temperature: config.Temperature,
TopP: config.TopP,
- Messages: messages,
+ }
+
+ if tools != nil {
+ req.Tools = tools
+ }
+ if toolChoice != nil {
+ req.ToolChoice = *toolChoice
}
resp, err := CreateChatCompletionWithRetries(
@@ -373,21 +430,43 @@ func GenNoteName(
req,
)
- var res string
- var nameRes prompts.NoteNameRes
+ var name string
if err != nil {
- fmt.Printf("Error during piped data name model call: %v\n", err)
+ fmt.Printf("Error during note name model call: %v\n", err)
return "", err
}
- for _, choice := range resp.Choices {
- if len(choice.Message.ToolCalls) == 1 &&
- choice.Message.ToolCalls[0].Function.Name == prompts.NoteNameFn.Name {
- fnCall := choice.Message.ToolCalls[0].Function
- res = fnCall.Arguments
- break
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ content := resp.Choices[0].Message.Content
+ name = GetXMLContent(content, "name")
+ if name == "" {
+ return "", fmt.Errorf("No name tag found in XML response")
}
+ } else {
+ var res string
+ for _, choice := range resp.Choices {
+ if len(choice.Message.ToolCalls) == 1 &&
+ choice.Message.ToolCalls[0].Function.Name == prompts.NoteNameFn.Name {
+ fnCall := choice.Message.ToolCalls[0].Function
+ res = fnCall.Arguments
+ break
+ }
+ }
+
+ if res == "" {
+ fmt.Println("no nameNote function call found in response")
+ return "", fmt.Errorf("No nameNote function call found in response. This usually means the model failed to generate a valid response.")
+ }
+
+ var nameRes prompts.NoteNameRes
+ bytes := []byte(res)
+ err = json.Unmarshal(bytes, &nameRes)
+ if err != nil {
+ fmt.Printf("Error unmarshalling note name response: %v\n", err)
+ return "", err
+ }
+ name = nameRes.Name
}
var inputTokens int
@@ -397,7 +476,7 @@ func GenNoteName(
outputTokens = resp.Usage.CompletionTokens
} else {
inputTokens = numTokens
- outputTokens = shared.GetNumTokensEstimate(res)
+ outputTokens = shared.GetNumTokensEstimate(name)
}
go func() {
@@ -405,16 +484,15 @@ func GenNoteName(
Auth: auth,
Plan: plan,
DidSendModelRequestParams: &hooks.DidSendModelRequestParams{
- InputTokens: inputTokens,
- OutputTokens: outputTokens,
- ModelName: config.BaseModelConfig.ModelName,
- ModelProvider: config.BaseModelConfig.Provider,
- ModelPackName: settings.ModelPack.Name,
- ModelRole: shared.ModelRolePlanSummary,
- Purpose: "Generated name for note added to context",
- GenerationId: resp.ID,
- PlanId: plan.Id,
-
+ InputTokens: inputTokens,
+ OutputTokens: outputTokens,
+ ModelName: config.BaseModelConfig.ModelName,
+ ModelProvider: config.BaseModelConfig.Provider,
+ ModelPackName: settings.ModelPack.Name,
+ ModelRole: shared.ModelRolePlanSummary,
+ Purpose: "Generated name for note added to context",
+ GenerationId: resp.ID,
+ PlanId: plan.Id,
RequestStartedAt: reqStarted,
Streaming: false,
Req: &req,
@@ -428,19 +506,5 @@ func GenNoteName(
}
}()
- if res == "" {
- fmt.Println("no nameNote function call found in response")
- return "", fmt.Errorf("No nameNote function call found in response. This usually means the model failed to generate a valid response.")
- }
-
- bytes := []byte(res)
-
- err = json.Unmarshal(bytes, &nameRes)
- if err != nil {
- fmt.Printf("Error unmarshalling piped data name response: %v\n", err)
- return "", err
- }
-
- return nameRes.Name, nil
-
+ return name, nil
}
diff --git a/app/server/model/plan/commit_msg.go b/app/server/model/plan/commit_msg.go
index 1ad30b9f..382be36d 100644
--- a/app/server/model/plan/commit_msg.go
+++ b/app/server/model/plan/commit_msg.go
@@ -38,13 +38,36 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
}
}
+ var sysPrompt string
+ var tools []openai.Tool
+ var toolChoice *openai.ToolChoice
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ sysPrompt = prompts.SysDescribeXml
+ } else {
+ sysPrompt = prompts.SysDescribe
+ tools = []openai.Tool{
+ {
+ Type: "function",
+ Function: &prompts.DescribePlanFn,
+ },
+ }
+ choice := openai.ToolChoice{
+ Type: "function",
+ Function: openai.ToolFunction{
+ Name: prompts.DescribePlanFn.Name,
+ },
+ }
+ toolChoice = &choice
+ }
+
messages := []types.ExtendedChatMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: []types.ExtendedChatMessagePart{
{
Type: openai.ChatMessagePartTypeText,
- Text: prompts.SysDescribe,
+ Text: sysPrompt,
},
},
},
@@ -78,24 +101,19 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
reqStarted := time.Now()
req := types.ExtendedChatCompletionRequest{
- Model: config.BaseModelConfig.ModelName,
- Tools: []openai.Tool{
- {
- Type: "function",
- Function: &prompts.DescribePlanFn,
- },
- },
- ToolChoice: openai.ToolChoice{
- Type: "function",
- Function: openai.ToolFunction{
- Name: prompts.DescribePlanFn.Name,
- },
- },
+ Model: config.BaseModelConfig.ModelName,
Messages: messages,
Temperature: config.Temperature,
TopP: config.TopP,
}
+ if tools != nil {
+ req.Tools = tools
+ }
+ if toolChoice != nil {
+ req.ToolChoice = *toolChoice
+ }
+
descResp, err := model.CreateChatCompletionWithRetries(
clients,
&config,
@@ -114,16 +132,50 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
log.Println("Plan description model call complete")
- var descStrRes string
- var desc shared.ConvoMessageDescription
+ var commitMsg string
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ content := descResp.Choices[0].Message.Content
+ commitMsg = GetXMLContent(content, "commitMsg")
+ if commitMsg == "" {
+ return nil, &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "No commitMsg tag found in XML response",
+ }
+ }
+ } else {
+ var descStrRes string
+ for _, choice := range descResp.Choices {
+ if len(choice.Message.ToolCalls) == 1 &&
+ choice.Message.ToolCalls[0].Function.Name == prompts.DescribePlanFn.Name {
+ fnCall := choice.Message.ToolCalls[0].Function
+ descStrRes = fnCall.Arguments
+ break
+ }
+ }
- for _, choice := range descResp.Choices {
- if len(choice.Message.ToolCalls) == 1 &&
- choice.Message.ToolCalls[0].Function.Name == prompts.DescribePlanFn.Name {
- fnCall := choice.Message.ToolCalls[0].Function
- descStrRes = fnCall.Arguments
- break
+ if descStrRes == "" {
+ fmt.Println("no describePlan function call found in response")
+ spew.Dump(descResp)
+ return nil, &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "No describePlan function call found in response. This usually means the model failed to generate a valid response.",
+ }
}
+
+ var desc shared.ConvoMessageDescription
+ err = json.Unmarshal([]byte(descStrRes), &desc)
+ if err != nil {
+ fmt.Printf("Error unmarshalling plan description response: %v\n", err)
+ return nil, &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: fmt.Sprintf("error unmarshalling plan description response: %v", err),
+ }
+ }
+ commitMsg = desc.CommitMsg
}
var inputTokens int
@@ -133,7 +185,7 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
outputTokens = descResp.Usage.CompletionTokens
} else {
inputTokens = numTokens
- outputTokens = shared.GetNumTokensEstimate(descStrRes)
+ outputTokens = shared.GetNumTokensEstimate(commitMsg)
}
log.Println("Sending DidSendModelRequest hook")
@@ -168,33 +220,9 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri
}
}()
- if descStrRes == "" {
- fmt.Println("no describePlan function call found in response")
-
- spew.Dump(descResp)
-
- return nil, &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: "No describePlan function call found in response. This usually means the model failed to generate a valid response.",
- }
- }
-
- descByteRes := []byte(descStrRes)
-
- err = json.Unmarshal(descByteRes, &desc)
- if err != nil {
- fmt.Printf("Error unmarshalling plan description response: %v\n", err)
- return nil, &shared.ApiError{
- Type: shared.ApiErrorTypeOther,
- Status: http.StatusInternalServerError,
- Msg: fmt.Sprintf("error unmarshalling plan description response: %v", err),
- }
- }
-
return &db.ConvoMessageDescription{
PlanId: planId,
- CommitMsg: desc.CommitMsg,
+ CommitMsg: commitMsg,
}, nil
}
diff --git a/app/server/model/plan/exec_status.go b/app/server/model/plan/exec_status.go
index 2bc1879f..3052468b 100644
--- a/app/server/model/plan/exec_status.go
+++ b/app/server/model/plan/exec_status.go
@@ -45,8 +45,6 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
var potentialProblem bool
if len(state.chunkProcessor.replyOperations) == 0 {
- // subtask was marked as completed, but there are no operations to execute
- // we'll let this fall through to the LLM call to verify, since something might have gone wrong
log.Printf("[ExecStatus] ✗ Subtask completion marker found, but there are no operations to execute")
potentialProblem = true
} else {
@@ -78,7 +76,6 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
log.Printf("[ExecStatus] ✗ No subtask completion marker found in message")
}
- // Log all subtasks current state for context
log.Println("[ExecStatus] Current subtasks state:")
for i, task := range state.subtasks {
log.Printf("[ExecStatus] Task %d: %q (finished=%v)", i+1, task.Title, task.IsFinished)
@@ -137,22 +134,25 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
reqStarted := time.Now()
req := types.ExtendedChatCompletionRequest{
- Model: config.BaseModelConfig.ModelName,
- Tools: []openai.Tool{
+ Model: config.BaseModelConfig.ModelName,
+ Messages: messages,
+ Temperature: config.Temperature,
+ TopP: config.TopP,
+ }
+
+ if config.BaseModelConfig.PreferredModelOutputFormat != shared.ModelOutputFormatXml {
+ req.Tools = []openai.Tool{
{
Type: "function",
Function: &prompts.DidFinishSubtaskFn,
},
- },
- ToolChoice: openai.ToolChoice{
+ }
+ req.ToolChoice = openai.ToolChoice{
Type: "function",
Function: openai.ToolFunction{
Name: prompts.DidFinishSubtaskFn.Name,
},
- },
- Messages: messages,
- Temperature: config.Temperature,
- TopP: config.TopP,
+ }
}
resp, err := model.CreateChatCompletionWithRetries(
@@ -167,16 +167,51 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
return execStatusShouldContinueResult{}, nil
}
- var strRes string
- for _, choice := range resp.Choices {
- if len(choice.Message.ToolCalls) == 1 &&
- choice.Message.ToolCalls[0].Function.Name == prompts.DidFinishSubtaskFn.Name {
- strRes = choice.Message.ToolCalls[0].Function.Arguments
- log.Printf("[ExecStatus] Got function response: %s", strRes)
- break
+ var reasoning string
+ var subtaskFinished bool
+
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ content := resp.Choices[0].Message.Content
+ reasoning = GetXMLContent(content, "reasoning")
+ subtaskFinishedStr := GetXMLContent(content, "subtaskFinished")
+ subtaskFinished = subtaskFinishedStr == "true"
+
+ if reasoning == "" || subtaskFinishedStr == "" {
+ return execStatusShouldContinueResult{}, &shared.ApiError{
+ Type: shared.ApiErrorTypeOther,
+ Status: http.StatusInternalServerError,
+ Msg: "Missing required XML tags in response",
+ }
+ }
+ } else {
+ var strRes string
+ for _, choice := range resp.Choices {
+ if len(choice.Message.ToolCalls) == 1 &&
+ choice.Message.ToolCalls[0].Function.Name == prompts.DidFinishSubtaskFn.Name {
+ strRes = choice.Message.ToolCalls[0].Function.Arguments
+ log.Printf("[ExecStatus] Got function response: %s", strRes)
+ break
+ }
+ }
+
+ if strRes == "" {
+ log.Printf("[ExecStatus] No function response found in model output")
+ return execStatusShouldContinueResult{}, nil
+ }
+
+ var res types.ExecStatusResponse
+ if err := json.Unmarshal([]byte(strRes), &res); err != nil {
+ log.Printf("[ExecStatus] Failed to parse response: %v", err)
+ return execStatusShouldContinueResult{}, nil
}
+
+ reasoning = res.Reasoning
+ subtaskFinished = res.SubtaskFinished
}
+ log.Printf("[ExecStatus] Decision: subtaskFinished=%v, reasoning=%v",
+ subtaskFinished, reasoning)
+
var inputTokens int
var outputTokens int
if resp.Usage.CompletionTokens > 0 {
@@ -184,7 +219,7 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
outputTokens = resp.Usage.CompletionTokens
} else {
inputTokens = numTokens
- outputTokens = shared.GetNumTokensEstimate(strRes)
+ outputTokens = shared.GetNumTokensEstimate(reasoning)
}
go func() {
@@ -217,21 +252,8 @@ func (state *activeTellStreamState) execStatusShouldContinue(currentMessage stri
}
}()
- if strRes == "" {
- log.Printf("[ExecStatus] No function response found in model output")
- return execStatusShouldContinueResult{}, nil
- }
-
- var res types.ExecStatusResponse
- if err := json.Unmarshal([]byte(strRes), &res); err != nil {
- log.Printf("[ExecStatus] Failed to parse response: %v", err)
- return execStatusShouldContinueResult{}, nil
- }
-
- log.Printf("[ExecStatus] Decision: subtaskFinished=%v, reasoning=%v",
- res.SubtaskFinished, res.Reasoning)
-
return execStatusShouldContinueResult{
- subtaskFinished: res.SubtaskFinished,
+ subtaskFinished: subtaskFinished,
}, nil
}
+
diff --git a/app/server/model/prompts/describe.go b/app/server/model/prompts/describe.go
index daef04b9..ade1e56c 100644
--- a/app/server/model/prompts/describe.go
+++ b/app/server/model/prompts/describe.go
@@ -1,3 +1,4 @@
+
package prompts
import (
@@ -5,6 +6,11 @@ import (
"github.com/sashabaranov/go-openai/jsonschema"
)
+const SysDescribeXml = `You are an AI parser. You turn an AI's plan for a programming task into a structured description. You MUST output a valid XML response that includes a <commitMsg> tag. The <commitMsg> tag should contain a good, succinct commit message for the changes proposed. Do not use XML attributes - put all data as tag content.
+
+Example response:
+<commitMsg>Add user authentication system with JWT support</commitMsg>`
+
const SysDescribe = "You are an AI parser. You turn an AI's plan for a programming task into a structured description. You MUST call the 'describePlan' function with a valid JSON object that includes the 'commitMsg' key. 'commitMsg' should be a good, succinct commit message for the changes proposed. You must ALWAYS call the 'describePlan' function. Never call any other function."
var DescribePlanFn = openai.FunctionDefinition{
@@ -21,3 +27,4 @@ var DescribePlanFn = openai.FunctionDefinition{
}
const SysPendingResults = "You are an AI commit message summarizer. You take a list of descriptions of pending changes and turn them into a succinct one-line summary of all the pending changes that makes for a good commit message title. Output ONLY this one-line title and nothing else."
+
diff --git a/app/server/model/prompts/exec_status.go b/app/server/model/prompts/exec_status.go
index 17da6115..b292af1c 100644
--- a/app/server/model/prompts/exec_status.go
+++ b/app/server/model/prompts/exec_status.go
@@ -1,3 +1,4 @@
+
package prompts
import (
@@ -5,6 +6,26 @@ import (
"github.com/sashabaranov/go-openai/jsonschema"
)
+const SysExecStatusFinishedSubtaskXml = `You are tasked with evaluating a response generated by another AI (AI 1) that has been given a coding task to implement.
+
+Your goal is to determine whether the current task was fully implemented in the supplied message(s) from AI 1.
+
+To do this, you need to analyze the latest message from AI 1, and possibly previous messages, and then carefully decide based on the following criteria:
+
+First, examining any previous messages along with the current message, assess whether the current task was fully implemented when these messages are taken together. A task is only considered fully implemented if all necessary code changes for that task have been completed with no remaining todo placeholders or partial implementations.
+
+You MUST output a valid XML response that includes a <subtaskStatus> tag. The <subtaskStatus> tag must contain two child tags:
+- <reasoning>: A brief explanation of whether the task was completed and why
+- <subtaskFinished>: Either "true" or "false" indicating if the task is done
+
+Do not use XML attributes - put all data as tag content.
+
+Example response:
+<subtaskStatus>
+<reasoning>Task is complete - all required code changes implemented with no placeholders</reasoning>
+<subtaskFinished>true</subtaskFinished>
+</subtaskStatus>`
+
const SysExecStatusFinishedSubtask = `You are tasked with evaluating a response generated by another AI (AI 1) that has been given a coding task to implement.
Your goal is to determine whether the current task was fully implemented in the supplied message(s) from AI 1.
@@ -24,7 +45,12 @@ The 'subtaskFinished' key is a boolean that indicates whether the current task h
You must always call 'didFinishSubtask'. Don't call any other function.`
func GetExecStatusFinishedSubtask(userPrompt, currentSubtask string, currentMessage string, previousMessages []string) string {
- s := SysExecStatusFinishedSubtask
+ var s string
+ if config.BaseModelConfig.PreferredModelOutputFormat == shared.ModelOutputFormatXml {
+ s = SysExecStatusFinishedSubtaskXml
+ } else {
+ s = SysExecStatusFinishedSubtask
+ }
if userPrompt != "" {
s += "\n\n**Here is the user's prompt:**\n" + userPrompt
@@ -55,3 +81,4 @@ var DidFinishSubtaskFn = openai.FunctionDefinition{
Required: []string{"reasoning", "subtaskFinished"},
},
}
+
diff --git a/app/server/model/prompts/name.go b/app/server/model/prompts/name.go
index 506996be..8264c73c 100644
--- a/app/server/model/prompts/name.go
+++ b/app/server/model/prompts/name.go
@@ -1,3 +1,4 @@
+
package prompts
import (
@@ -5,9 +6,10 @@ import (
"github.com/sashabaranov/go-openai/jsonschema"
)
-type PlanNameRes struct {
- PlanName string `json:"PlanName"`
-}
+const SysPlanNameXml = `You are an AI namer that creates a name for the plan. Most plans will be related to software development. You MUST output a valid XML response that includes a <planName> tag. The <planName> tag should contain a *short* lowercase file name for the plan content. Use dashes as word separators. No spaces, numbers, or special characters. **2-3 words max**. 1-2 words if you can. Shorten and abbreviate where possible. Do not use XML attributes - put all data as tag content.
+
+Example response:
+<planName>add-auth-system</planName>`
const SysPlanName = "You are an AI namer that creates a name for the plan. Most plans will be related to software development. Call the 'namePlan' function with a valid JSON object that includes the 'planName' key. 'planName' is a *short* lowercase file name for the plan content. Use dashes as word separators. No spaces, numbers, or special characters. **2-3 words max**. 1-2 words if you can. Shorten and abbreviate where possible. You must ALWAYS call the 'namePlan' function. Don't call any other function."
@@ -32,6 +34,11 @@ type PipedDataNameRes struct {
Name string `json:"name"`
}
+const SysPipedDataNameXml = `You are an AI namer that creates a name for output that has been piped into context. Take the output into account and also try to guess what command produced it if you can. You MUST output a valid XML response that includes a <name> tag. The <name> tag should contain a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. Do not use XML attributes - put all data as tag content.
+
+Example response:
+<name>git-status</name>`
+
const SysPipedDataName = "You are an AI namer that creates a name for output that has been piped into context. Take the output into account and also try to guess what command produced it if you can. Call the 'namePipedData' function with a valid JSON object that includes the 'name' key. 'name' is a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. You must ALWAYS call the 'namePipedData' function. Don't call any other function."
var PipedDataNameFn = openai.FunctionDefinition{
@@ -55,6 +62,12 @@ type NoteNameRes struct {
Name string `json:"name"`
}
+
+const SysNoteNameXml = `You are an AI namer that creates a name for an arbitrary text note. You MUST output a valid XML response that includes a <name> tag. The <name> tag should contain a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. Do not use XML attributes - put all data as tag content.
+
+Example response:
+<name>meeting-notes</name>`
+
const SysNoteName = "You are an AI namer that creates a name for an arbitrary text note. Call the 'nameNote' function with a valid JSON object that includes the 'name' key. 'name' is a *short* lowercase name for the data. Use dashes as word separators. No spaces, numbers, or special characters. Shorten and abbreviate where possible. You must ALWAYS call the 'nameNote' function. Don't call any other function."
var NoteNameFn = openai.FunctionDefinition{
@@ -73,3 +86,4 @@ var NoteNameFn = openai.FunctionDefinition{
func GetNoteNamePrompt(text string) string {
return SysNoteName + "\n\nNote:\n" + text
}
+