gc fixups
This commit is contained in:
parent
2418506d7e
commit
7ec6535eef
|
|
@ -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
|
||||
"""
|
||||
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:
|
||||
success_msg = f"Successfully deleted fact #{fact_id}: {fact.content}"
|
||||
console.print(
|
||||
Panel(Markdown(success_msg), title="Fact Deleted", border_style="green")
|
||||
)
|
||||
deleted_facts.append((fact_id, fact.content))
|
||||
log_work_event(f"Deleted fact {fact_id}.")
|
||||
return success_msg
|
||||
else:
|
||||
return f"Failed to delete fact #{fact_id}"
|
||||
failed_facts.append(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"))
|
||||
console.print(Panel("No key facts to clean.", title="🗑 GC Info"))
|
||||
|
|
@ -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>
|
||||
{key_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.
|
||||
"""
|
||||
|
|
@ -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.
|
||||
"""
|
||||
Loading…
Reference in New Issue