fix(partners): only start Partner authoring on an actual creation request

The authoring gate matched an action word and a Partner word anywhere in
the message, so turns that only mention a Partner ("I want to file an
issue about the Partner bug", "the release notes mention Partner
channels", "I need help understanding my tutor's feedback") activated the
capability, and finish_instruction then forced a propose_partner draft
the user never asked for.

Require the action to lead into the Partner object within one clause
(e.g. "create a Socratic tutor", "帮我创建一个学习伙伴"), and stop the
Chinese match at words that make the Partner a topic (关于/有关/提到/讨论).

Closes #1587
This commit is contained in:
Mohammad Hijjawi
2026-09-25 13:02:17 +01:00
parent a053fecf6e
commit 4f5db49b34
2 changed files with 52 additions and 8 deletions

View File

@@ -8,14 +8,26 @@ from deeptutor.core.context import UnifiedContext
PARTNER_AUTHORING_CAPABILITY_NAME = "partner_authoring"
_ACTION = re.compile(
r"(创建|新建|生成|设计|定制|做一个|来一个|来个|想要|需要|帮我做|帮我建|加一个)"
r"|(\bcreate\b|\bmake\b|\bbuild\b|\bdesign\b|\bgenerate\b|\bwant\b|\bneed\b|\badd\b)",
re.IGNORECASE,
# The action has to lead into the Partner object within one clause. Matching the two words
# anywhere in the message fired on turns that only mention a Partner ("I want to file an issue
# about the Partner bug"), and finish_instruction then forces a draft the user never asked for.
_ZH_ACTION = (
r"(?:创建|新建|生成|设计|定制|帮我做|帮我建|做一个|来一个|来个|加一个"
r"|(?:想要|需要)(?:一个|一位|个|位))"
)
_OBJECT = re.compile(
r"(partner|伙伴|学习搭子|陪伴者|陪练|助教|导师|教练|学伴|智能体|角色)"
r"|(\bcompanion\b|\btutor\b|\bmentor\b|\bcoach\b|\bstudy buddy\b)",
_ZH_OBJECT = r"(?:partner|伙伴|学习搭子|陪伴者|陪练|助教|导师|教练|学伴|智能体|角色)"
# Stops at clause punctuation and at words that make the object a topic rather than the target.
_ZH_GAP = r"(?:(?!关于|有关|提到|讨论)[^。!?!?;;,,、\n]){0,16}?"
_EN_ACTION = (
r"(?:\b(?:create|make|build|design|generate|add|set\s+up)\b(?:\s+(?:me|us))?"
r"|\b(?:want|need)\b)"
)
_EN_DETERMINER = r"\s+(?:a|an|another|one|my\s+own|our\s+own|a\s+new|new)\b"
_EN_GAP = r"(?:\s+(?!(?:about|with|for|of|from|in|on|to|that|which)\b)[\w'-]+){0,3}?"
_EN_OBJECT = r"\s+(?:partners?|companions?|tutors?|mentors?|coach(?:es)?|study\s+budd(?:y|ies))\b"
_AUTHORING_REQUEST = re.compile(
rf"{_ZH_ACTION}{_ZH_GAP}{_ZH_OBJECT}|{_EN_ACTION}{_EN_DETERMINER}{_EN_GAP}{_EN_OBJECT}",
re.IGNORECASE,
)
@@ -29,7 +41,7 @@ def is_partner_authoring_turn(context: UnifiedContext) -> bool:
if context.active_capability == PARTNER_AUTHORING_CAPABILITY_NAME:
return True
text = str(context.user_message or "")
return bool(_ACTION.search(text) and _OBJECT.search(text))
return _AUTHORING_REQUEST.search(text) is not None
__all__ = ["PARTNER_AUTHORING_CAPABILITY_NAME", "is_partner_authoring_turn"]

View File

@@ -26,6 +26,38 @@ def test_partner_authoring_activation_requires_action_and_partner_object() -> No
assert not is_partner_authoring_turn(partner_context)
@pytest.mark.parametrize(
"message",
[
"Create a partner that quizzes me on French verbs",
"I want a patient math tutor",
"Can you make me a strict coach?",
"Set up a new study buddy for physics",
"我想要一个数学导师",
"来个学习搭子",
],
)
def test_partner_authoring_activates_on_a_creation_request(message: str) -> None:
assert is_partner_authoring_turn(_context(message))
@pytest.mark.parametrize(
"message",
[
"I want to file an issue about the Partner bug",
"I want to report that Partner creation keeps triggering",
"I need help understanding my tutor's feedback",
"Make sure my tutor sees this",
"Why can a flash-tier model answer well? The release notes mention Partner channels.",
"我想提交一个关于伙伴功能的 bug",
"生成的回答里提到了伙伴",
"我需要解释一下,为什么会触发伙伴创建",
],
)
def test_partner_authoring_ignores_turns_that_only_mention_a_partner(message: str) -> None:
assert not is_partner_authoring_turn(_context(message))
def test_capability_forces_a_draft_before_finishing() -> None:
capability = PartnerAuthoringCapability()
context = _context("创建一个伙伴")