mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 06:02:43 +08:00
Immersive Reading, self-configuration, and a two-way IMA library. - Immersive Reading: a new capability that opens a document beside the thread. New reading engine (PDF pages / slides / page-sized sections), five reading tools, a deterministic locate pre-pass that grounds the turn without a second LLM call, /api/v1/reading, and a reader pane with selection, highlights, notes, and export to an annotated PDF or Markdown. - Setup capability: inspect the install, apply a setting, install a parsing engine, or request a credential from a chat turn. New settings spec table; a candidate value is probed before it is committed, and API keys never enter the model's context. - Tencent IMA: pipeline split into transport/envelope/models/sources/ notes/media/inventory, an additive capability with five tools, and connected libraries that can finally be enumerated (bounded listings are reported as a lower bound). - Retrieval: supports_rag_retrieval() replaces is_connected_kb() for the "can I sweep this?" question, so linked / lightrag_server / ima sources stop being silently dropped from every book. - Notebooks: their own console at /notebook, per-notebook locks and atomic writes, copy / move / export routes, damaged files surfaced instead of dropped, and renaming a record no longer clears its knowledge-base link. - Settings persistence: one lock and one atomic replace shared by every writer of interface.json; the PUT endpoints stop writing the defaults-merged view back to disk. Release notes: assets/releases/ver1-5-14.md
59 lines
2.6 KiB
Python
59 lines
2.6 KiB
Python
"""Immersive Reading capability — the chat agent loop, reading a document.
|
|
|
|
There is no bespoke pipeline: the standard agentic chat loop IS the reader. This
|
|
capability only marks the turn and runs that pipeline. Everything specific to
|
|
reading is contributed by the loop capability
|
|
(:class:`deeptutor.capabilities.reading.capability.ReadingCapability`), which
|
|
mounts the five reading tools, binds the open material server-side, injects the
|
|
reading playbook and runs the deterministic locate pre-pass.
|
|
|
|
The split matters for a practical reason: the *mode* is what the user picks in
|
|
the composer, while the *loop capability* activates on whether a document is
|
|
actually open. Selecting the mode with no document open therefore still gives a
|
|
perfectly ordinary chat turn — the reader panel is showing its file picker, and
|
|
there is nothing to ground an answer in yet.
|
|
|
|
Design axiom (shared with chat / solve / mastery): the intelligence lives at the
|
|
loop's exit — the model decides what to read and what to cite — while the
|
|
deterministic parts (which units exist, whether a quote is really on the page it
|
|
claims) are engine calls behind tools.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from deeptutor.agents.chat.agentic_pipeline import AgenticChatPipeline
|
|
from deeptutor.capabilities.reading.capability import (
|
|
MATERIAL_ID_KEY,
|
|
MODE_KEY,
|
|
resolve_material_id,
|
|
)
|
|
from deeptutor.capabilities.reading.tools import READING_TOOL_NAMES
|
|
from deeptutor.core.capability_protocol import BaseCapability, CapabilityManifest
|
|
from deeptutor.core.context import UnifiedContext
|
|
from deeptutor.core.stream_bus import StreamBus
|
|
|
|
|
|
class ImmersiveReadingCapability(BaseCapability):
|
|
manifest = CapabilityManifest(
|
|
name="immersive_reading",
|
|
description=(
|
|
"Read a document alongside the assistant, which cites the exact "
|
|
"page or section behind every claim."
|
|
),
|
|
stages=["responding"],
|
|
tools_used=[*READING_TOOL_NAMES, "web_search", "code_execution", "reason"],
|
|
cli_aliases=["reading", "read"],
|
|
)
|
|
|
|
async def run(self, context: UnifiedContext, stream: StreamBus) -> None:
|
|
# Normalised so the flag and the id can never disagree: the loop
|
|
# capability keys off the id alone, and a turn with no document open is
|
|
# deliberately just a normal chat turn.
|
|
material_id = resolve_material_id(context)
|
|
context.metadata[MATERIAL_ID_KEY] = material_id
|
|
context.metadata[MODE_KEY] = True
|
|
await AgenticChatPipeline(language=context.language).run(context, stream)
|
|
|
|
|
|
__all__ = ["ImmersiveReadingCapability"]
|