Skip to content

Node/add history#61

Merged
JulienExr merged 2 commits into
mainfrom
node/add_history
Feb 25, 2026
Merged

Node/add history#61
JulienExr merged 2 commits into
mainfrom
node/add_history

Conversation

@JulienExr
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings February 25, 2026 15:16
@JulienExr JulienExr merged commit 3bb92a3 into main Feb 25, 2026
2 of 3 checks passed
@JulienExr JulienExr deleted the node/add_history branch February 25, 2026 15:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds conversation history context to the ambiguity detection node to better handle follow-up questions and understand the full context of user queries.

Changes:

  • Added conversation history building logic that formats all messages as "Utilisateur"/"Assistant" pairs
  • Updated the prompt to include the formatted conversation history
  • Added explanatory text in the prompt about how to use the history for context
Comments suppressed due to low confidence (4)

core/nodes/ambiguity_detector.py:27

  • If the messages list is empty, the history_text will be an empty string, but the code will still iterate over an empty list without issue. However, consider adding a guard check before line 25 (if not messages: history_text = "No conversation history") to make the prompt clearer when there's no history, rather than leaving an empty section.
    history_text = ""
    for m in messages:
        role = "Utilisateur" if m.type == "human" else "Assistant"
        history_text += f"{role}: {m.content}\n"

core/nodes/ambiguity_detector.py:27

  • The history building logic doesn't account for message types other than "human" and "ai". Messages can also have type "tool" (as seen in validator.py and graph.py). Tool messages will be incorrectly labeled as "Assistant" in the history. Consider handling all message types explicitly or filtering out tool messages if they shouldn't be included in the conversation history shown to the LLM.
        role = "Utilisateur" if m.type == "human" else "Assistant"
        history_text += f"{role}: {m.content}\n"

core/nodes/ambiguity_detector.py:33

  • Spelling error: "informations" should be "information" in English. The word "information" is uncountable in English and doesn't take a plural form.
    You can find informations in the history of the conversation, the last question can be just a precision or a follow-up, you have to consider the whole history to understand the context of the question and detect ambiguity.

core/nodes/ambiguity_detector.py:80

  • The conversation history includes all messages including the last user question, which is then also shown separately as "USER QUESTION". This creates redundancy in the prompt. Consider either excluding the last message from the history (for m in messages[:-1]) or removing the separate USER QUESTION field. The current implementation may confuse the LLM by presenting the same question twice.
    history_text = ""
    for m in messages:
        role = "Utilisateur" if m.type == "human" else "Assistant"
        history_text += f"{role}: {m.content}\n"


    prompt = f"""
    You are the Ambiguity Detector Router for the Montreal Mobility Copilot.
    Your ONLY job is to map the user's question to the correct routing flags.
    You can find informations in the history of the conversation, the last question can be just a precision or a follow-up, you have to consider the whole history to understand the context of the question and detect ambiguity.

    🚨 RULES (CRITICAL) 🚨
    If location is missing assume it's for the whole Montreal city.
    If timeframe is missing, assume it's for all available data.
    Only flag as ambiguous if the lack of this information would lead to a completely different answer or if the question is too vague to even attempt a database query.

    🚨 DOMAINS & DATASETS 🚨
    {business_context}
    {dataset_descriptions}

    🚨 CLASSIFICATION RULES 🚨
    1. RANKINGS/HOTSPOTS (NEVER AMBIGUOUS): Questions asking for "the most", "top", "worst", "axes", "le plus de" are NEVER ambiguous. They imply a full database scan. Set `is_ambiguous=False` and `need_external_data=True`.
    2. MISSING PARAMS (AMBIGUOUS): Questions asking for a specific count ("Combien de...") without a timeframe (year/month) or location. Set `is_ambiguous=True`.
    3. CHAT/BYPASS: Greetings or non-mobility questions. Set `is_ambiguous=False` and `need_external_data=False`.
    4. WEATHER-311 CORRELATIONS: Questions asking for correlations between weather and 311 requests are NEVER ambiguous because we have a specific algorithm for that. Set `is_ambiguous=False` and `need_external_data=True`.
    5. WEATHER PREVISIONS: Questions asking for today's weather or prevision for tomorrow are NOT ambiguous. Set `is_ambiguous=False` and `need_external_data=True`.

    ✅ EXAMPLES (YOU MUST FOLLOW THIS LOGIC) ✅
    
    Question: "Combien de collisions y a-t-il eu ?"
    Thought: Missing timeframe and location for a specific count.
    Output: is_ambiguous=True, need_external_data=False
    
    Question: "Où y a-t-il le plus de nids-de-poule ?"
    Thought: Asks for "le plus de" (Ranking/Hotspot). We scan the whole DB. Not ambiguous.
    Output: is_ambiguous=False, need_external_data=True
    
    Question: "Autour de quels axes STM (arrêts/lignes) observe-t-on le plus de collisions graves ?"
    Thought: Asks for "le plus de" (Ranking/Axes). We will let the SQL agent figure it out. Not ambiguous.
    Output: is_ambiguous=False, need_external_data=True
    
    Question: "Quels sont les signaux faibles aujourd'hui ?"
    Thought: Business rule term (weak signals) + timeframe (today). Not ambiguous.
    Output: is_ambiguous=False, need_external_data=True

    Question: "Quels types de requêtes 311 augmentent quand la température passe sous 0°C ?"
    Thought: Asks for a correlation between weather and 311. We have a specific algorithm for this, but it's not ambiguous because the user is clear about what they want.
    Output: is_ambiguous=False, need_external_data=True

    Question: Quels secteurs ont une hausse de collisions en conditions de pluie/neige
    Thought: Asks for a correlation between weather and collisions. We have a specific algorithm for this, but it's not ambiguous because the user is clear about what they want.
    Output: is_ambiguous=False, need_external_data=True

    USER QUESTION: "{question}"

    CONVERSATION HISTORY:
    {history_text}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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