mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 10:20:23 +08:00
fix: list only usable skills, as a runtime snapshot
This commit is contained in:
@@ -104,8 +104,6 @@ loop:
|
||||
Build the answer on the conversation above — the gathered evidence,
|
||||
memory, persona, and attached sources.
|
||||
|
||||
If a skill listed in the Skills block matches the task, call read_skill
|
||||
before attempting that workflow, then follow the skill instructions.
|
||||
Use each tool according to its schema and tool-specific guidance. If an
|
||||
extended tool is listed but not loaded, call load_tools first with the
|
||||
exact tool name.
|
||||
|
||||
@@ -76,7 +76,6 @@ loop:
|
||||
也不要逐字复述你的工作笔记,并按工具结果原样引用生成文件。
|
||||
基于上面的对话——已收集的证据、记忆、persona 和附件来源——作答。
|
||||
|
||||
如果 Skills 区域里有匹配任务的 skill,先调用 read_skill 再执行该工作流,并遵循 skill 的指示。
|
||||
按各工具的 schema 和工具专属说明使用工具。如果 Extended Tools 里列出的工具尚未加载,
|
||||
先用精确工具名调用 load_tools。
|
||||
|
||||
|
||||
@@ -838,7 +838,7 @@ class AgenticLoopPipeline:
|
||||
# wrong question the learner owns up to (#1244). Product chat
|
||||
# keeps the entries-exist gate.
|
||||
has_question_bank=user_has_question_bank() or partner_can_record_questions(),
|
||||
has_skills=bool(context.skills_manifest),
|
||||
has_skills=bool(context.skills_manifest or context.active_skills_context),
|
||||
has_deferred_tools=getattr(self, "_deferred_loader", None) is not None,
|
||||
has_exec=getattr(self, "_exec_enabled", False),
|
||||
# Reaching a mastery topic is a chat-wide affordance, not part
|
||||
|
||||
@@ -36,6 +36,7 @@ RUNTIME_BLOCK_NAMES = frozenset(
|
||||
"tools",
|
||||
"knowledge_base_note",
|
||||
"extended_tools",
|
||||
"skills",
|
||||
"sidebar_tutor_context",
|
||||
}
|
||||
)
|
||||
@@ -194,6 +195,11 @@ class LoopPromptAssembler:
|
||||
blocks.append(PromptBlock("tools", tools))
|
||||
elif kb_note:
|
||||
blocks.append(PromptBlock("knowledge_base_note", kb_note))
|
||||
# Always-on skill playbooks are instructions and change only when the
|
||||
# user installs one, so they stay in the system prompt; the on-demand
|
||||
# list changes with every install/enable and is a runtime snapshot.
|
||||
if context.active_skills_context:
|
||||
blocks.append(PromptBlock("active_skills", context.active_skills_context))
|
||||
if context.skills_manifest:
|
||||
blocks.append(PromptBlock("skills", context.skills_manifest))
|
||||
if context.source_manifest:
|
||||
|
||||
@@ -125,10 +125,12 @@ class UnifiedContext:
|
||||
first token; empty when no persona is active).
|
||||
sidebar_context: High-priority grounding for an isolated sidebar tutor
|
||||
(for example, the exact passage selected in another chat).
|
||||
skills_manifest: System-prompt Skills block — one line per
|
||||
capability skill visible to this user, plus any ``always``
|
||||
skills' full bodies. The model pulls full skill content on
|
||||
demand via the ``read_skill`` tool.
|
||||
skills_manifest: Skills list — one line per available skill visible
|
||||
to this user (unavailable ones are only counted). Replayed as a
|
||||
runtime snapshot; the model pulls full skill content on demand
|
||||
via the ``read_skill`` tool.
|
||||
active_skills_context: Full bodies of available ``always`` skills,
|
||||
kept in the system prompt (empty when none).
|
||||
source_manifest: Plain-text manifest of attached sources (one line per
|
||||
source: id/name/type/preview). Empty when no sources are attached.
|
||||
Consumed by the chat capability to render an "Attached Sources"
|
||||
@@ -156,6 +158,7 @@ class UnifiedContext:
|
||||
persona_context: str = ""
|
||||
sidebar_context: str = ""
|
||||
skills_manifest: str = ""
|
||||
active_skills_context: str = ""
|
||||
source_manifest: str = ""
|
||||
runtime: TurnRuntimeContext = field(default_factory=TurnRuntimeContext)
|
||||
interaction: InteractionState = field(default_factory=InteractionState)
|
||||
|
||||
@@ -718,7 +718,7 @@ class PartnerRunner:
|
||||
# Assemble resource context in the same scope the turn's tools use.
|
||||
# The Soul remains in the Partner's private store in either mode.
|
||||
with partner_content_context(self.partner_id, self.config):
|
||||
skills_manifest = self._build_skills_manifest()
|
||||
active_skills, skills_manifest = self._build_skill_context()
|
||||
kb_names = self._list_kb_names()
|
||||
workspace_runtime = None
|
||||
if getattr(self.config, "workspace_id", ""):
|
||||
@@ -843,6 +843,7 @@ class PartnerRunner:
|
||||
language=self._language(),
|
||||
persona_context=persona_context,
|
||||
skills_manifest=skills_manifest,
|
||||
active_skills_context=active_skills,
|
||||
source_manifest=source_manifest,
|
||||
metadata=metadata,
|
||||
)
|
||||
@@ -884,11 +885,12 @@ class PartnerRunner:
|
||||
return None
|
||||
return [str(name) for name in configured]
|
||||
|
||||
def _build_skills_manifest(self) -> str:
|
||||
def _build_skill_context(self) -> tuple[str, str]:
|
||||
"""``(active_skills, skills_manifest)``, split like chat's executor."""
|
||||
if getattr(self.config, "workspace_id", ""):
|
||||
from deeptutor.services.skill.runtime import skill_manifest
|
||||
from deeptutor.services.skill.runtime import skill_context
|
||||
|
||||
return skill_manifest()
|
||||
return skill_context()
|
||||
try:
|
||||
from deeptutor.services.skill.service import (
|
||||
get_skill_service,
|
||||
@@ -897,15 +899,15 @@ class PartnerRunner:
|
||||
|
||||
service = get_skill_service()
|
||||
entries = service.summary_entries()
|
||||
always_block = service.load_always_for_context()
|
||||
return "\n\n".join(
|
||||
part for part in (always_block, render_skills_manifest(entries)) if part
|
||||
)
|
||||
return service.load_always_for_context(), render_skills_manifest(entries)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Failed to build skills manifest for partner %s", self.partner_id, exc_info=True
|
||||
)
|
||||
return ""
|
||||
return "", ""
|
||||
|
||||
def _build_skills_manifest(self) -> str:
|
||||
return "\n\n".join(part for part in self._build_skill_context() if part)
|
||||
|
||||
def _list_kb_names(self) -> list[str]:
|
||||
if getattr(self.config, "workspace_id", ""):
|
||||
|
||||
@@ -637,9 +637,9 @@ class TurnExecutor:
|
||||
)
|
||||
active_persona = requested_persona if persona_context else ""
|
||||
|
||||
from deeptutor.services.skill.runtime import skill_manifest
|
||||
from deeptutor.services.skill.runtime import skill_context
|
||||
|
||||
skills_manifest = skill_manifest()
|
||||
active_skills, skills_manifest = skill_context()
|
||||
|
||||
# Chat capability uses the lightweight manifest + read_source
|
||||
# affordance (no upstream LLM call, no wholesale-dump into the
|
||||
@@ -1017,6 +1017,7 @@ class TurnExecutor:
|
||||
persona_context=persona_context,
|
||||
sidebar_context=sidebar_system_context,
|
||||
skills_manifest=skills_manifest,
|
||||
active_skills_context=active_skills,
|
||||
source_manifest=source_manifest_text,
|
||||
runtime=TurnRuntimeContext(
|
||||
model_history=getattr(history_result, "model_history", None),
|
||||
|
||||
@@ -61,7 +61,14 @@ def runtime_skills() -> dict[str, SkillService]:
|
||||
return resolved
|
||||
|
||||
|
||||
def skill_manifest() -> str:
|
||||
def skill_context() -> tuple[str, str]:
|
||||
"""Return ``(active_skills, skills_manifest)`` for the current scope.
|
||||
|
||||
``active_skills`` holds the full bodies of available ``always`` skills —
|
||||
standing instructions that belong in the system prompt. ``skills_manifest``
|
||||
lists the on-demand skills; it changes whenever a skill is installed,
|
||||
enabled, or selected, so the loop replays it as a runtime snapshot.
|
||||
"""
|
||||
entries = []
|
||||
always = []
|
||||
resolved = runtime_skills()
|
||||
@@ -72,7 +79,13 @@ def skill_manifest() -> str:
|
||||
entries.append(entry)
|
||||
if entry.always and entry.available:
|
||||
always.append(service.load_for_context([entry.name]))
|
||||
return "\n\n".join(part for part in (*always, render_skills_manifest(entries)) if part)
|
||||
active = "\n\n".join(part for part in always if part)
|
||||
return active, render_skills_manifest(entries)
|
||||
|
||||
|
||||
def skill_manifest() -> str:
|
||||
"""Both skill parts joined, for callers that need a single text."""
|
||||
return "\n\n".join(part for part in skill_context() if part)
|
||||
|
||||
|
||||
def resolve_runtime_skill(name: str) -> SkillService:
|
||||
|
||||
@@ -1007,31 +1007,40 @@ class SkillService:
|
||||
|
||||
|
||||
def render_skills_manifest(entries: list[SkillSummaryEntry]) -> str:
|
||||
"""Render manifest rows into the system-prompt Skills block.
|
||||
"""Render manifest rows into the Skills runtime snapshot.
|
||||
|
||||
``always`` entries are excluded — their full bodies are already injected
|
||||
eagerly, so listing them again would only waste tokens. Duplicate names
|
||||
keep their first occurrence (caller orders user > admin > builtin).
|
||||
Only skills the model can actually use are listed. ``always`` entries are
|
||||
excluded — their full bodies are already injected eagerly, so listing them
|
||||
again would only waste tokens. Unavailable skills collapse into one count
|
||||
line (with their unmet requirements) so the model can still explain why a
|
||||
workflow is missing without paying a row per skill. Duplicate names keep
|
||||
their first occurrence (caller orders user > admin > builtin).
|
||||
"""
|
||||
seen: set[str] = set()
|
||||
lines: list[str] = []
|
||||
unavailable = 0
|
||||
missing: list[str] = []
|
||||
for entry in entries:
|
||||
if entry.always or entry.name in seen:
|
||||
continue
|
||||
seen.add(entry.name)
|
||||
suffix = ""
|
||||
if not entry.available:
|
||||
suffix = f" (unavailable: {', '.join(entry.missing)})"
|
||||
unavailable += 1
|
||||
missing.extend(item for item in entry.missing if item not in missing)
|
||||
continue
|
||||
description = entry.description or entry.name
|
||||
lines.append(f"- **{entry.name}** — {description}{suffix}")
|
||||
lines.append(f"- **{entry.name}** — {description}")
|
||||
if unavailable:
|
||||
reason = f" (missing: {', '.join(missing)})" if missing else ""
|
||||
noun = "skill is" if unavailable == 1 else "skills are"
|
||||
lines.append(f"- {unavailable} more {noun} installed but unavailable here{reason}.")
|
||||
if not lines:
|
||||
return ""
|
||||
return (
|
||||
"## Skills\n"
|
||||
"Specialised playbooks available on demand. When a task matches a "
|
||||
"skill's description, call `read_skill` with its name BEFORE "
|
||||
"attempting the task, then follow the returned instructions. Skills "
|
||||
"marked unavailable cannot be used until their requirements are met.\n\n" + "\n".join(lines)
|
||||
"attempting the task, then follow the returned instructions.\n\n" + "\n".join(lines)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -63,9 +63,11 @@ def test_manifest_excludes_always_and_marks_unavailable(tmp_path: Path) -> None:
|
||||
assert "**normal**" in manifest
|
||||
# always-skills are injected eagerly, not listed in the manifest
|
||||
assert "housekeeping" not in manifest
|
||||
# unmet requirement is surfaced
|
||||
assert "needs-git" in manifest
|
||||
assert "unavailable" in manifest
|
||||
# an unusable skill is not advertised by name — only counted, with the
|
||||
# missing requirement, so the model does not try to read it
|
||||
assert "needs-git" not in manifest
|
||||
assert "1 more skill is installed but unavailable here" in manifest
|
||||
assert "definitely-not-a-real-bin" in manifest
|
||||
|
||||
|
||||
def test_load_always_for_context(tmp_path: Path) -> None:
|
||||
|
||||
Reference in New Issue
Block a user