From 0395340881c92bde273b184028234c4687ac3d73 Mon Sep 17 00:00:00 2001 From: V-R-Dighe Date: Tue, 6 Aug 2024 16:13:30 +0530 Subject: [PATCH] Updated the error messages --- agents/sirji_agents/llm/generic/infer.py | 10 +++++----- .../llm/generic/system_prompts/anthropic.py | 3 +++ .../sirji_agents/llm/generic/system_prompts/default.py | 5 +++-- .../messages/actions/find_and_replace.py | 2 +- messages/sirji_messages/parser.py | 2 +- sirji/vscode-extension/src/utils/executor/executor.ts | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/agents/sirji_agents/llm/generic/infer.py b/agents/sirji_agents/llm/generic/infer.py index d37bf04..3aca151 100644 --- a/agents/sirji_agents/llm/generic/infer.py +++ b/agents/sirji_agents/llm/generic/infer.py @@ -68,19 +68,19 @@ def __get_response(self, conversation): raise e self.logger.info(f"Requesting LLM to resend the message in correct format.\n") conversation.append({"role": "assistant", "content": response_message, "parsed_content": {}}) - conversation.append({"role": "user", "content": "Error obtained in processing your last response. Your response must conform strictly to one of the allowed Response Templates, as it will be processed programmatically and only these templates are recognized. Your response must be enclosed within '***' at the beginning and end, without any additional text above or below these markers. Not conforming above rules will lead to response processing errors."}) + conversation.append({"role": "user", "content": "Error obtained in processing your last message. Your last message has been discarded. The message must conform strictly to one of the allowed Response Templates, as it will be processed programmatically and only these templates are recognized. Your message must be enclosed within '***' at the beginning and end, without any additional text above or below these markers. Not conforming above rules will lead to response processing errors."}) if isinstance(e, MessageMissingPropertyError): conversation.append({"role": "assistant", "content": response_message, "parsed_content": {}}) - conversation.append({"role": "user", "content": "Error obtained in processing your last response. your response is missing some required properties. Please refer to the allowed response templates and provide the missing properties."}) + conversation.append({"role": "user", "content": "Error obtained in processing your last message. Your last message has been discarded. The message is missing some required properties. Please refer to the allowed response templates and provide the missing properties."}) if isinstance(e, MessageUnRecognizedActionError): conversation.append({"role": "assistant", "content": response_message, "parsed_content": {}}) - conversation.append({"role": "user", "content": "Error obtained in processing your last response. Your response contains an unrecognized action. Please refer to the allowed response templates and provide a valid action."}) + conversation.append({"role": "user", "content": "Error obtained in processing your last message. Your last message has been discarded. The message contains an unrecognized action. Please refer to the allowed response templates and provide a valid action."}) if isinstance(e, MessageLengthConstraintError): conversation.append({"role": "assistant", "content": response_message, "parsed_content": {}}) - conversation.append({"role": "user", "content": "Error obtained in processing your last response. Your response does not have all the required properties."}) + conversation.append({"role": "user", "content": "Error obtained in processing your last message. Your last message has been discarded. The message does not have all the required properties."}) if isinstance(e, MessageMultipleActionError): conversation.append({"role": "assistant", "content": response_message, "parsed_content": {}}) - conversation.append({"role": "user", "content": "Error obtained in processing your last response. Your response contains more than one ACTION keyword."}) + conversation.append({"role": "user", "content": "Error obtained in processing your last message. Your last message has been discarded. The message contains more than one 'ACTION' keyword. Send only one 'ACTION' at a time."}) except Exception as e: self.logger.info(f"Generic error while parsing message. Error: {e}\n") raise e diff --git a/agents/sirji_agents/llm/generic/system_prompts/anthropic.py b/agents/sirji_agents/llm/generic/system_prompts/anthropic.py index a108993..b7ad5e7 100644 --- a/agents/sirji_agents/llm/generic/system_prompts/anthropic.py +++ b/agents/sirji_agents/llm/generic/system_prompts/anthropic.py @@ -99,6 +99,9 @@ def system_prompt(self): action_list.add(ActionEnum[action]) allowed_response_templates_str += '\n' + allowed_response_templates(AgentEnum.ANY, AgentEnum.EXECUTOR, action_list) + '\n' + action_list_researcher = permissions_dict[(AgentEnum.ANY, AgentEnum.RESEARCHER)] + allowed_response_templates_str += '\n' + allowed_response_templates(AgentEnum.ANY, AgentEnum.RESEARCHER, action_list_researcher) + '\n' + allowed_response_templates_str += f"""For updating in project folder use either {ActionEnum.FIND_AND_REPLACE.name}, {ActionEnum.INSERT_ABOVE.name} or {ActionEnum.INSERT_BELOW.name} actions. Ensure you provide the exact matching string in find from file, with the exact number of lines and proper indentation for insert and replace actions.\n""" allowed_response_templates_str += '\n' + allowed_response_templates(AgentEnum.ANY, AgentEnum.CALLER, permissions_dict[(AgentEnum.ANY, AgentEnum.CALLER)]) + '\n' diff --git a/agents/sirji_agents/llm/generic/system_prompts/default.py b/agents/sirji_agents/llm/generic/system_prompts/default.py index f703b57..d19bf6d 100644 --- a/agents/sirji_agents/llm/generic/system_prompts/default.py +++ b/agents/sirji_agents/llm/generic/system_prompts/default.py @@ -49,7 +49,8 @@ def system_prompt(self): - Execute the sub-tasks associated with each of these matching skills. - Do not respond with two actions in the same response. Respond with one action at a time. - Always use {ActionEnum.STORE_IN_AGENT_OUTPUT.name} and {ActionEnum.READ_AGENT_OUTPUT_FILES.name} to write and read files to and from the agent output folder. - - If any step is not applicable or cannot be followed, use the DO_NOTHING action to skip it. + - If any step is not applicable or cannot be followed, use the DO_NOTHING action to skip it. + - On getting error multiple times, that you have skipped a step you need to consult with the SIRJI_USER. """) formatted_skills = self.__format_skills() @@ -121,7 +122,7 @@ def __format_skills(self): output_text += f"Skill: {self.config['skill']}\n" - output_text += f"Make sure to first convert all the points mentioned in Pseudo code in plain english to steps having at max 10 words each and log these steps using {ActionEnum.LOG_STEPS.name} action.\n" + output_text += f"Make sure to first convert all the points mentioned in Pseudo code to plain english steps having at max 10 words each. Ensure to have one and only one plain english step for each pseudo code point. Log these plain english steps using {ActionEnum.LOG_STEPS.name} action.\n" output_text += "Then, execute the steps in the order they are logged.\n" output_text += f"Pseudo code which you must follow:\n{self.config['pseudo_code']}" output_text += "\n" diff --git a/messages/sirji_messages/messages/actions/find_and_replace.py b/messages/sirji_messages/messages/actions/find_and_replace.py index 6fd1800..8ff3ed4 100644 --- a/messages/sirji_messages/messages/actions/find_and_replace.py +++ b/messages/sirji_messages/messages/actions/find_and_replace.py @@ -19,7 +19,7 @@ def sample(self): "summary": "{{Display a concise summary to the user, describing the action using the present continuous tense.}}", "body": textwrap.dedent(""" FILE_PATH: - {{File path}} + {{File path}} --- FIND: {{Code to Find}} diff --git a/messages/sirji_messages/parser.py b/messages/sirji_messages/parser.py index c116afc..ab84d2a 100644 --- a/messages/sirji_messages/parser.py +++ b/messages/sirji_messages/parser.py @@ -39,7 +39,7 @@ def _validate_message(message): message = message.strip() if not (message.startswith("***") and message.endswith("***")): raise MessageIncorrectFormatError("Message must start and end with ***") - if message.count("ACTION") > 1: + if message.count("ACTION:") > 1: raise MessageMultipleActionError("Message contains more than one ACTION keyword") message = message[3:-3].strip() lines = message.split("\n") diff --git a/sirji/vscode-extension/src/utils/executor/executor.ts b/sirji/vscode-extension/src/utils/executor/executor.ts index 209519f..a7bd23f 100644 --- a/sirji/vscode-extension/src/utils/executor/executor.ts +++ b/sirji/vscode-extension/src/utils/executor/executor.ts @@ -91,7 +91,7 @@ export class Executor { console.log('LOG_STEPS', oThis.parsedMessage.BODY, oThis.agentStack); return await oThis.stepManager.createStepsFile(oThis.agentStack, oThis.parsedMessage.BODY); default: - return `Invalid message ACTION: ${action} sent to executor. Your response must conform strictly to one of the allowed Response Templates, as it will be processed programmatically and only these templates are recognized. Your response must be enclosed within '***' at the beginning and end, without any additional text above or below these markers. Not conforming above rules will lead to response processing errors.`; + return `Invalid message "ACTION": ${action} sent to executor. Your response must conform strictly to one of the allowed Response Templates, as it will be processed programmatically and only these templates are recognized. Your response must be enclosed within '***' at the beginning and end, without any additional text above or below these markers. Not conforming above rules will lead to response processing errors.`; } }