refactor(agent): 移除未使用的通用问题检测逻辑
清理不再使用的通用问题检测函数及相关正则表达式模式,简化代码结构
This commit is contained in:
parent
88b7eabe14
commit
28e0fe7c27
@ -8,7 +8,6 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
@ -86,35 +85,6 @@ Guidelines:
|
||||
MAX_ITERATIONS = 10
|
||||
_TOOL_MAP = {t.name: t for t in TOOLS}
|
||||
|
||||
QUESTION_PATTERNS = [
|
||||
r'\?$', # ends with ?
|
||||
r'?$', # ends with Chinese ?
|
||||
r'\b(what|how|why|when|where|who|which|explain|describe|tell me|can you|could you|is there|are there|do you know)\b',
|
||||
r'(什么|怎么|为什么|何时|哪里|谁|哪个|解释|描述|告诉我|能否|可以|有没有|是不是)',
|
||||
]
|
||||
|
||||
|
||||
def _is_general_question(text: str) -> bool:
|
||||
"""Check if text looks like a general knowledge question (not a project task)."""
|
||||
text_lower = text.lower().strip()
|
||||
|
||||
project_indicators = [
|
||||
'create', 'make', 'build', 'fix', 'update', 'delete', 'remove', 'add',
|
||||
'implement', 'refactor', 'test', 'run', 'execute', 'start', 'stop',
|
||||
'project', 'folder', 'directory', 'file', 'code', 'session',
|
||||
'创建', '制作', '构建', '修复', '更新', '删除', '添加', '实现', '重构', '测试', '运行', '项目', '文件夹', '文件', '代码',
|
||||
]
|
||||
|
||||
for indicator in project_indicators:
|
||||
if indicator in text_lower:
|
||||
return False
|
||||
|
||||
for pattern in QUESTION_PATTERNS:
|
||||
if re.search(pattern, text_lower, re.IGNORECASE):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class OrchestrationAgent:
|
||||
"""Per-user agent with conversation history and active session tracking."""
|
||||
@ -186,23 +156,6 @@ class OrchestrationAgent:
|
||||
logger.exception("Passthrough error for user=%s", user_id)
|
||||
return f"[Error] {exc}"
|
||||
|
||||
# Direct Q&A: if no active session and message looks like a general question, answer directly
|
||||
if not active_conv and _is_general_question(text):
|
||||
logger.debug(" → direct Q&A (no tools)")
|
||||
llm_no_tools = ChatOpenAI(
|
||||
base_url=OPENAI_BASE_URL,
|
||||
api_key=OPENAI_API_KEY,
|
||||
model=OPENAI_MODEL,
|
||||
temperature=0.7,
|
||||
)
|
||||
qa_prompt = (
|
||||
"You are a helpful assistant. Answer the user's question concisely and accurately. "
|
||||
"Reply in the same language the user uses.\n\n"
|
||||
f"Question: {text}"
|
||||
)
|
||||
response = await llm_no_tools.ainvoke([HumanMessage(content=qa_prompt)])
|
||||
return response.content or ""
|
||||
|
||||
messages: list[BaseMessage] = (
|
||||
[SystemMessage(content=self._build_system_prompt(user_id))]
|
||||
+ self._history[user_id]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user