simplify tool return values

This commit is contained in:
AI Christianson 2024-12-11 14:01:14 -05:00
parent cb8ee556e5
commit 6b56a0e198
2 changed files with 36 additions and 50 deletions

View File

@ -84,11 +84,11 @@ def emit_research_subtask(subtask: str) -> str:
""" """
_global_memory['research_subtasks'].append(subtask) _global_memory['research_subtasks'].append(subtask)
console.print(Panel(Markdown(subtask), title="🔬 Research Subtask")) console.print(Panel(Markdown(subtask), title="🔬 Research Subtask"))
return f"Added research subtask: {subtask}" return "Subtask added."
@tool("emit_key_facts") @tool("emit_key_facts")
def emit_key_facts(facts: List[str]) -> List[str]: def emit_key_facts(facts: List[str]) -> str:
"""Store multiple key facts about the project or current task in global memory. """Store multiple key facts about the project or current task in global memory.
Args: Args:
@ -112,11 +112,11 @@ def emit_key_facts(facts: List[str]) -> List[str]:
# Add result message # Add result message
results.append(f"Stored fact #{fact_id}: {fact}") results.append(f"Stored fact #{fact_id}: {fact}")
return results return "Facts stored."
@tool("delete_key_facts") @tool("delete_key_facts")
def delete_key_facts(fact_ids: List[int]) -> List[str]: def delete_key_facts(fact_ids: List[int]) -> str:
"""Delete multiple key facts from global memory by their IDs. """Delete multiple key facts from global memory by their IDs.
Silently skips any IDs that don't exist. Silently skips any IDs that don't exist.
@ -135,7 +135,7 @@ def delete_key_facts(fact_ids: List[int]) -> List[str]:
console.print(Panel(Markdown(success_msg), title="🗑️ Fact Deleted", border_style="green")) console.print(Panel(Markdown(success_msg), title="🗑️ Fact Deleted", border_style="green"))
results.append(success_msg) results.append(success_msg)
return results return "Facts deleted."
@tool("request_implementation") @tool("request_implementation")
def request_implementation(reason: str) -> str: def request_implementation(reason: str) -> str:
@ -169,7 +169,7 @@ def skip_implementation(reason: str) -> str:
return reason return reason
@tool("emit_key_snippets") @tool("emit_key_snippets")
def emit_key_snippets(snippets: List[SnippetInfo]) -> List[str]: def emit_key_snippets(snippets: List[SnippetInfo]) -> str:
"""Store multiple key source code snippets in global memory. """Store multiple key source code snippets in global memory.
Args: Args:
@ -212,10 +212,10 @@ def emit_key_snippets(snippets: List[SnippetInfo]) -> List[str]:
results.append(f"Stored snippet #{snippet_id}") results.append(f"Stored snippet #{snippet_id}")
return results return "Snippets stored."
@tool("delete_key_snippets") @tool("delete_key_snippets")
def delete_key_snippets(snippet_ids: List[int]) -> List[str]: def delete_key_snippets(snippet_ids: List[int]) -> str:
"""Delete multiple key snippets from global memory by their IDs. """Delete multiple key snippets from global memory by their IDs.
Silently skips any IDs that don't exist. Silently skips any IDs that don't exist.
@ -236,7 +236,7 @@ def delete_key_snippets(snippet_ids: List[int]) -> List[str]:
border_style="green")) border_style="green"))
results.append(success_msg) results.append(success_msg)
return results return "Snippets deleted."
def get_memory_value(key: str) -> str: def get_memory_value(key: str) -> str:
"""Get a value from global memory. """Get a value from global memory.

View File

@ -35,7 +35,7 @@ def test_emit_key_facts_single_fact(reset_memory):
"""Test emitting a single key fact using emit_key_facts""" """Test emitting a single key fact using emit_key_facts"""
# Test with single fact # Test with single fact
result = emit_key_facts.invoke({"facts": ["First fact"]}) result = emit_key_facts.invoke({"facts": ["First fact"]})
assert result[0] == "Stored fact #0: First fact" assert result == "Facts stored."
assert _global_memory['key_facts'][0] == "First fact" assert _global_memory['key_facts'][0] == "First fact"
assert _global_memory['key_fact_id_counter'] == 1 assert _global_memory['key_fact_id_counter'] == 1
@ -46,20 +46,20 @@ def test_delete_key_facts_single_fact(reset_memory):
# Delete the fact # Delete the fact
result = delete_key_facts.invoke({"fact_ids": [0]}) result = delete_key_facts.invoke({"fact_ids": [0]})
assert result[0] == "Successfully deleted fact #0: Test fact" assert result == "Facts deleted."
assert 0 not in _global_memory['key_facts'] assert 0 not in _global_memory['key_facts']
def test_delete_key_facts_invalid(reset_memory): def test_delete_key_facts_invalid(reset_memory):
"""Test deleting non-existent facts returns empty list""" """Test deleting non-existent facts returns empty list"""
# Try to delete non-existent fact # Try to delete non-existent fact
result = delete_key_facts.invoke({"fact_ids": [999]}) result = delete_key_facts.invoke({"fact_ids": [999]})
assert result == [] assert result == "Facts deleted."
# Add and delete a fact, then try to delete it again # Add and delete a fact, then try to delete it again
emit_key_facts.invoke({"facts": ["Test fact"]}) emit_key_facts.invoke({"facts": ["Test fact"]})
delete_key_facts.invoke({"fact_ids": [0]}) delete_key_facts.invoke({"fact_ids": [0]})
result = delete_key_facts.invoke({"fact_ids": [0]}) result = delete_key_facts.invoke({"fact_ids": [0]})
assert result == [] assert result == "Facts deleted."
def test_get_memory_value_key_facts(reset_memory): def test_get_memory_value_key_facts(reset_memory):
"""Test get_memory_value with key facts dictionary""" """Test get_memory_value with key facts dictionary"""
@ -91,14 +91,10 @@ def test_emit_key_facts(reset_memory):
"""Test emitting multiple key facts at once""" """Test emitting multiple key facts at once"""
# Test emitting multiple facts # Test emitting multiple facts
facts = ["First fact", "Second fact", "Third fact"] facts = ["First fact", "Second fact", "Third fact"]
results = emit_key_facts.invoke({"facts": facts}) result = emit_key_facts.invoke({"facts": facts})
# Verify return messages # Verify return message
assert results == [ assert result == "Facts stored."
"Stored fact #0: First fact",
"Stored fact #1: Second fact",
"Stored fact #2: Third fact"
]
# Verify facts stored in memory with correct IDs # Verify facts stored in memory with correct IDs
assert _global_memory['key_facts'][0] == "First fact" assert _global_memory['key_facts'][0] == "First fact"
@ -114,13 +110,10 @@ def test_delete_key_facts(reset_memory):
emit_key_facts.invoke({"facts": ["First fact", "Second fact", "Third fact"]}) emit_key_facts.invoke({"facts": ["First fact", "Second fact", "Third fact"]})
# Test deleting mix of existing and non-existing IDs # Test deleting mix of existing and non-existing IDs
results = delete_key_facts.invoke({"fact_ids": [0, 1, 999]}) result = delete_key_facts.invoke({"fact_ids": [0, 1, 999]})
# Verify only success messages for existing facts # Verify success message
assert results == [ assert result == "Facts deleted."
"Successfully deleted fact #0: First fact",
"Successfully deleted fact #1: Second fact"
]
# Verify correct facts removed from memory # Verify correct facts removed from memory
assert 0 not in _global_memory['key_facts'] assert 0 not in _global_memory['key_facts']
@ -147,10 +140,10 @@ def test_emit_key_snippets(reset_memory):
] ]
# Emit snippets # Emit snippets
results = emit_key_snippets.invoke({"snippets": snippets}) result = emit_key_snippets.invoke({"snippets": snippets})
# Verify return messages # Verify return message
assert results == ["Stored snippet #0", "Stored snippet #1"] assert result == "Snippets stored."
# Verify snippets stored correctly # Verify snippets stored correctly
assert _global_memory['key_snippets'][0] == snippets[0] assert _global_memory['key_snippets'][0] == snippets[0]
@ -185,13 +178,10 @@ def test_delete_key_snippets(reset_memory):
emit_key_snippets.invoke({"snippets": snippets}) emit_key_snippets.invoke({"snippets": snippets})
# Test deleting mix of valid and invalid IDs # Test deleting mix of valid and invalid IDs
results = delete_key_snippets.invoke({"snippet_ids": [0, 1, 999]}) result = delete_key_snippets.invoke({"snippet_ids": [0, 1, 999]})
# Verify success messages # Verify success message
assert results == [ assert result == "Snippets deleted."
"Successfully deleted snippet #0 from test1.py",
"Successfully deleted snippet #1 from test2.py"
]
# Verify correct snippets removed # Verify correct snippets removed
assert 0 not in _global_memory['key_snippets'] assert 0 not in _global_memory['key_snippets']
@ -211,8 +201,8 @@ def test_delete_key_snippets_empty(reset_memory):
emit_key_snippets.invoke({"snippets": [snippet]}) emit_key_snippets.invoke({"snippets": [snippet]})
# Test with empty list # Test with empty list
results = delete_key_snippets.invoke({"snippet_ids": []}) result = delete_key_snippets.invoke({"snippet_ids": []})
assert results == [] assert result == "Snippets deleted."
# Verify snippet still exists # Verify snippet still exists
assert 0 in _global_memory['key_snippets'] assert 0 in _global_memory['key_snippets']
@ -242,8 +232,8 @@ def test_key_snippets_integration(reset_memory):
] ]
# Add all snippets # Add all snippets
results = emit_key_snippets.invoke({"snippets": snippets}) result = emit_key_snippets.invoke({"snippets": snippets})
assert results == ["Stored snippet #0", "Stored snippet #1", "Stored snippet #2"] assert result == "Snippets stored."
assert _global_memory['key_snippet_id_counter'] == 3 assert _global_memory['key_snippet_id_counter'] == 3
# Verify all snippets were stored correctly # Verify all snippets were stored correctly
@ -253,10 +243,8 @@ def test_key_snippets_integration(reset_memory):
assert _global_memory['key_snippets'][2] == snippets[2] assert _global_memory['key_snippets'][2] == snippets[2]
# Delete some but not all snippets (0 and 2) # Delete some but not all snippets (0 and 2)
results = delete_key_snippets.invoke({"snippet_ids": [0, 2]}) result = delete_key_snippets.invoke({"snippet_ids": [0, 2]})
assert len(results) == 2 assert result == "Snippets deleted."
assert "Successfully deleted snippet #0 from file1.py" in results
assert "Successfully deleted snippet #2 from file3.py" in results
# Verify remaining snippet is intact # Verify remaining snippet is intact
assert len(_global_memory['key_snippets']) == 1 assert len(_global_memory['key_snippets']) == 1
@ -273,15 +261,13 @@ def test_key_snippets_integration(reset_memory):
"snippet": "def func4():\n return False", "snippet": "def func4():\n return False",
"description": "Fourth function" "description": "Fourth function"
} }
results = emit_key_snippets.invoke({"snippets": [new_snippet]}) result = emit_key_snippets.invoke({"snippets": [new_snippet]})
assert results == ["Stored snippet #3"] assert result == "Snippets stored."
assert _global_memory['key_snippet_id_counter'] == 4 assert _global_memory['key_snippet_id_counter'] == 4
# Delete remaining snippets # Delete remaining snippets
results = delete_key_snippets.invoke({"snippet_ids": [1, 3]}) result = delete_key_snippets.invoke({"snippet_ids": [1, 3]})
assert len(results) == 2 assert result == "Snippets deleted."
assert "Successfully deleted snippet #1 from file2.py" in results
assert "Successfully deleted snippet #3 from file4.py" in results
# Verify all snippets are gone # Verify all snippets are gone
assert len(_global_memory['key_snippets']) == 0 assert len(_global_memory['key_snippets']) == 0
@ -296,7 +282,7 @@ def test_emit_research_subtask(reset_memory):
result = emit_research_subtask(subtask) result = emit_research_subtask(subtask)
# Verify return message # Verify return message
assert result == f"Added research subtask: {subtask}" assert result == "Subtask added."
# Verify it was stored in memory # Verify it was stored in memory
assert len(_global_memory['research_subtasks']) == 1 assert len(_global_memory['research_subtasks']) == 1