DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(partners): never spend an answer on a keyword guess
ZQR11016bba21e96cfb
diff --git a/deeptutor/capabilities/partner_authoring/binding.py b/deeptutor/capabilities/partner_authoring/binding.pyindex 17f7bb0c1..7b8b92371 100644--- a/deeptutor/capabilities/partner_authoring/binding.py+++ b/deeptutor/capabilities/partner_authoring/binding.py@@ -20,16 +20,31 @@ _OBJECT = re.compile()-def is_partner_authoring_turn(context: UnifiedContext) -> bool:+def partner_authoring_trigger(context: UnifiedContext) -> str | None:+ """Why this turn is in the authoring flow, or ``None`` when it is not.++ ``explicit`` means the user selected the capability; ``heuristic`` means only+ the keyword gate matched, which is a guess about the words they typed.+ """# Home/product Chat owns the review card and confirmation flow. A Partner# (including one running inside a Group) must not create drafts inside its# synthetic workspace merely because someone talks about another Partner.if context.metadata.get("source") == "partner":- return False+ return Noneif context.active_capability == PARTNER_AUTHORING_CAPABILITY_NAME:- return True+ return "explicit"text = str(context.user_message or "")- return bool(_ACTION.search(text) and _OBJECT.search(text))+ if _ACTION.search(text) and _OBJECT.search(text):+ return "heuristic"+ return None+++def is_partner_authoring_turn(context: UnifiedContext) -> bool:+ return partner_authoring_trigger(context) is not None-__all__ = ["PARTNER_AUTHORING_CAPABILITY_NAME", "is_partner_authoring_turn"]+__all__ = [+ "PARTNER_AUTHORING_CAPABILITY_NAME",+ "is_partner_authoring_turn",+ "partner_authoring_trigger",+]diff --git a/deeptutor/capabilities/partner_authoring/capability.py b/deeptutor/capabilities/partner_authoring/capability.pyindex 1370f18f6..7af6d5216 100644--- a/deeptutor/capabilities/partner_authoring/capability.py+++ b/deeptutor/capabilities/partner_authoring/capability.py@@ -8,6 +8,7 @@ from typing import Anyfrom deeptutor.capabilities.partner_authoring.binding import (PARTNER_AUTHORING_CAPABILITY_NAME,is_partner_authoring_turn,+ partner_authoring_trigger,)from deeptutor.capabilities.partner_authoring.tools import PARTNER_AUTHORING_TOOL_NAMESfrom deeptutor.capabilities.protocol import PromptBlock@@ -51,6 +52,12 @@ class PartnerAuthoringCapability:_ = final_textif context.extension(self.name).get("draft_created"):return ""+ if partner_authoring_trigger(context) != "explicit":+ # Returning an instruction makes the loop discard the answer already+ # written this round, so only a request the user chose to make may+ # pay that cost. A keyword match is a guess about their words, and+ # guessing must never delete a response (#1587).+ return ""return ("The user asked to create a Partner, but no reviewable draft exists yet. ""Call propose_partner now with a complete profile; do not merely describe one."diff --git a/tests/capabilities/test_partner_authoring_capability.py b/tests/capabilities/test_partner_authoring_capability.pyindex d4f4615a3..aa570f881 100644--- a/tests/capabilities/test_partner_authoring_capability.py+++ b/tests/capabilities/test_partner_authoring_capability.py@@ -26,14 +26,38 @@ def test_partner_authoring_activation_requires_action_and_partner_object() -> Noassert not is_partner_authoring_turn(partner_context)-def test_capability_forces_a_draft_before_finishing() -> None:+def _selected_context(message: str) -> UnifiedContext:+ context = _context(message)+ context.active_capability = "partner_authoring"+ return context+++def test_explicit_selection_forces_a_draft_before_finishing() -> None:capability = PartnerAuthoringCapability()- context = _context("创建一个伙伴")+ context = _selected_context("创建一个伙伴")assert "propose_partner" in capability.finish_instruction(context, "好的")context.extension("partner_authoring")["draft_created"] = "draft"assert capability.finish_instruction(context, "完成") == ""+ "message",+ [+ # Filing a report about the false trigger supplies one word from each+ # list, so the bug report about the bug triggers the bug.+ 'I want to file an issue about this: Spurious "Create Partner" triggers hijack',+ "Please add a companion-style tone to my summary",+ ],+)+def test_a_keyword_match_never_discards_the_answer(message: str) -> None:+ # A finish instruction makes the loop throw away the reply written this+ # round, so it has to cost something the user actually asked for (#1587).+ capability = PartnerAuthoringCapability()+ context = _context(message)+ assert is_partner_authoring_turn(context)+ assert capability.finish_instruction(context, "A careful answer.") == ""++@pytest.mark.asyncioasync def test_propose_partner_persists_user_scoped_reviewable_draft(tmp_path: Path) -> None:user = CurrentUser(