Remove CRM chat fallback responses

This commit is contained in:
Ruslan Bakiev
2026-02-19 14:48:26 +07:00
parent 808b918894
commit 2f64bc51dc
2 changed files with 15 additions and 31 deletions

View File

@@ -111,10 +111,14 @@ export async function runCrmAgentFor(
process.env.QWEN_API_KEY;
const hasGigachat = Boolean((process.env.GIGACHAT_AUTH_KEY ?? "").trim() && (process.env.GIGACHAT_SCOPE ?? "").trim());
if (mode !== "rule" && (llmApiKey || hasGigachat)) {
if (mode !== "rule") {
return runLangGraphCrmAgentFor(input);
}
if (!llmApiKey && !hasGigachat) {
throw new Error("LLM API key is not configured. Set OPENROUTER_API_KEY or GIGACHAT_AUTH_KEY/GIGACHAT_SCOPE.");
}
await ensureDataset({ teamId: input.teamId, userId: input.userId });
const q = normalize(input.userText);
const root = datasetRoot({ teamId: input.teamId, userId: input.userId });
@@ -220,18 +224,9 @@ export async function runCrmAgentFor(
};
}
// Default: keep it simple, ask for intent + show what the agent can do.
return {
plan: ["Уточнить цель", "Выбрать данные для анализа", "Предложить план действий и, если нужно, изменения в CRM"],
tools: ["read index/contacts.json (по необходимости)", "search messages/events (по необходимости)"],
toolRuns: [],
text:
"Ок. Скажи, что нужно сделать.\n" +
"Примеры:\n" +
"- \"покажи 10 лучших клиентов\"\n" +
"- \"чем мне сегодня заняться\"\n" +
"- \"составь план касаний на неделю\"\n",
};
throw new Error(
"Rule mode has no fallback responses. Use a supported structured query or switch to langgraph mode with a configured LLM API key.",
);
}
export async function persistChatMessage(input: {

View File

@@ -441,17 +441,9 @@ export async function runLangGraphCrmAgentFor(input: {
}
if (!llmApiKey) {
return {
text: "LLM API key не задан. Сейчас включен fallback-агент без LLM.",
plan: [
"Проверить .env",
"Добавить OPENROUTER_API_KEY (или LLM_API_KEY / OPENAI_API_KEY / DASHSCOPE_API_KEY / QWEN_API_KEY / GIGACHAT_AUTH_KEY+GIGACHAT_SCOPE)",
"Перезапустить dev-сервер",
],
tools: [],
thinking: ["LLM недоступна, возвращен fallback-ответ."],
toolRuns: [],
};
throw new Error(
"LLM API key is not configured. Set OPENROUTER_API_KEY (or GIGACHAT_AUTH_KEY/GIGACHAT_SCOPE) and restart.",
);
}
// Keep the dataset fresh so the "CRM filesystem" stays in sync with DB.
@@ -1002,7 +994,7 @@ export async function runLangGraphCrmAgentFor(input: {
};
const extractResult = (res: any) => {
const fallbackText = (() => {
const extractedText = (() => {
const messages = Array.isArray(res?.messages) ? res.messages : [];
for (let i = messages.length - 1; i >= 0; i -= 1) {
const msg = messages[i];
@@ -1015,7 +1007,7 @@ export async function runLangGraphCrmAgentFor(input: {
})();
return {
text: fallbackText.trim(),
text: extractedText.trim(),
};
};
@@ -1063,16 +1055,13 @@ export async function runLangGraphCrmAgentFor(input: {
),
]);
} catch (e: any) {
await emitTrace({ text: "Один из шагов завершился ошибкой, пробую безопасный обход." });
await emitTrace({ text: "Один из шагов завершился ошибкой." });
cycleSpan?.end({
output: "error",
level: "ERROR",
statusMessage: String(e?.message ?? e ?? "unknown_error"),
});
if (!finalText) {
finalText = "Не удалось завершить задачу за отведенное время. Уточни запрос или сократи объем.";
}
break;
throw e;
}
const parsed = extractResult(res);