Skip to content

Feature/remove hardcode#2

Open
Fiona361123 wants to merge 10 commits intobrewtechsolutions:mainfrom
Fiona361123:feature/remove-hardcode
Open

Feature/remove hardcode#2
Fiona361123 wants to merge 10 commits intobrewtechsolutions:mainfrom
Fiona361123:feature/remove-hardcode

Conversation

@Fiona361123
Copy link
Contributor

  • 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Generic Multi-Agent Architecture: The chatbot architecture has been refactored to be more generic and domain-agnostic, moving towards a config-driven multi-agent pipeline (Analysis → Routing → Retrieval → Ranking → Response) that can be configured for any product type without code changes.
  • Centralized AI Configuration: A new ai-registry.js file was introduced to centralize all AI model assignments, temperature settings, max tokens, and tool access for different agent roles (e.g., ANALYZER, RANKER, OPTIMIZER), removing hardcoded values from individual agents.
  • Config-Driven Analysis Agents: The AnalysisAgent is now fully configurable via workflow.json, allowing dynamic definition of intents, entities, system prompts, active skills, and fast-path rules, significantly reducing hardcoding.
  • Enhanced Session Memory for Selections: A new session-option-sets.js utility was added to provide robust session memory for numbered product lists, allowing users to select items by number or name from any previously displayed list within the conversation.
  • Improved Location Detection and Bug Fixes: The local_market_expert skill in analysis-agent.js and workflow.json was refined to improve location detection, differentiate between stating a location and asking about one, and fix issues with agent function calls.
  • Persistent User Language Preferences: The system now saves and retrieves user language preferences to ensure consistent conversation language across sessions, preventing language switching unless explicitly changed by the user.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +241 to +295
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants