diff --git a/backend/.env.example b/backend/.env.example index b5005d8..b27a3a0 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -23,4 +23,7 @@ TAVILY_API_KEY= LANGSMITH_TRACING= LANGSMITH_ENDPOINT= LANGSMITH_API_KEY= -LANGSMITH_PROJECT= \ No newline at end of file +LANGSMITH_PROJECT= + +#Discord Bot Name Configuration +BOT_NAME = "DevRelBot" #Add your own Discord Bot name \ No newline at end of file diff --git a/backend/app/agents/devrel/github/github_toolkit.py b/backend/app/agents/devrel/github/github_toolkit.py index b419812..20fc50e 100644 --- a/backend/app/agents/devrel/github/github_toolkit.py +++ b/backend/app/agents/devrel/github/github_toolkit.py @@ -104,13 +104,13 @@ async def execute(self, query: str) -> Dict[str, Any]: if classification == "contributor_recommendation": result = await handle_contributor_recommendation(query) elif classification == "repo_support": - result = "Not implemented" + result = {"status": "not_implemented", "message": "Repo support not implemented yet"} # result = await handle_repo_query(query) elif classification == "issue_creation": result = "Not implemented" # result = await handle_issue_creation(query) elif classification == "documentation_generation": - result = "Not implemented" + result = {"status": "not_implemented", "message": "Documentation generation is not yet implemented"} # result = await handle_documentation_generation(query) elif classification == "web_search": result = await handle_web_search(query) diff --git a/backend/app/classification/classification_router.py b/backend/app/classification/classification_router.py index 1708dce..e5df05f 100644 --- a/backend/app/classification/classification_router.py +++ b/backend/app/classification/classification_router.py @@ -8,9 +8,10 @@ logger = logging.getLogger(__name__) class ClassificationRouter: - """Simple DevRel triage - determines if message needs DevRel assistance""" + """Strict DevRel triage - determines if message needs DevRel assistance""" def __init__(self, llm_client=None): + self.bot_name = settings.bot_name.lower() self.llm = llm_client or ChatGoogleGenerativeAI( model=settings.classification_agent_model, temperature=0.1, @@ -18,16 +19,23 @@ def __init__(self, llm_client=None): ) async def should_process_message(self, message: str, context: Dict[str, Any] = None) -> Dict[str, Any]: - """Simple triage: Does this message need DevRel assistance?""" + """Strict triage: Does this message need DevRel assistance?""" try: + # Detect explicit bot mention + mention_flag = False + if self.bot_name in message.lower(): + mention_flag = True + # Add note to the context so LLM knows it was mentioned + context = (context or '') + f" | Note: This message explicitly mentions the bot '{self.bot_name}'." + triage_prompt = DEVREL_TRIAGE_PROMPT.format( message=message, context=context or 'No additional context' ) response = await self.llm.ainvoke([HumanMessage(content=triage_prompt)]) - response_text = response.content.strip() + if '{' in response_text: json_start = response_text.find('{') json_end = response_text.rfind('}') + 1 @@ -37,23 +45,25 @@ async def should_process_message(self, message: str, context: Dict[str, Any] = N result = json.loads(json_str) return { - "needs_devrel": result.get("needs_devrel", True), + "needs_devrel": result.get("needs_devrel", False), "priority": result.get("priority", "medium"), "reasoning": result.get("reasoning", "LLM classification"), - "original_message": message + "original_message": message, + "bot_mentioned": mention_flag } - return self._fallback_triage(message) + return self._fallback_triage(message, mention_flag) except Exception as e: logger.error(f"Triage error: {str(e)}") return self._fallback_triage(message) - def _fallback_triage(self, message: str) -> Dict[str, Any]: - """Fallback: assume it needs DevRel help""" + def _fallback_triage(self, message: str, mention_flag=False) -> Dict[str, Any]: + """Fallback: only trigger DevRel if bot was mentioned and message looks relevant""" return { - "needs_devrel": True, - "priority": "medium", - "reasoning": "Fallback - assuming DevRel assistance needed", - "original_message": message + "needs_devrel": mention_flag, + "priority": "medium" if mention_flag else "low", + "reasoning": "Fallback - bot mention" if mention_flag else "Fallback - no DevRel assistance", + "original_message": message, + "bot_mentioned": mention_flag } diff --git a/backend/app/core/config/settings.py b/backend/app/core/config/settings.py index f314a94..402bec8 100644 --- a/backend/app/core/config/settings.py +++ b/backend/app/core/config/settings.py @@ -15,6 +15,7 @@ class Settings(BaseSettings): # Platforms github_token: str = "" discord_bot_token: str = "" + bot_name: str = "DevRelBot" # 👈 Default bot name, can override via .env # DB configuration supabase_url: str