DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(cli): respect configured token budget in doctor probe
OrdoAbChao757dc901c8ae2
diff --git a/deeptutor/services/doctor.py b/deeptutor/services/doctor.pyindex 335b50033..133d84e8b 100644--- a/deeptutor/services/doctor.py+++ b/deeptutor/services/doctor.py@@ -336,8 +336,21 @@ def _redact_error(exc: Exception, config: Any) -> str:async def _probe_provider(config: Any) -> None:+ from deeptutor.services.config.loader import get_agent_paramsfrom deeptutor.services.llm import complete+ # Share the Settings probe's configurable budget. A 64-token cap can be+ # exhausted by hidden reasoning before a healthy model emits even "OK".+ # Doctor must also work before agents.yaml has been created.+ try:+ probe_params = get_agent_params("llm_probe")+ except FileNotFoundError:+ probe_params = {}+ try:+ max_tokens = max(1, int(probe_params.get("max_tokens", 4096)))+ except (TypeError, ValueError):+ max_tokens = 4096+response = await complete(model=str(config.model),prompt="Reply with OK.",@@ -351,7 +364,7 @@ async def _probe_provider(config: Any) -> None:reasoning_effort=config.reasoning_effort,max_retries=0,allow_image_fallback=False,- max_tokens=64,+ max_tokens=max_tokens,)if not (response or "").strip():raise RuntimeError("The model returned an empty response.")diff --git a/tests/cli/test_doctor_cli.py b/tests/cli/test_doctor_cli.pyindex 030d366f3..dabea65b9 100644--- a/tests/cli/test_doctor_cli.py+++ b/tests/cli/test_doctor_cli.py@@ -203,7 +203,13 @@ async def test_online_probe_success_is_reported(tmp_path) -> None:@pytest.mark.asyncio-async def test_online_probe_passes_one_bounded_token_parameter(monkeypatch, tmp_path) -> None:+ ("configured_budget", "expected"),+ [(None, 4096), (512, 512), (8192, 8192), ("2048", 2048), ("invalid", 4096), (0, 1)],+)+async def test_online_probe_uses_configured_budget(+ monkeypatch, tmp_path, configured_budget, expected+) -> None:import deeptutor.services.llm as llmcaptured = {}@@ -213,6 +219,13 @@ async def test_online_probe_passes_one_bounded_token_parameter(monkeypatch, tmp_return "OK"monkeypatch.setattr(llm, "complete", fake_complete)+ (tmp_path / "agents.yaml").write_text(+ json.dumps({"diagnostics": {"llm_probe": {"max_tokens": configured_budget}}}),+ encoding="utf-8",+ )+ monkeypatch.setattr(+ "deeptutor.services.config.loader.get_runtime_settings_dir", lambda _root: tmp_path+ )report = await run_diagnostics(online=True,@@ -227,10 +240,36 @@ async def test_online_probe_passes_one_bounded_token_parameter(monkeypatch, tmp_)assert report.ok is True- assert captured["max_tokens"] == 64+ assert captured["max_tokens"] == expectedassert "max_completion_tokens" not in captured[email protected](("response", "expected_status"), [("OK", "pass"), (" ", "fail")])+async def test_online_probe_allows_reasoning_before_visible_output(+ monkeypatch, tmp_path, response, expected_status+) -> None:+ """A healthy reasoning endpoint must not fail because the probe truncates it."""++ async def fake_complete(**kwargs):+ return response if kwargs["max_tokens"] >= 4096 else ""++ def missing_settings(module):+ raise FileNotFoundError("agents.yaml")++ monkeypatch.setattr("deeptutor.services.llm.complete", fake_complete)+ monkeypatch.setattr("deeptutor.services.config.loader.get_agent_params", missing_settings)+ report = await run_diagnostics(+ online=True,+ resolve_llm=lambda: _llm_config(model="gpt-5-mini"),+ data_root=tmp_path,+ load_rag_config=lambda: {"defaults": {}, "knowledge_bases": {}},+ )++ assert next(check for check in report.checks if check.key == "online").status == expected_status+ assert report.ok is (expected_status == "pass")++@pytest.mark.asyncioasync def test_online_probe_preserves_empty_custom_endpoint_api_key(monkeypatch, tmp_path) -> None:import deeptutor.services.llm as llm