feat(bias): implement ToolBiasEngine and integrate into ai_client orchestration loop
This commit is contained in:
50
tests/test_tool_bias.py
Normal file
50
tests/test_tool_bias.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import pytest
|
||||
from src.tool_bias import ToolBiasEngine
|
||||
from src.models import ToolPreset, Tool, BiasProfile
|
||||
|
||||
def test_apply_semantic_nudges():
|
||||
engine = ToolBiasEngine()
|
||||
preset = ToolPreset(name="test", categories={
|
||||
"General": [
|
||||
Tool(name="read_file", weight=5),
|
||||
Tool(name="list_directory", weight=1)
|
||||
]
|
||||
})
|
||||
|
||||
# Mock tool definitions (simplified MCP_TOOL_SPECS)
|
||||
tool_defs = [
|
||||
{"name": "read_file", "description": "Read file content.", "parameters": {"properties": {"path": {"description": "Path to file"}}}},
|
||||
{"name": "list_directory", "description": "List dir.", "parameters": {"properties": {"path": {"description": "Path to dir"}}}}
|
||||
]
|
||||
|
||||
nudged = engine.apply_semantic_nudges(tool_defs, preset)
|
||||
|
||||
assert "[HIGH PRIORITY]" in nudged[0]["description"]
|
||||
assert "[LOW PRIORITY]" in nudged[1]["description"]
|
||||
|
||||
def test_parameter_bias_nudging():
|
||||
engine = ToolBiasEngine()
|
||||
preset = ToolPreset(name="test", categories={
|
||||
"General": [
|
||||
Tool(name="read_file", parameter_bias={"path": "PREFERRED"})
|
||||
]
|
||||
})
|
||||
|
||||
tool_defs = [
|
||||
{"name": "read_file", "description": "Read file.", "parameters": {"properties": {"path": {"description": "Path."}}, "required": ["path"]}}
|
||||
]
|
||||
|
||||
nudged = engine.apply_semantic_nudges(tool_defs, preset)
|
||||
assert "[PREFERRED]" in nudged[0]["parameters"]["properties"]["path"]["description"]
|
||||
|
||||
def test_generate_tooling_strategy():
|
||||
engine = ToolBiasEngine()
|
||||
preset = ToolPreset(name="test", categories={
|
||||
"General": [Tool(name="read_file", weight=5)]
|
||||
})
|
||||
bias = BiasProfile(name="test", category_multipliers={"General": 2.0})
|
||||
|
||||
strategy = engine.generate_tooling_strategy(preset, bias)
|
||||
assert "Tooling Strategy" in strategy
|
||||
assert "read_file" in strategy
|
||||
assert "General" in strategy
|
||||
Reference in New Issue
Block a user