Honor tool plans despite weak classification

This commit is contained in:
2026-05-11 00:14:49 +08:00
parent 7215033028
commit 28a2f63713
2 changed files with 55 additions and 18 deletions
+30
View File
@@ -1,6 +1,17 @@
import asyncio
from app.core.async_router import AsyncRouter
from app.core.contracts import CriticScore, ExecutionDirective, PlanStep, UserTask
class _FakeAdapter:
def __init__(self, responses: list[str]) -> None:
self._responses = responses
async def generate(self, prompt: str, max_tokens: int | None = None) -> str:
return self._responses.pop(0)
def test_user_task_defaults() -> None:
task = UserTask(input="hello")
assert task.task_id
@@ -35,3 +46,22 @@ def test_execution_directive_defaults() -> None:
assert directive.payload == {}
assert directive.confidence == 0.0
def test_router_compiles_tool_plan_even_when_classifier_says_conversation() -> None:
router = AsyncRouter(
thinker=_FakeAdapter([
"conversation",
"ПЛАН:\nШаг 1: [shell_exec] выполнить `uptime`",
]),
json_compiler=_FakeAdapter([
'{"type":"plan","payload":{"steps":[{"id":"1","tool":"shell_exec","args":{"command":"uptime"},"depends_on":[]}]}}'
]),
)
directive = asyncio.run(
router.decide(
state={},
context={"task_summary": "Проверь аптайм ПК", "task_context": {}},
)
)
assert directive.type == "plan"
assert directive.payload["steps"][0]["tool"] == "shell_exec"