修复一些已知问题
This commit is contained in:
@@ -5,6 +5,7 @@ InterviewAgent:正式访谈 Specialist
|
||||
|
||||
from typing import Any, List
|
||||
|
||||
from app.agents.chat.agent_turn import AgentChatTurn
|
||||
from app.core.dependencies import get_llm_provider
|
||||
from app.core.logging import get_logger
|
||||
|
||||
@@ -18,6 +19,9 @@ from app.agents.state_schema import MemoirStateSchema
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
# LLM 不可用或调用失败时对用户展示(不暴露异常细节、不触发 TTS)
|
||||
_FALLBACK_REPLY = "刚才网络不太稳,没接上。你可以再说一遍,或稍后再试。"
|
||||
|
||||
|
||||
def _get_langchain_llm():
|
||||
try:
|
||||
@@ -149,12 +153,11 @@ class InterviewAgent:
|
||||
user_message: str,
|
||||
memoir_state: MemoirStateSchema,
|
||||
user_profile_context: str = "",
|
||||
) -> List[str]:
|
||||
) -> AgentChatTurn:
|
||||
"""生成状态感知的访谈回复,不持久化(由 Orchestrator 负责)"""
|
||||
if not self.llm:
|
||||
return [
|
||||
"抱歉,LLM 服务未配置。请设置 DEEPSEEK_API_KEY 或 LLM_API_KEY 环境变量。"
|
||||
]
|
||||
logger.warning("InterviewAgent: LLM 未配置,返回兜底文案")
|
||||
return AgentChatTurn(messages=[_FALLBACK_REPLY], skip_tts=True)
|
||||
try:
|
||||
empty_slots = memoir_state.empty_slots_for_current_stage()
|
||||
filled_slots = {
|
||||
@@ -191,10 +194,11 @@ class InterviewAgent:
|
||||
messages = [
|
||||
msg.strip() for msg in response_text.split("[SPLIT]") if msg.strip()
|
||||
]
|
||||
return messages[:3] if messages else [response_text]
|
||||
out = messages[:3] if messages else [response_text]
|
||||
return AgentChatTurn(messages=out, skip_tts=False)
|
||||
except Exception as e:
|
||||
logger.error("生成回应失败: %s", e)
|
||||
return [f"抱歉,生成回应时出现错误: {str(e)}"]
|
||||
logger.error("生成回应失败: %s", e, exc_info=True)
|
||||
return AgentChatTurn(messages=[_FALLBACK_REPLY], skip_tts=True)
|
||||
|
||||
async def generate_opening_message(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user