From b5e4c6404262ca1f56a1ed8d0d56ea991f4f4c9d Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Mon, 10 Mar 2025 16:41:09 -0400 Subject: [PATCH] improve prompts; make list_directory more resilient --- ra_aid/agents/research_agent.py | 4 ++-- ra_aid/prompts/reasoning_assist_prompt.py | 11 ++++++++--- ra_aid/tools/list_directory.py | 2 +- tests/ra_aid/tools/test_list_directory.py | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ra_aid/agents/research_agent.py b/ra_aid/agents/research_agent.py index 667f07b..381cb9e 100644 --- a/ra_aid/agents/research_agent.py +++ b/ra_aid/agents/research_agent.py @@ -110,7 +110,7 @@ def run_research_agent( try: human_input_repository = get_human_input_repository() recent_inputs = human_input_repository.get_recent(1) - if recent_inputs and len(recent_inputs) > 0: + if recent_inputs and len(recent_inputs) > 0 and recent_inputs[0].content != base_task_or_query: last_human_input = recent_inputs[0].content base_task = ( f"{last_human_input}\n{base_task}" @@ -195,7 +195,7 @@ def run_research_agent( tool_info = get_tool_info(tool.func) name = tool.func.__name__ description = inspect.getdoc(tool.func) - tool_metadata.append(f"Tool: {name}\nDescription: {description}\n") + tool_metadata.append(f"Tool: {tool_info}\nDescription: {description}\n") except Exception as e: logger.warning(f"Error getting tool info for {tool}: {e}") diff --git a/ra_aid/prompts/reasoning_assist_prompt.py b/ra_aid/prompts/reasoning_assist_prompt.py index 1f7dfd8..f6c11e7 100644 --- a/ra_aid/prompts/reasoning_assist_prompt.py +++ b/ra_aid/prompts/reasoning_assist_prompt.py @@ -46,6 +46,7 @@ WE DO NOT WANT TO EXCESSIVELY EMIT TINY KEY SNIPPETS --THEY SHOULD BE "paragraph Given the available information, tools, and base task, write a couple paragraphs about how an agentic system might use the available tools to plan the base task, break it down into tasks, and request implementation of those tasks. The agent will not be writing any code at this point, so we should keep it to high level tasks and keep the focus on project planning. The agent has a tendency to do the same work/functin calls over and over again. +The agent is so dumb it needs you to explicitly say how to use the parameters to the tools as well. Answer quickly and confidently with five sentences at most. @@ -61,6 +62,7 @@ PROPOSE THE TASK BREAKDOWN TO THE AGENT. INCLUDE THIS AS A BULLETED LIST IN YOUR WE ARE NOT WRITING ANY CODE AT THIS STAGE. THE AGENT IS VERY FORGETFUL AND YOUR WRITING MUST INCLUDE REMARKS ABOUT HOW IT SHOULD USE *ALL* AVAILABLE TOOLS, INCLUDING AND ESPECIALLY ask_expert. THE AGENT IS DUMB AND NEEDS REALLY DETAILED GUIDANCE LIKE LITERALLY REMINDING IT TO CALL request_task_implementation FOR EACH TASK IN YOUR BULLETED LIST. +YOU MUST MENTION request_task_implementation AT LEAST ONCE. """ REASONING_ASSIST_PROMPT_IMPLEMENTATION = """Current Date: {current_date} @@ -105,6 +107,8 @@ IF ANYTHING AT ALL GOES WRONG, CALL ask_expert. Given the available information, tools, and base task, write a couple paragraphs about how an agentic system might use the available tools to implement the given task definition. The agent will be writing code and making changes at this point. +The agent is so dumb it needs you to explicitly say how to use the parameters to the tools as well. + Answer quickly and confidently with a few sentences at most. WRITE AT LEAST ONE SENTENCE @@ -156,9 +160,7 @@ IF INFORMATION IS TOO COMPLEX TO UNDERSTAND, THE AGENT SHOULD USE ask_expert. Given the available information, tools, and base task or query, write a couple paragraphs about how an agentic system might use the available tools to research the codebase, identify important components, gather key information, and emit key facts and snippets. The focus is on thorough investigation and understanding before any implementation. Remember, the research agent generally should emit research notes at the end of its execution, right before it calls request_implementation if a change or new work is required. -**IF APPLICABLE*, instruct the agent to grep or read actual library code including system include files, python library files, files in node_modules, etc. and emit key snippets on those. The agent is dumb and will need specific paths to directories/files to look in and how to use tools to do this. - -The agent is so dumb it needs you to explicitly say how to use the parameters to the tools as well, e.g. base_dir for ripgrep tool. +The agent is so dumb it needs you to explicitly say how to use the parameters to the tools as well. Answer quickly and confidently with five sentences at most. @@ -170,4 +172,7 @@ REFERENCE ACTUAL TOOL NAMES IN YOUR WRITING, BUT KEEP THE WRITING PLAIN LOGICAL BE DETAILED AND INCLUDE LOGIC BRANCHES FOR WHAT TO DO IF DIFFERENT TOOLS RETURN DIFFERENT THINGS. THINK OF IT AS A FLOW CHART BUT IN NATURAL ENGLISH. THE AGENT IS VERY FORGETFUL AND YOUR WRITING MUST INCLUDE REMARKS ABOUT HOW IT SHOULD USE *ALL* AVAILABLE TOOLS, INCLUDING AND ESPECIALLY ask_expert. + +REMEMBER WE ARE INSTRUCTING THE AGENT **HOW TO DO RESEARCH ABOUT WHAT ALREADY EXISTS** AT THIS POINT USING THE TOOLS AVAILABLE. YOU ARE NOT TO DO THE ACTUAL RESEARCH YOURSELF. IF AN IMPLEMENTATION IS REQUESTED, THE AGENT SHOULD BE INSTRUCTED TO CALL request_task_implementation BUT ONLY AFTER EMITTING RESEARCH NOTES, KEY FACTS, AND KEY SNIPPETS AS RELEVANT. +IT IS IMPERATIVE THAT WE DO NOT START DIRECTLY IMPLEMENTING ANYTHING AT THIS POINT. WE ARE RESEARCHING, THEN CALLING request_implementation *AT MOST ONCE*. """ diff --git a/ra_aid/tools/list_directory.py b/ra_aid/tools/list_directory.py index ad17ced..285f7ff 100644 --- a/ra_aid/tools/list_directory.py +++ b/ra_aid/tools/list_directory.py @@ -200,7 +200,7 @@ def list_directory_tree( """ root_path = Path(path).resolve() if not root_path.exists(): - raise ValueError(f"Path does not exist: {path}") + return f"Error: Path does not exist: {path}" # Load .gitignore patterns if present (only needed for directories) spec = None diff --git a/tests/ra_aid/tools/test_list_directory.py b/tests/ra_aid/tools/test_list_directory.py index ce11ee9..968f620 100644 --- a/tests/ra_aid/tools/test_list_directory.py +++ b/tests/ra_aid/tools/test_list_directory.py @@ -128,7 +128,7 @@ def test_gitignore_patterns(): def test_invalid_path(): """Test error handling for invalid paths""" - with pytest.raises(ValueError, match="Path does not exist"): - list_directory_tree.invoke({"path": "/nonexistent/path"}) + result = list_directory_tree.invoke({"path": "/nonexistent/path"}) + assert "Error: Path does not exist: /nonexistent/path" in result # We now allow files to be passed to list_directory_tree, so we don't test for this case anymore