Conversation
Fiona361123
commented
Mar 26, 2026
- Remove hardcode from the analysis agents
- Adding a session-option-sets.js for let ai model have the memory within in the session
- fix the bugs like location detection error and call agent function
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the chatbot's flexibility and maintainability by transforming it into a truly generic, config-driven multi-agent system. The changes centralize AI model configurations, eliminate hardcoded logic in core agents, and introduce a robust session memory for product selections. This refactoring makes the chatbot easily adaptable to new product domains and improves the accuracy of intent and entity extraction, leading to a more reliable and user-friendly experience. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the chatbot architecture into a generic, multi-agent, and highly configurable system. Key improvements include moving domain-specific logic into workflow.json and introducing a central AI registry for model management. The AnalysisAgent now uses configurable fast-path rules and tool-calling for intent/entity extraction, while AnalysisRouter implements slot-based routing. A new session-option-sets.js utility enhances model selection from displayed lists. The SearchAgent now dynamically extracts brands and includes database error handling. The ResponseAgent ensures consistent language and sanitizes responses. The workflow.json is significantly expanded to define intents, entities, prompts, and routing logic, making the system adaptable to various product domains without code changes. A code duplication was identified in src/agents/search-agent.js regarding the logic for finding alternative products, which could be simplified for better readability and maintainability.
| const modelIsPricey = budgetNum != null && inBudgetAndArea.length === 0; | ||
| if (modelIsPricey) { | ||
| const altConditions = { | ||
| AND: [ | ||
| { active: true }, | ||
| { inStock: true }, | ||
| ...(skipIds.length > 0 ? [{ id: { notIn: skipIds } }] : []), | ||
| ...(budgetCap != null ? [{ price: { lte: budgetCap } }] : []), | ||
| { id: { notIn: [...modelIds] } }, | ||
| ], | ||
| }; | ||
| const alternatives = await prisma.product.findMany({ | ||
| where: altConditions, | ||
| take: 10, | ||
| orderBy: { popularity: 'desc' }, | ||
| }); | ||
| let altFiltered = alternatives; | ||
| if (entities.area) { | ||
| altFiltered = alternatives.filter(p => { | ||
| const locations = p.features?.locations || []; | ||
| return locations.length === 0 || locations.some(loc => | ||
| loc.toLowerCase().includes(entities.area.toLowerCase()) | ||
| ); | ||
| }); | ||
| if (altFiltered.length === 0) altFiltered = alternatives; | ||
| } | ||
| finalProducts = [...finalProducts, ...altFiltered.slice(0, 1)]; | ||
| } else { | ||
| const altConditions = { | ||
| AND: [ | ||
| { active: true }, | ||
| { inStock: true }, | ||
| ...(skipIds.length > 0 ? [{ id: { notIn: skipIds } }] : []), | ||
| { id: { notIn: [...modelIds] } }, | ||
| ], | ||
| }; | ||
| if (budgetCap != null) altConditions.AND.push({ price: { lte: budgetCap } }); | ||
| const alternatives = await prisma.product.findMany({ | ||
| where: altConditions, | ||
| take: 10, | ||
| orderBy: { popularity: 'desc' }, | ||
| }); | ||
| let altFiltered = alternatives; | ||
| if (entities.area) { | ||
| altFiltered = alternatives.filter(p => { | ||
| const locations = p.features?.locations || []; | ||
| return locations.length === 0 || locations.some(loc => | ||
| loc.toLowerCase().includes(entities.area.toLowerCase()) | ||
| ); | ||
| }); | ||
| if (altFiltered.length === 0) altFiltered = alternatives; | ||
| } | ||
| finalProducts = [...finalProducts, ...altFiltered.slice(0, 1)]; | ||
| } | ||
| finalProducts = finalProducts.slice(0, 4); |
There was a problem hiding this comment.
The logic for finding alternative products is duplicated within the if (modelIsPricey) and else blocks. Since the logic is identical in both branches, the conditional statement is redundant. This can be simplified to a single block of code to improve readability and maintainability.
const altConditions = {
AND: [
{ active: true },
{ inStock: true },
...(skipIds.length > 0 ? [{ id: { notIn: skipIds } }] : []),
{ id: { notIn: [...modelIds] } },
],
};
if (budgetCap != null) {
altConditions.AND.push({ price: { lte: budgetCap } });
}
const alternatives = await prisma.product.findMany({
where: altConditions,
take: 10,
orderBy: { popularity: 'desc' },
});
let altFiltered = alternatives;
if (entities.area) {
altFiltered = alternatives.filter(p => {
const locations = p.features?.locations || [];
return locations.length === 0 || locations.some(loc =>
loc.toLowerCase().includes(entities.area.toLowerCase())
);
});
if (altFiltered.length === 0) altFiltered = alternatives;
}
finalProducts.push(...altFiltered.slice(0, 1));