fix(agents): only run InputGate on first message to prevent mid-conversation misclassification

Short follow-up answers like "计算机,信息技术" were being classified as
OFF_TOPIC (0.85) because the InputGate has no conversation context. Now the
gate only runs when there are no previous messages (first message in conversation).
Mid-conversation topic management is handled by the Coordinator prompt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-07 09:43:33 -08:00
parent f5820f9c7f
commit b7e84ba3b6
1 changed files with 10 additions and 6 deletions

View File

@ -196,12 +196,16 @@ export class CoordinatorAgentService implements OnModuleInit {
const startTime = Date.now(); const startTime = Date.now();
try { try {
// 0. Input Gate — 轻量级预检 // 0. Input Gate — 仅对首条消息运行(无历史对话时)
const gateResult = await this.inputGate.classify(userContent); // 已在对话中的用户由 Coordinator prompt 管理话题,避免短回复被误判偏题
if (gateResult.classification !== 'ON_TOPIC' && gateResult.fixedResponse) { const hasPreviousMessages = context.previousMessages && context.previousMessages.length > 0;
yield { type: 'text', content: gateResult.fixedResponse }; if (!hasPreviousMessages) {
yield { type: 'end', inputTokens: 0, outputTokens: 0 }; const gateResult = await this.inputGate.classify(userContent);
return; if (gateResult.classification !== 'ON_TOPIC' && gateResult.fixedResponse) {
yield { type: 'text', content: gateResult.fixedResponse };
yield { type: 'end', inputTokens: 0, outputTokens: 0 };
return;
}
} }
// 1. Build messages from conversation history (async: 文本附件需下载内容) // 1. Build messages from conversation history (async: 文本附件需下载内容)