Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(evaluator): reject non-boolean notification decisions
Shuhan Sie2cd6908c79f
diff --git a/nanobot/utils/evaluator.py b/nanobot/utils/evaluator.pyindex 4dbafb988..e6f626dfb 100644--- a/nanobot/utils/evaluator.py+++ b/nanobot/utils/evaluator.py@@ -129,9 +129,15 @@ async def evaluate_response(args = llm_response.tool_calls[0].argumentsshould_notify = args.get("should_notify", default_notify)+ if not isinstance(should_notify, bool):+ logger.warning(+ "evaluate_response: non-boolean should_notify, defaulting to notify={}",+ default_notify,+ )+ return default_notifyreason = args.get("reason", "")logger.info("evaluate_response: should_notify={}, reason={}", should_notify, reason)- return bool(should_notify)+ return should_notifyexcept Exception:logger.exception("evaluate_response failed, defaulting to notify={}", default_notify)diff --git a/tests/agent/test_evaluator.py b/tests/agent/test_evaluator.pyindex 22c568e73..3d1ad6a00 100644--- a/tests/agent/test_evaluator.py+++ b/tests/agent/test_evaluator.py@@ -95,6 +95,25 @@ async def test_should_notify_false() -> None:assert result is False[email protected]("decision", ["false", "true", 0, 1, None, [], {"notify": True}])[email protected]("default_notify", [False, True])+async def test_invalid_notification_decision_uses_default(decision, default_notify) -> None:+ response = LLMResponse(+ content="",+ tool_calls=[ToolCallRequest(+ id="eval_1", name="evaluate_notification",+ arguments={"should_notify": decision},+ )],+ )+ result = await evaluate_response(+ "All clear", "check status", DummyProvider([response]), "m",+ evaluator_prompt=_EVAL_PROMPT, default_notify=default_notify,+ )++ assert result is default_notify++@pytest.mark.asyncioasync def test_fallback_on_error() -> None:class FailingProvider(DummyProvider):