From 7ec6535eefebf6c788bb94d95e3c81b5a006018f Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Sun, 2 Mar 2025 15:18:16 -0500 Subject: [PATCH] gc fixups --- ra_aid/agents/key_facts_gc_agent.py | 64 ++++++++++++++------- ra_aid/prompts/key_facts_cleaner_prompts.py | 51 ++++++++++++++++ ra_aid/prompts/key_facts_gc_prompts.py | 8 ++- 3 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 ra_aid/prompts/key_facts_cleaner_prompts.py diff --git a/ra_aid/agents/key_facts_gc_agent.py b/ra_aid/agents/key_facts_gc_agent.py index 8fd21a5..2cbc144 100644 --- a/ra_aid/agents/key_facts_gc_agent.py +++ b/ra_aid/agents/key_facts_gc_agent.py @@ -25,31 +25,51 @@ key_fact_repository = KeyFactRepository() @tool -def delete_key_fact(fact_id: int) -> str: - """Delete a key fact by its ID. +def delete_key_facts(fact_ids: List[int]) -> str: + """Delete multiple key facts by their IDs. Args: - fact_id: The ID of the key fact to delete + fact_ids: List of IDs of the key facts to delete Returns: str: Success or failure message """ - # Get the fact first to display information - fact = key_fact_repository.get(fact_id) - if fact: - # Delete the fact - was_deleted = key_fact_repository.delete(fact_id) - if was_deleted: - success_msg = f"Successfully deleted fact #{fact_id}: {fact.content}" - console.print( - Panel(Markdown(success_msg), title="Fact Deleted", border_style="green") - ) - log_work_event(f"Deleted fact {fact_id}.") - return success_msg + deleted_facts = [] + not_found_facts = [] + failed_facts = [] + + for fact_id in fact_ids: + # Get the fact first to display information + fact = key_fact_repository.get(fact_id) + if fact: + # Delete the fact + was_deleted = key_fact_repository.delete(fact_id) + if was_deleted: + deleted_facts.append((fact_id, fact.content)) + log_work_event(f"Deleted fact {fact_id}.") + else: + failed_facts.append(fact_id) else: - return f"Failed to delete fact #{fact_id}" - else: - return f"Fact #{fact_id} not found" + not_found_facts.append(fact_id) + + # Prepare result message + result_parts = [] + if deleted_facts: + deleted_msg = "Successfully deleted facts:\n" + "\n".join([f"- #{fact_id}: {content}" for fact_id, content in deleted_facts]) + result_parts.append(deleted_msg) + console.print( + Panel(Markdown(deleted_msg), title="Facts Deleted", border_style="green") + ) + + if not_found_facts: + not_found_msg = f"Facts not found: {', '.join([f'#{fact_id}' for fact_id in not_found_facts])}" + result_parts.append(not_found_msg) + + if failed_facts: + failed_msg = f"Failed to delete facts: {', '.join([f'#{fact_id}' for fact_id in failed_facts])}" + result_parts.append(failed_msg) + + return "\n".join(result_parts) def run_key_facts_gc_agent() -> None: @@ -81,8 +101,8 @@ def run_key_facts_gc_agent() -> None: temperature=llm_config.get("temperature") ) - # Create the agent with the delete_key_fact tool - agent = create_agent(model, [delete_key_fact]) + # Create the agent with the delete_key_facts tool + agent = create_agent(model, [delete_key_facts]) # Format the prompt with the current facts prompt = KEY_FACTS_GC_PROMPT.format(key_facts=formatted_facts) @@ -103,8 +123,8 @@ def run_key_facts_gc_agent() -> None: console.print( Panel( f"Cleaned key facts: {fact_count} → {updated_count}", - title="🗑️ GC Complete" + title="🗑 GC Complete" ) ) else: - console.print(Panel("No key facts to clean.", title="🗑️ GC Info")) \ No newline at end of file + console.print(Panel("No key facts to clean.", title="🗑 GC Info")) \ No newline at end of file diff --git a/ra_aid/prompts/key_facts_cleaner_prompts.py b/ra_aid/prompts/key_facts_cleaner_prompts.py new file mode 100644 index 0000000..8df73c1 --- /dev/null +++ b/ra_aid/prompts/key_facts_cleaner_prompts.py @@ -0,0 +1,51 @@ +""" +Key facts cleaner-specific prompts for the AI agent system. + +This module contains the prompt for the key facts cleaner agent that is +responsible for evaluating and trimming down the stored key facts to keep +only the most valuable ones, ensuring that the collection remains manageable. +""" + +KEY_FACTS_CLEANER_PROMPT = """ +You are a Key Facts Cleaner agent responsible for maintaining the knowledge base by pruning less important facts. + + +{key_facts} + + +Task: +Your task is to analyze all the key facts in the system and determine which ones should be kept and which ones should be removed. + +Guidelines for evaluation: +1. Review all key facts and their IDs +2. Identify which facts are lowest value/most ephemeral based on: + - Relevance to the overall project + - Specificity and actionability of the information + - Long-term value vs. temporary relevance + - Uniqueness of the information (avoid redundancy) + - How fundamental the fact is to understanding the codebase + +3. Trim down the collection to keep no more than 20 highest value, longest-lasting facts +4. For each fact you decide to delete, provide a brief explanation of your reasoning + +Retention priority (from highest to lowest): +- Core architectural facts about the project structure +- Critical implementation details that affect multiple parts of the system +- Important design patterns and conventions +- API endpoints and interfaces +- Configuration requirements +- Build and deployment information +- Testing approaches +- Low-level implementation details that are easily rediscovered + +For facts of similar importance, prefer to keep more recent facts if they supersede older information. + +Output: +1. List the IDs of facts to be deleted +2. Provide a brief explanation for each deletion decision +3. Explain your overall approach to selecting which facts to keep + +Remember: Your goal is to maintain a concise, high-value knowledge base that preserves essential project understanding while removing ephemeral or less critical information. + +DO NOT MENTION, JUSTIFY, OR SAY ANYTHING ABOUT THE FACTS YOU ARE DELETING. JUST DELETE THEM SILENTLY AND EXIT IMMEDIATELY TO CONSERVE RESOURCES. +""" \ No newline at end of file diff --git a/ra_aid/prompts/key_facts_gc_prompts.py b/ra_aid/prompts/key_facts_gc_prompts.py index b75aabb..f3070c6 100644 --- a/ra_aid/prompts/key_facts_gc_prompts.py +++ b/ra_aid/prompts/key_facts_gc_prompts.py @@ -41,9 +41,15 @@ Retention priority (from highest to lowest): For facts of similar importance, prefer to keep more recent facts if they supersede older information. Output: -1. List the IDs of facts to be deleted +1. List the IDs of facts to be deleted using the delete_key_facts tool with the IDs provided as a list [ids...], NOT as a comma-separated string 2. Provide a brief explanation for each deletion decision 3. Explain your overall approach to selecting which facts to keep +IMPORTANT: +- Use the delete_key_facts tool with multiple IDs at once in a single call, rather than making multiple individual deletion calls +- The delete_key_facts tool accepts a list of IDs in the format [id1, id2, id3, ...], not as a comma-separated string +- Batch deletion is much more efficient than calling the deletion function multiple times +- Collect all IDs to delete first, then make a single call to delete_key_facts with the complete list + Remember: Your goal is to maintain a concise, high-value knowledge base that preserves essential project understanding while removing ephemeral or less critical information. """ \ No newline at end of file