diff --git a/main/xiaozhi-server/core/providers/llm/coze/coze.py b/main/xiaozhi-server/core/providers/llm/coze/coze.py index f4139cb6..a9e10784 100644 --- a/main/xiaozhi-server/core/providers/llm/coze/coze.py +++ b/main/xiaozhi-server/core/providers/llm/coze/coze.py @@ -60,10 +60,10 @@ class LLMProvider(LLMProviderBase): # 如果最后一个是 role="tool",附加到user上 if len(dialogue) > 1 and dialogue[-1]["role"] == "tool": - assistant_msg = "tool call result: " + dialogue[-1]["content"] + assistant_msg = "\ntool call result: " + dialogue[-1]["content"] + "\n\n" while len(dialogue) > 1 : if dialogue[-1]["role"] == "user": - dialogue[-1]["content"] += assistant_msg + dialogue[-1]["content"] = assistant_msg + dialogue[-1]["content"] break dialogue.pop() diff --git a/main/xiaozhi-server/core/providers/llm/dify/dify.py b/main/xiaozhi-server/core/providers/llm/dify/dify.py index 93114129..09f0739e 100644 --- a/main/xiaozhi-server/core/providers/llm/dify/dify.py +++ b/main/xiaozhi-server/core/providers/llm/dify/dify.py @@ -93,10 +93,10 @@ class LLMProvider(LLMProviderBase): # 如果最后一个是 role="tool",附加到user上 if len(dialogue) > 1 and dialogue[-1]["role"] == "tool": - assistant_msg = "tool call result: " + dialogue[-1]["content"] + assistant_msg = "\ntool call result: " + dialogue[-1]["content"] + "\n\n" while len(dialogue) > 1 : if dialogue[-1]["role"] == "user": - dialogue[-1]["content"] += assistant_msg + dialogue[-1]["content"] = assistant_msg + dialogue[-1]["content"] break dialogue.pop() diff --git a/main/xiaozhi-server/core/providers/llm/system_prompt.py b/main/xiaozhi-server/core/providers/llm/system_prompt.py index dc43b901..606f0e4b 100644 --- a/main/xiaozhi-server/core/providers/llm/system_prompt.py +++ b/main/xiaozhi-server/core/providers/llm/system_prompt.py @@ -10,11 +10,13 @@ def get_system_prompt_for_function(functions: str) -> str: TOOL USE -You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. +You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. +You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. # Tool Use Formatting -Tool use is formatted using JSON-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure: +Tool use is formatted using JSON-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. +Here's the structure: {{ @@ -68,16 +70,19 @@ Always adhere to this format for the tool use to ensure proper parsing and execu # Tool Use Guidelines -1. In tags, assess what information you already have and what information you need to proceed with the task. -2. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task. -3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. Each step must be informed by the previous step's result. -4. Formulate your tool use using the XML format specified for each tool. +1. Tools must be called in a separate message, Do not add thoughts when calling tools. The message must start with and end with , with the tool invocation JSON data in between. No additional response content is needed. +2. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. + For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task. +3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. + Each step must be informed by the previous step's result. +4. Formulate your tool use using the JSON format specified for each tool. 5. After each tool use, the user will respond with the result of that tool use. This result will provide you with the necessary information to continue your task or make further decisions. This response may include: - Information about whether the tool succeeded or failed, along with any reasons for failure. - Linter errors that may have arisen due to the changes you made, which you'll need to address. - New terminal output in reaction to the changes, which you may need to consider or act upon. - Any other relevant feedback or information related to the tool use. 6. ALWAYS wait for user confirmation after each tool use before proceeding. Never assume the success of a tool use without explicit confirmation of the result from the user. +7. Tool calls should contain no extra information. Only after receiving the tool's response should you integrate it into a complete reply. It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task. This approach allows you to: 1. Confirm the success of each step before proceeding. @@ -89,10 +94,10 @@ By waiting for and carefully considering the user's response after each tool use ==== -USER'S CUSTOM INSTRUCTIONS +USER CHAT CONTENT -The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines. +The following additional message is the user's chat message, and should be followed to the best of your ability without interfering with the TOOL USE guidelines. - """ +""" return SYSTEM_PROMPT \ No newline at end of file