diff --git a/src/tool_bias.py b/src/tool_bias.py index bb33e86..d0d8c57 100644 --- a/src/tool_bias.py +++ b/src/tool_bias.py @@ -39,13 +39,23 @@ class ToolBiasEngine: lines = ["### Tooling Strategy"] preferred = [] + low_priority = [] for cat_tools in preset.categories.values(): for t in cat_tools: - if isinstance(t, Tool) and t.weight >= 4: - preferred.append(t.name) + if not isinstance(t, Tool): continue + if t.weight >= 5: + preferred.append(f"{t.name} [HIGH PRIORITY]") + elif t.weight == 4: + preferred.append(f"{t.name} [PREFERRED]") + elif t.weight == 2: + low_priority.append(f"{t.name} [NOT RECOMMENDED]") + elif t.weight <= 1: + low_priority.append(f"{t.name} [LOW PRIORITY]") if preferred: lines.append(f"Preferred tools: {', '.join(preferred)}.") + if low_priority: + lines.append(f"Low-priority tools: {', '.join(low_priority)}.") if global_bias.category_multipliers: lines.append("Category focus multipliers:") diff --git a/tests/test_bias_efficacy.py b/tests/test_bias_efficacy.py new file mode 100644 index 0000000..9710b86 --- /dev/null +++ b/tests/test_bias_efficacy.py @@ -0,0 +1,51 @@ +import pytest +from src import ai_client +from src.models import ToolPreset, Tool, BiasProfile +from unittest.mock import MagicMock, patch + +def test_bias_efficacy_prompt_generation(): + # Verify that the generated prompt contains the expected nudges and strategy + preset = ToolPreset(name="BiasTest", categories={ + "General": [ + Tool(name="list_directory", weight=5), + Tool(name="search_files", weight=1) + ] + }) + bias = BiasProfile(name="Balanced", category_multipliers={"General": 1.0}) + + with patch("src.ai_client._active_tool_preset", preset): + with patch("src.ai_client._active_bias_profile", bias): + prompt = ai_client._get_combined_system_prompt() + + # Check strategy section + assert "Tooling Strategy" in prompt + assert "list_directory" in prompt + assert "PREFERRED" in prompt or "HIGH PRIORITY" in prompt + + # Check tool definitions nudging + with patch("src.ai_client._agent_tools", {"list_directory": True, "search_files": True}): + # Anthropic tools as an example + with patch("src.ai_client._CACHED_ANTHROPIC_TOOLS", None): + tools = ai_client._get_anthropic_tools() + + ls_tool = next(t for t in tools if t["name"] == "list_directory") + search_tool = next(t for t in tools if t["name"] == "search_files") + + assert "[HIGH PRIORITY]" in ls_tool["description"] + assert "[LOW PRIORITY]" in ls_tool["description"] or "[LOW PRIORITY]" in search_tool["description"] + +def test_bias_parameter_nudging(): + preset = ToolPreset(name="ParamTest", categories={ + "General": [ + Tool(name="read_file", parameter_bias={"path": "CRITICAL"}) + ] + }) + + with patch("src.ai_client._active_tool_preset", preset): + with patch("src.ai_client._agent_tools", {"read_file": True}): + with patch("src.ai_client._CACHED_ANTHROPIC_TOOLS", None): + tools = ai_client._get_anthropic_tools() + read_tool = next(t for t in tools if t["name"] == "read_file") + + path_param_desc = read_tool["input_schema"]["properties"]["path"]["description"] + assert "[CRITICAL]" in path_param_desc