Files
DeepTutor/deeptutor/agents/research/capability.py
Bingxi Zhao (Frank) 7ac3a3ba79 release: v1.4.6
A broad consolidation release across four product surfaces.

- Learning Space: Space becomes a learning dashboard; My Agents imports
  local Claude Code / Codex chat history into resumable agents (with an
  objective explore_context briefing so the tutor never role-plays the
  user); Memory is promoted to a top-level /memory route; Partner
  conversations flow into Memory; EduHub skills install inline.
- Knowledge Center: /knowledge rebuilt as a console with per-engine
  detail pages; GraphRAG / PageIndex / LightRAG engines join LlamaIndex;
  linked-KB read-only mounts; Obsidian live-vault capability.
- Settings: pluggable document parsing (MinerU / Docling / MarkItDown)
  with a content-addressed cache and MinerU cloud/local backends; voice
  TTS/STT; image & video generation; rebuilt settings navigation.
- Platform: per-user capability gating by assigned model; Solve rebuilt
  on the chat loop with a per-step gate and mid-run failure fallback;
  username login + inline errors; CLI skill publish/update; picker
  polish; math-before-citation render fix.

Docs were split out to a standalone site, so site/ is now landing-page
only. Bumps __version__ to 1.4.6 and adds assets/releases/ver1-4-6.md.

Folds in mypy fixes surfaced by pre-commit (mineru/local Path typing,
knowledge/manager no-redef, explore_context token kwargs, CLI
set_dist_tag capability probe) plus prettier reformatting of
previously-committed web files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:50:44 +08:00

100 lines
4.2 KiB
Python

"""Deep Research capability — agentic-engine-based deep research.
Thin shim that delegates to :class:`ResearchPipeline`. All orchestration
— rephrase (mini agentic loop with ``ask_user``), decompose, per-block
research loops with ``THINK`` / ``TOOL`` / ``APPEND`` / ``FINISH``,
queue scheduler, and iterative reporting — lives in the pipeline
module. The capability only handles:
* request-config validation,
* the outline-preview two-stage flow (first call returns sub-topics
the user edits / confirms; second call drives Phase 3+4 with the
confirmed outline).
Tool composition is delegated to the shared
:mod:`deeptutor.agents._shared.tool_composition` policy — same as chat,
so the user's composer toggles + the attached KB drive what the per-block
research loop actually has access to. There is no separate "sources"
knob.
"""
from __future__ import annotations
from typing import Any
from deeptutor.agents.research.pipeline import ResearchPipeline, SubTopicItem
from deeptutor.agents.research.request_config import (
build_research_runtime_config,
validate_research_request_config,
)
from deeptutor.core.capability_protocol import BaseCapability, CapabilityManifest
from deeptutor.core.context import UnifiedContext
from deeptutor.core.stream_bus import StreamBus
from deeptutor.runtime.request_contracts import get_capability_request_schema
from deeptutor.services.config import load_config_with_main
class DeepResearchCapability(BaseCapability):
manifest = CapabilityManifest(
name="deep_research",
description="Agentic-loop deep research with iterative report generation.",
stages=["rephrasing", "decomposing", "researching", "reporting"],
tools_used=["rag", "web_search", "paper_search", "code_execution"],
cli_aliases=["research"],
request_schema=get_capability_request_schema("deep_research"),
)
async def run(self, context: UnifiedContext, stream: StreamBus) -> None:
kb_name = context.knowledge_bases[0] if context.knowledge_bases else None
request_config = validate_research_request_config(context.config_overrides)
enabled_tools = list(context.enabled_tools or [])
runtime_config = build_research_runtime_config(
base_config=load_config_with_main("main.yaml"),
request_config=request_config,
kb_name=kb_name,
)
# Outline-preview two-stage flow: first call lacks a confirmed
# outline → pipeline returns ``outline_preview`` and exits; the
# frontend surfaces the outline editor and (after the user
# confirms) sends a second call with ``confirmed_outline`` set.
confirmed_outline_items: list[SubTopicItem] | None = None
if request_config.confirmed_outline is not None:
confirmed_outline_items = [
SubTopicItem(title=item.title, overview=item.overview or "")
for item in request_config.confirmed_outline
]
pipeline = ResearchPipeline(
language=context.language,
runtime_config=runtime_config,
kb_name=kb_name,
enabled_tools=enabled_tools,
)
result = await pipeline.run(
context=context,
topic=context.user_message,
confirmed_outline=confirmed_outline_items,
attachments=context.attachments,
stream=stream,
)
# Outline-preview payloads carry the sub-topics + the original
# request config so the second call has everything it needs to
# confirm and resume. Fields live at top level so
# ``event.metadata.outline_preview`` resolves on the FE.
if result.get("outline_preview"):
research_config: dict[str, Any] = {
"mode": request_config.mode,
"depth": request_config.depth,
}
if request_config.manual_subtopics is not None:
research_config["manual_subtopics"] = request_config.manual_subtopics
if request_config.manual_max_iterations is not None:
research_config["manual_max_iterations"] = request_config.manual_max_iterations
await stream.result(
{**result, "research_config": research_config},
source=self.name,
)