Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: make prompt loading and capability failures terminal (#738)

GMyhf0021c4d20760
diff --git a/deeptutor/agents/math_animator/agents/concept_analysis_agent.py b/deeptutor/agents/math_animator/agents/concept_analysis_agent.py
index a2f75778e..c1deb6c80 100644
--- a/deeptutor/agents/math_animator/agents/concept_analysis_agent.py
+++ b/deeptutor/agents/math_animator/agents/concept_analysis_agent.py
@@ -5,6 +5,7 @@ from __future__ import annotations
from deeptutor.agents.base_agent import BaseAgent
from deeptutor.core.context import Attachment
from deeptutor.core.trace import build_trace_metadata, new_call_id
+from deeptutor.services.prompt import get_prompt_manager
from ..models import ConceptAnalysis
from ..utils import extract_json_object
@@ -38,6 +39,18 @@ class ConceptAnalysisAgent(BaseAgent):
) -> ConceptAnalysis:
system_prompt = self.get_prompt("system")
user_template = self.get_prompt("user_template")
+ if not system_prompt or not user_template:
+ # Retry once: a worker that looked the prompts up before the
+ # package finished installing used to cache the empty result
+ # forever. PromptManager no longer caches misses, so a reload can
+ # now actually recover — and it stays the one place that knows how
+ # to find a prompt file.
+ self.prompts = get_prompt_manager().reload_prompts(
+ "math_animator", "concept_analysis_agent", self.language
+ )
+ system_prompt = self.get_prompt("system")
+ user_template = self.get_prompt("user_template")
+
if not system_prompt or not user_template:
raise ValueError("ConceptAnalysisAgent prompts are not configured.")
diff --git a/deeptutor/services/prompt/manager.py b/deeptutor/services/prompt/manager.py
index f4fdd736b..ede866171 100644
--- a/deeptutor/services/prompt/manager.py
+++ b/deeptutor/services/prompt/manager.py
@@ -77,7 +77,11 @@ class PromptManager:
return self._cache[cache_key]
prompts = self._load_with_fallback(module_name, agent_name, lang_code, subdirectory)
- self._cache[cache_key] = prompts
+ # A missing resource is usually a packaging or startup-layout problem.
+ # Do not cache the empty result permanently: a later retry must be able
+ # to see resources that become available after startup.
+ if prompts:
+ self._cache[cache_key] = prompts
return prompts
def _build_cache_key(
diff --git a/packaging/deeptutor-cli/pyproject.toml b/packaging/deeptutor-cli/pyproject.toml
index 2f8d9385a..eab776ff7 100644
--- a/packaging/deeptutor-cli/pyproject.toml
+++ b/packaging/deeptutor-cli/pyproject.toml
@@ -63,3 +63,17 @@ version = {attr = "deeptutor.__version__.__version__"}
where = ["../.."]
include = ["deeptutor*", "deeptutor_cli*"]
exclude = ["deeptutor_web*"]
+
+# This distribution includes the shared agent implementations. Keep their
+# runtime prompt/config assets in the wheel as the full distribution does.
+[tool.setuptools.package-data]
+deeptutor = [
+ "**/*.yaml",
+ "**/*.yml",
+ "**/*.md",
+ "**/*.json",
+ "**/*.sh",
+ "**/*.j2",
+ "**/*.jinja",
+]
+deeptutor_cli = ["**/*.md"]
diff --git a/tests/core/test_prompt_manager.py b/tests/core/test_prompt_manager.py
index fbadb3e55..3badc49c5 100644
--- a/tests/core/test_prompt_manager.py
+++ b/tests/core/test_prompt_manager.py
@@ -47,6 +47,14 @@ class TestPromptManager:
or prompts == {}
)
+ def test_load_prompts_math_animator_concept_analysis(self):
+ """Math animator prompts must be available to the shared loader."""
+ pm = get_prompt_manager()
+ prompts = pm.reload_prompts("math_animator", "concept_analysis_agent", "zh")
+
+ assert prompts["system"]
+ assert prompts["user_template"]
+
def test_load_prompts_solve_module(self):
"""Test loading prompts for solve module."""
pm = get_prompt_manager()
@@ -86,7 +94,7 @@ class TestPromptManager:
# Load some prompts
pm.load_prompts("research", "pipeline", "en")
- pm.load_prompts("solve", "solve_agent", "en")
+ pm.load_prompts("math_animator", "concept_analysis_agent", "en")
assert len(pm._cache) >= 2
@@ -99,13 +107,13 @@ class TestPromptManager:
# Load prompts for multiple modules
pm.load_prompts("research", "pipeline", "en")
- pm.load_prompts("solve", "solve_agent", "en")
+ pm.load_prompts("math_animator", "concept_analysis_agent", "en")
# Clear only research cache
pm.clear_cache("research")
# Solve prompts should still be cached
- assert any("solve" in k for k in pm._cache)
+ assert any("math_animator" in k for k in pm._cache)
assert not any("research" in k for k in pm._cache)
def test_get_prompt_helper(self):