DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
refactor(pageindex): trim review findings — drop redundant dir resolution in search, dedupe deferred_tools() call, inline blocklist, fix stale docstrings
BukeLy3288ce793127
diff --git a/deeptutor/agents/chat/agentic_pipeline.py b/deeptutor/agents/chat/agentic_pipeline.pyindex b71a5c602..953069708 100644--- a/deeptutor/agents/chat/agentic_pipeline.py+++ b/deeptutor/agents/chat/agentic_pipeline.py@@ -468,19 +468,19 @@ class AgenticChatPipeline:# are also preloaded (no load_tools round-trip) so retrieval# works on the first turn.self._pageindex_docs = self._pageindex_doc_maps(context)+ pool = self.registry.deferred_tools()pageindex_tools: set[str] = set()if self._pageindex_docs:from deeptutor.services.mcp.pageindex_server import PAGEINDEX_SERVER_NAMEpageindex_tools = {t.get_definition().name- for t in self.registry.deferred_tools()+ for t in poolif getattr(t, "server_name", "") == PAGEINDEX_SERVER_NAME}if allowed is not None:allowed = allowed | pageindex_tools- pool = self.registry.deferred_tools()if allowed is not None:pool = [t for t in pool if t.get_definition().name in allowed]self._deferred_pool = pool@@ -1280,19 +1280,19 @@ class AgenticChatPipeline:return ""if not self._selected_kbs(context):return ""- parts: list[str] = []+ rag_note = ""rag_kbs = self._rag_kbs(context)if rag_kbs:joined = ", ".join(rag_kbs)- if self.language == "zh":- parts.append(f"用户已挂载知识库:{joined}。调用 rag 时,kb_name 必须从其中选一个。")- else:- parts.append(+ rag_note = (+ f"用户已挂载知识库:{joined}。调用 rag 时,kb_name 必须从其中选一个。"+ if self.language == "zh"+ else (f"Attached knowledge bases: {joined}. When calling rag, kb_name ""must be one of these names.")- parts.append(self._pageindex_system_note())- return "".join(parts)+ )+ return rag_note + self._pageindex_system_note()def _pageindex_system_note(self) -> str:"""Doc list + retrieval instructions for attached PageIndex KBs.diff --git a/deeptutor/services/mcp/pageindex_server.py b/deeptutor/services/mcp/pageindex_server.pyindex e01de66ad..409494ff1 100644--- a/deeptutor/services/mcp/pageindex_server.py+++ b/deeptutor/services/mcp/pageindex_server.py@@ -16,11 +16,6 @@ from deeptutor.services.mcp.config import MCPConfig, MCPServerConfigPAGEINDEX_SERVER_NAME = "pageindex"-# remove_document is the one api-proxy tool DeepTutor blocks: an agent-# deleting a cloud doc would silently orphan the doc_ids in the local KB-# manifest. Everything else the server advertises passes through.-_BLOCKED_TOOLS = ["remove_document"]-def builtin_pageindex_server() -> MCPServerConfig | None:"""The injected server entry, or ``None`` when no API key is configured."""@@ -35,7 +30,10 @@ def builtin_pageindex_server() -> MCPServerConfig | None:url=cfg.api_base_url.rstrip("/") + "/mcp",headers={"Authorization": f"Bearer {cfg.api_key}"},tool_timeout=120,- disabled_tools=list(_BLOCKED_TOOLS),+ # remove_document is the one api-proxy tool DeepTutor blocks: an agent+ # deleting a cloud doc would silently orphan the doc_ids in the local+ # KB manifest. Everything else the server advertises passes through.+ disabled_tools=["remove_document"],)diff --git a/deeptutor/services/rag/pipelines/pageindex/pipeline.py b/deeptutor/services/rag/pipelines/pageindex/pipeline.pyindex 8b060a522..64026f2bb 100644--- a/deeptutor/services/rag/pipelines/pageindex/pipeline.py+++ b/deeptutor/services/rag/pipelines/pageindex/pipeline.py@@ -167,11 +167,9 @@ class PageIndexPipeline:programmatic callers this returns the documents' real structure ascontext — shallow but honest grounding."""- kb_dir = resolve_kb_dir(self.kb_base_dir, kb_name)- storage_dir = resolve_storage_dir_for_read(kb_dir, None)docs = self.document_map(kb_name)- if storage_dir is None or not docs:+ if not docs:return {"query": query,"answer": (@@ -279,8 +277,7 @@ class PageIndexPipeline:def document_map(self, kb_name: str) -> dict[str, str]:"""file name -> cloud doc_id for the KB's current manifest.- Used by the chat layer to inject the doc list into the system prompt,- and embedded in the ``mcp_only`` search result.+ Used by the chat layer to inject the doc list into the system prompt."""kb_dir = resolve_kb_dir(self.kb_base_dir, kb_name)manifest = storage.read_manifest(resolve_storage_dir_for_read(kb_dir, None))diff --git a/tests/services/rag/test_pageindex_pipeline.py b/tests/services/rag/test_pageindex_pipeline.pyindex ebe738af8..948b0f188 100644--- a/tests/services/rag/test_pageindex_pipeline.py+++ b/tests/services/rag/test_pageindex_pipeline.py@@ -1,8 +1,8 @@"""Unit tests for the PageIndex cloud RAG pipeline + provider routing.The pipeline talks to PageIndex's REST API through an injectable client, so we-exercise the orchestration (file filtering, manifest, mcp_only search contract,-delete) against a fake client without any network calls. Retrieval itself is+exercise the orchestration (file filtering, manifest, outline search contract,+delete) against a fake client without any network calls. Deep retrieval isagentic via the PageIndex MCP server and out of scope here."""