diff --git a/src/fabledassistant/services/intent.py b/src/fabledassistant/services/intent.py index 0473bf6..7d8b1e8 100644 --- a/src/fabledassistant/services/intent.py +++ b/src/fabledassistant/services/intent.py @@ -104,12 +104,17 @@ Rules: ("search for X", "look up X", "what is the latest version of X", "find X online", "google X", "what is X" for quick factual answers — NOT when they want a comprehensive note) - research_topic: user wants to research a topic and create a comprehensive note from web sources - ("research X", "research X and make a note", "compile notes on X", "write a report on X", - "deep dive into X", "find everything about X", "comprehensive guide to X") + ("research X", "Research: X", "research X and make a note", "compile notes on X", "write a report on X", + "deep dive into X", "find everything about X", "comprehensive guide to X", + "research where to buy X", "research how to X", "research X and ship to me" — the topic + is everything after "Research:" or "research") - "ack": one short, natural sentence confirming the action (tool path only). Vary phrasing — do not always start with "Let me". Omit (null) for chat-only responses. - Do NOT wrap the JSON in markdown code fences.""" +_RESEARCH_PREFIX = re.compile(r"^[Rr]esearch:\s+(.+)", re.DOTALL) + + async def classify_intent( user_message: str, tools: list[dict], @@ -127,6 +132,21 @@ async def classify_intent( if not tools: return IntentResult() + # Fast-path: "Research: " is the canonical format sent by the Research + # button in the UI. It always means research_topic — skip the LLM call entirely. + valid_names = {t.get("function", {}).get("name") for t in tools} + if "research_topic" in valid_names: + m = _RESEARCH_PREFIX.match(user_message.strip()) + if m: + topic = m.group(1).strip() + logger.info("Intent fast-path: 'Research:' prefix → research_topic, topic='%s'", topic[:80]) + return IntentResult( + tool_name="research_topic", + arguments={"topic": topic}, + confidence="high", + ack=f"I'll research that and compile a comprehensive note.", + ) + tool_summary = _build_tool_summary(tools) today = date_type.today().isoformat()