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:
parent
f5820f9c7f
commit
b7e84ba3b6
|
|
@ -196,13 +196,17 @@ export class CoordinatorAgentService implements OnModuleInit {
|
|||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// 0. Input Gate — 轻量级预检
|
||||
// 0. Input Gate — 仅对首条消息运行(无历史对话时)
|
||||
// 已在对话中的用户由 Coordinator prompt 管理话题,避免短回复被误判偏题
|
||||
const hasPreviousMessages = context.previousMessages && context.previousMessages.length > 0;
|
||||
if (!hasPreviousMessages) {
|
||||
const gateResult = await this.inputGate.classify(userContent);
|
||||
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: 文本附件需下载内容)
|
||||
const messages = await this.buildMessages(context, userContent, attachments);
|
||||
|
|
|
|||
Loading…
Reference in New Issue