How I replaced 200 lines of regex with a fine-tuned 7B model β and why it was worth it.
The Problem
I built an autonomous AI agent with 9 tools: web search, calculator, weather, Wikipedia, translation, and more. The first question every request must answer is deceptively simple:
Which tool should I use?
My first solution was a heuristic classifier β a function called classify_query() that uses regex patterns to detect intent:
# 200+ lines of patterns like this: _SEARCH_INDICATORS = re . compile ( r " \b(latest|current|news|today|recent|who won|score|price| " r " stock|update|happening|trending|release|launched)\b " , re . IGNORECASE )
_KNOWLEDGE_INDICATORS = re . compile ( r " \b(explain|what is|how does|define|difference between| " r " why do|concept of|overview|meaning of|works)\b " , re . IGNORECASE )
Enter fullscreen mode
Exit fullscreen mode
It worked.β¦