From 0dc0d95b6318a54990ca598ba575261d263bab37 Mon Sep 17 00:00:00 2001
From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
Date: Wed, 2 Oct 2024 04:04:21 -0400
Subject: [PATCH] Provide instructions to model when it fails to use tools
---
src/core/ClaudeDev.ts | 1 +
src/core/prompts/responses.ts | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/core/ClaudeDev.ts b/src/core/ClaudeDev.ts
index 2c52b1f..beff39a 100644
--- a/src/core/ClaudeDev.ts
+++ b/src/core/ClaudeDev.ts
@@ -1771,6 +1771,7 @@ export class ClaudeDev {
type: "text",
text: formatResponse.noToolsUsed(),
})
+ this.consecutiveMistakeCount++
}
const recDidEndLoop = await this.recursivelyMakeClaudeRequests(this.userMessageContent)
diff --git a/src/core/prompts/responses.ts b/src/core/prompts/responses.ts
index b465c92..24642ff 100644
--- a/src/core/prompts/responses.ts
+++ b/src/core/prompts/responses.ts
@@ -11,7 +11,27 @@ export const formatResponse = {
toolError: (error?: string) => `The tool execution failed with the following error:\n\n${error}\n`,
noToolsUsed: () =>
- "If you have completed the user's task, use the attempt_completion tool. If you require additional information from the user, use the ask_followup_question tool. Otherwise, if you have not completed the task and do not need additional information, then proceed with the next step of the task. (This is an automated message, so do not respond to it conversationally.)",
+ `[ERROR] You did not use a tool in your previous response! Please retry with a tool use.
+
+# Instructions for Tool Use
+Tool uses are formatted with the name of the tool enclosed in XML tags on their own line.
+Each parameter is defined within its own set of XML tags, also each on their own line.
+Example:
+
+
+value1
+
+
+value2
+
+
+Ensure that each tool use follows this structure for consistent parsing and execution.
+
+# Next Steps
+If you have completed the user's task, use the attempt_completion tool.
+If you require additional information from the user, use the ask_followup_question tool.
+Otherwise, if you have not completed the task and do not need additional information, then proceed with the next step of the task.
+(This is an automated message, so do not respond to it conversationally.)`,
tooManyMistakes: (feedback?: string) =>
`You seem to be having trouble proceeding. The user has provided the following feedback to help guide you:\n\n${feedback}\n`,