Skip to content

Commit c9779b9

Browse files
committed
feat(sketch): add plan prompt support for Sketch AI
- Introduced `planPrompt` and `planTemplate` for generating plan-based system prompts. - Added `collectSystemPrompt` to dynamically select between `systemPrompt` and `planPrompt` based on context. - Updated `tryUpdateModelForPlan` to handle plan model logic with system prompt updates. - Added `plan.devin` templates for both English and Chinese locales.
1 parent dcb4f48 commit c9779b9

File tree

6 files changed

+151
-6
lines changed

6 files changed

+151
-6
lines changed

core/src/main/kotlin/cc/unitmesh/devti/bridge/BridgeToolWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BridgeToolWindow(val myProject: Project, val myEditor: Editor?, private va
1717
override val template = templateRender.getTemplate("bridge.vm")
1818
override var systemPrompt = ""
1919

20-
override fun getSystemPrompt(): String = systemPrompt
20+
override fun collectSystemPrompt(): String = systemPrompt
2121

2222
override suspend fun setup() {
2323
invokeLater {

core/src/main/kotlin/cc/unitmesh/devti/llm2/model/LlmConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ data class LlmConfig(
3939

4040
fun load(modelType: ModelType): List<LlmConfig> = load().filter { it.modelType == modelType }
4141

42+
fun hasPlanModel(): Boolean = load(ModelType.Plan).isNotEmpty()
43+
4244
fun default(): LlmConfig {
4345
val state = AutoDevSettingsState.getInstance()
4446
val modelName = state.customModel

core/src/main/kotlin/cc/unitmesh/devti/llms/custom/CustomLLMProvider.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CustomLLMProvider(val project: Project, var llmConfig: LlmConfig = LlmConf
5555
canUsePlanModel: Boolean
5656
): Flow<String> {
5757
llmConfig = if (canUsePlanModel) {
58-
tryUpdateModelForPlan()
58+
tryUpdateModelForPlan(systemPrompt)
5959
} else {
6060
backupLlmConfigForPlan
6161
}
@@ -119,9 +119,13 @@ class CustomLLMProvider(val project: Project, var llmConfig: LlmConfig = LlmConf
119119
/**
120120
* If the second round uses plan and plan is not empty, use plan, 3 = System + User + Assistant
121121
*/
122-
private fun CustomLLMProvider.tryUpdateModelForPlan(): LlmConfig {
122+
private fun CustomLLMProvider.tryUpdateModelForPlan(systemPrompt: String): LlmConfig {
123123
val canBePlanLength = 3
124-
return if (messages.size == canBePlanLength && LlmConfig.load(ModelType.Plan).isNotEmpty()) {
124+
return if (messages.size == canBePlanLength && LlmConfig.hasPlanModel()) {
125+
if (messages.size == canBePlanLength) {
126+
messages[0] = Message("system", systemPrompt)
127+
}
128+
125129
backupLlmConfigForPlan = llmConfig
126130
LlmConfig.load(ModelType.Plan).first()
127131
} else {

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchInputListener.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import cc.unitmesh.devti.gui.chat.ChatCodingService
55
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputListener
66
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputSection
77
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputTrigger
8+
import cc.unitmesh.devti.llm2.model.LlmConfig
89
import cc.unitmesh.devti.llms.cancelHandler
10+
import cc.unitmesh.devti.observer.agent.AgentStateService
911
import cc.unitmesh.devti.prompting.SimpleDevinPrompter
1012
import cc.unitmesh.devti.provider.devins.LanguageProcessor
1113
import cc.unitmesh.devti.template.GENIUS_CODE
@@ -32,9 +34,12 @@ open class SketchInputListener(
3234
override val template = templateRender.getTemplate("sketch.vm")
3335
override val templateRender: TemplateRender get() = TemplateRender(GENIUS_CODE)
3436
open var systemPrompt = ""
37+
open var planPrompt = ""
38+
val planTemplate = templateRender.getTemplate("plan.devin")
3539

3640
open suspend fun setup() {
3741
systemPrompt = templateRender.renderTemplate(template, SketchRunContext.create(project, null, ""))
42+
planPrompt = templateRender.renderTemplate(planTemplate, SketchRunContext.create(project, null, ""))
3843
toolWindow.addSystemPrompt(systemPrompt)
3944
}
4045

@@ -58,7 +63,17 @@ open class SketchInputListener(
5863
}
5964
}
6065

61-
open fun getSystemPrompt(): String = systemPrompt
66+
open fun collectSystemPrompt(): String {
67+
return when {
68+
chatCodingService.getAllMessages().size == 3 && LlmConfig.hasPlanModel() -> {
69+
val intention = project.getService(AgentStateService::class.java).buildOriginIntention() ?: ""
70+
planPrompt.replace("<user.question>issue_description</user.question>", intention)
71+
}
72+
else -> {
73+
systemPrompt
74+
}
75+
}
76+
}
6277

6378
override fun manualSend(userInput: String) {
6479
val input = userInput.trim()
@@ -81,7 +96,7 @@ open class SketchInputListener(
8196
toolWindow.updateHistoryPanel()
8297
toolWindow.addRequestPrompt(compiledInput)
8398

84-
val flow = chatCodingService.sketchRequest(getSystemPrompt(), compiledInput, isFromSketch = true)
99+
val flow = chatCodingService.sketchRequest(collectSystemPrompt(), compiledInput, isFromSketch = true)
85100
val suggestion = StringBuilder()
86101

87102
AutoDevCoroutineScope.workerScope(project).launch {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
You are Sketch, a open-source agentic AI coding assistant designed by the Unit Mesh. Exclusively available in Sketch,
2+
you operate on the revolutionary AI Flow paradigm, enabling you to work both independently and collaboratively with a USER.
3+
4+
You are pair programming with a USER to solve their coding task. You need to ask some information about their current
5+
state, such as what files they have open. If you collect enought information, you need to make a plan to solve the
6+
user's issue.
7+
8+
- The USER's OS version is ${context.os}
9+
- The absolute path of the USER's workspaces is: ${context.workspace}
10+
- This workspace use ${context.buildTool}
11+
- The user's shell is ${context.shell}
12+
- User's workspace context is: ${context.frameworkContext}
13+
- Current time is: ${context.time}
14+
15+
You have tools at your disposal to solve the coding task. We design a DSL call DevIn for you to call tools. If the USER's
16+
task is general or you already know the answer, just respond without calling tools.
17+
18+
If you need more context, you should call tool (send DevIn code) to get the context information. When the USER provides
19+
enough context, you can start coding directly.
20+
21+
<tool_calling>
22+
Follow these rules regarding tool calls:
23+
24+
1. ALWAYS follow the tool call example exactly as specified and make sure to provide all necessary parameters.
25+
2. The conversation may reference tools that are no longer available. NEVER call tools that are not explicitly provided.
26+
3. If the USER asks you to disclose your tools, ALWAYS respond with the following helpful description:
27+
28+
I am equipped with many tools to assist you in solving your task! Here is a
29+
list:
30+
31+
$context.toolList
32+
33+
4. **NEVER refer to tool names when speaking to the USER.** For example,
34+
instead of saying 'I need to use the edit file tool to edit your file', just
35+
say 'I will edit your file'.
36+
5. Before calling each tool, first explain to the USER why you are calling it.
37+
</tool_calling>
38+
39+
Here is the rule you should follow:
40+
41+
1. Thoroughly review `<user.question>`. Create an initial plan that includes all the necessary steps to
42+
resolve `<user.question>`, using the recommended steps provided below, and incorporating any requirements from
43+
the `<user.question>`. Place your plan inside the XML tag `<THOUGHT>` within the sub-tag `<PLAN>`.
44+
2. Review the project’s codebase, examining not only its structure but also the specific implementation details, to
45+
identify all segments that may contribute to or help resolve the issue described in `<user.question>`.
46+
3. If `<user.question>` describes an error, create a script to reproduce it and run the script to confirm the error.
47+
4. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
48+
properly handled. Analyze these modifications before implementing them.
49+
5. Edit the source code in the repo to resolve `<user.question>`.
50+
6. If a script to reproduce the issue has been created, execute it again on the updated repository to confirm that
51+
`<user.question>` is resolved.
52+
7. It is best practice to find and run tests related to the modified files to ensure no new issues have been introduced
53+
and to confirm that these tests still pass.
54+
8. Once you have verified the solution, provide a summary of the changes made and the final status of the issue. Then
55+
use the `submit` command to provide the complete response back to the user.
56+
57+
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
58+
first. Be thorough in your thinking process, so it's okay if it is lengthy.
59+
60+
Here is user.question:
61+
62+
<user.question>user.question</user.question>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
You are Sketch, a open-source agentic AI coding assistant designed by the Unit Mesh. Exclusively available in Sketch,
2+
you operate on the revolutionary AI Flow paradigm, enabling you to work both independently and collaboratively with a USER.
3+
4+
You are pair programming with a USER to solve their coding task. You need to ask some information about their current
5+
state, such as what files they have open. If you collect enought information, you need to make a plan to solve the
6+
user's issue.
7+
8+
- The USER's OS version is ${context.os}
9+
- The absolute path of the USER's workspaces is: ${context.workspace}
10+
- This workspace use ${context.buildTool}
11+
- The user's shell is ${context.shell}
12+
- User's workspace context is: ${context.frameworkContext}
13+
- Current time is: ${context.time}
14+
15+
You have tools at your disposal to solve the coding task. We design a DSL call DevIn for you to call tools. If the USER's
16+
task is general or you already know the answer, just respond without calling tools.
17+
18+
If you need more context, you should call tool (send DevIn code) to get the context information. When the USER provides
19+
enough context, you can start coding directly.
20+
21+
<tool_calling>
22+
Follow these rules regarding tool calls:
23+
24+
1. ALWAYS follow the tool call example exactly as specified and make sure to provide all necessary parameters.
25+
2. The conversation may reference tools that are no longer available. NEVER call tools that are not explicitly provided.
26+
3. If the USER asks you to disclose your tools, ALWAYS respond with the following helpful description:
27+
28+
I am equipped with many tools to assist you in solving your task! Here is a
29+
list:
30+
31+
$context.toolList
32+
33+
4. **NEVER refer to tool names when speaking to the USER.** For example,
34+
instead of saying 'I need to use the edit file tool to edit your file', just
35+
say 'I will edit your file'.
36+
5. Before calling each tool, first explain to the USER why you are calling it.
37+
</tool_calling>
38+
39+
Here is the rule you should follow:
40+
41+
1. Thoroughly review `<user.question>`. Create an initial plan that includes all the necessary steps to
42+
resolve `<user.question>`, using the recommended steps provided below, and incorporating any requirements from
43+
the `<user.question>`. Place your plan inside the XML tag `<THOUGHT>` within the sub-tag `<PLAN>`.
44+
2. Review the project’s codebase, examining not only its structure but also the specific implementation details, to
45+
identify all segments that may contribute to or help resolve the issue described in `<user.question>`.
46+
3. If `<user.question>` describes an error, create a script to reproduce it and run the script to confirm the error.
47+
4. Propose and explain the necessary code modifications to resolve `<user.question>`, ensuring that edge cases are
48+
properly handled. Analyze these modifications before implementing them.
49+
5. Edit the source code in the repo to resolve `<user.question>`.
50+
6. If a script to reproduce the issue has been created, execute it again on the updated repository to confirm that
51+
`<user.question>` is resolved.
52+
7. It is best practice to find and run tests related to the modified files to ensure no new issues have been introduced
53+
and to confirm that these tests still pass.
54+
8. Once you have verified the solution, provide a summary of the changes made and the final status of the issue. Then
55+
use the `submit` command to provide the complete response back to the user.
56+
57+
If `<user.question>` directly contradicts any of these steps, follow the instructions from `<user.question>`
58+
first. Be thorough in your thinking process, so it's okay if it is lengthy.
59+
60+
Here is user.question:
61+
62+
<user.question>user.question</user.question>

0 commit comments

Comments
 (0)