From e27b442efc984f4fbbf8cec4d442a2f8091a3f6a Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Sat, 24 May 2025 18:20:29 +0200 Subject: [PATCH] Prompting --- config/modes/editing.yml | 6 ++++-- config/modes/one-shot.yml | 3 +++ config/modes/planning.yml | 15 ++++++++++++--- serena_config.template.yml | 10 +++++----- src/serena/agent.py | 14 +++++++++----- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/config/modes/editing.yml b/config/modes/editing.yml index bddda04..b42610d 100644 --- a/config/modes/editing.yml +++ b/config/modes/editing.yml @@ -1,5 +1,7 @@ description: All tools, with detailed instructions for code editing prompt: | - You are operating in editing mode. Your task is to implement the requested changes while adhering to the project's - code style and patterns. Use symbolic editing tools whenever possible for precise code modifications. + You are operating in editing mode. You can edit files with the provided tools + to implement the requested changes to the code base while adhering to the project's code style and patterns. + Use symbolic editing tools whenever possible for precise code modifications. + If no editing task has yet been provided, wait for the user to provide one. excluded_tools: [] diff --git a/config/modes/one-shot.yml b/config/modes/one-shot.yml index b408669..1d0f061 100644 --- a/config/modes/one-shot.yml +++ b/config/modes/one-shot.yml @@ -9,6 +9,9 @@ prompt: | Only abort the task if absolutely necessary, such as when critical information is missing that cannot be inferred from the codebase. + + It may be that you have not received a task yet. In this case, wait for the user to provide a task, this will be the + only time you should wait for user interaction. excluded_tools: - get_current_config - activate_project diff --git a/config/modes/planning.yml b/config/modes/planning.yml index 84564ea..53e2989 100644 --- a/config/modes/planning.yml +++ b/config/modes/planning.yml @@ -1,8 +1,17 @@ description: Only read-only tools, focused on analysis and planning prompt: | - You are operating in planning mode. Your task is to analyze code and create a comprehensive plan but not write any code. - Focus on understanding the existing codebase structure, architecture, and functionality to create detailed planning - documents that can be used for future implementation. + You are operating in planning mode. Your task is to analyze code but not write any code. + The user may ask you to assist in creating a comprehensive plan, or to learn something about the codebase - + either a small aspect of it or about the whole project. + When reading code in order to answer a user question or task, you should try reading only the necessary code. + Some tasks may require you to understand the architecture of large parts of the codebase, while for others, + it may be enough to read a single file or a small set of symbols. + You can achieve the intelligent reading of code by using the symbolic tools for getting an overview of symbols and + the relations between them, and then only reading the bodies of symbols that are necessary to answer the question + or complete the task. You can also use the standard tools like list_dir and search_for_pattern if you need to. + You generally have access to memories and it may be useful for you to read them, but also only if they help you + to answer the question or complete the task. You can infer which memories are relevant to the current task by reading + the memory names and descriptions. excluded_tools: - create_text_file - replace_symbol_body diff --git a/serena_config.template.yml b/serena_config.template.yml index 90853f0..ca8d022 100644 --- a/serena_config.template.yml +++ b/serena_config.template.yml @@ -8,15 +8,15 @@ enable_project_activation: True # Add your list of projects here (which you can switch between using "activate_project"). # Every list item must be either -# - a path to a .yml file, absolute or relative to the directory this +# - [Recommended] a path to the project's root directory (e.g. "/path/to/myproject"), with the +# configuration file being located in "/path/to/myproject/.serena/project.yml". +# In this case, the name of the project will be the name of the directory ("myproject"). +# - or a path to a .yml file, absolute or relative to the directory this # configuration file is in (e.g. "myproject.yml" or "/path/to/wherever/myproject.yml"). # In this case, the name of the project will be the base filename of the .yml file # (e.g. "myproject" for "myproject.yml"). -# - or a path to the project's root directory (e.g. "/path/to/myproject"), with the -# configuration file being located in "/path/to/myproject/.serena/project.yml". -# In this case, the name of the project will be the name of the directory ("myproject"). projects: - - myproject.yml + - /path/to/myproject # Whether to open a graphical window with Serena's logs (not supported on macOS). # This is useful both for troubleshooting and for monitoring the tool calls, diff --git a/src/serena/agent.py b/src/serena/agent.py index f93370f..527bfc2 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -1232,8 +1232,6 @@ class CheckOnboardingPerformedTool(Tool): Checks whether project onboarding was already performed. You should always call this tool before beginning to actually work on the project/after activating a project, but after calling the initial instructions tool. - If onboarding was already performed, you will receive a list of available memories. - Don't read the memories immediately after if not needed, just remember that they exist and that you can read them later. """ list_memories_tool = self.agent.get_tool(ListMemoriesTool) memories = json.loads(list_memories_tool.apply()) @@ -1243,7 +1241,13 @@ class CheckOnboardingPerformedTool(Tool): + "You should perform onboarding by calling the `onboarding` tool before proceeding with the task." ) else: - return json.dumps({"result": "Onboarding already performed.", "available_memories": memories}) + return f"""The onboarding was already performed, below is the list of available memories. + Do not read them immediately, just remember that they exist and that you can read them later, if it is necessary + for the current task. + Some memories may be based on previous conversations, others may be general for the current project. + You should be able to tell which one you need based on the name of the memory. + + {memories}""" class OnboardingTool(Tool): @@ -1556,8 +1560,8 @@ class SwitchModesTool(Tool): self.agent.set_modes(mode_instances) # Inform the Agent about the activated modes and the currently active tools - result_str = f"Successfully activated modes: {', '.join([mode.name for mode in mode_instances])}" - result_str += "\n".join([mode_instance.prompt for mode_instance in mode_instances]) + result_str = f"Successfully activated modes: {', '.join([mode.name for mode in mode_instances])}" + "\n" + result_str += "\n".join([mode_instance.prompt for mode_instance in mode_instances]) + "\n" result_str += f"Currently active tools: {', '.join(self.agent.get_active_tool_names())}" return result_str