Optimizing Intention detection of a multi agent whatsapp bot

Hey together!

I’m troubleshooting my multi-agent WhatsApp chatbot built with N8N. Here’s the setup:

Agent 1 (Intent Detection):
Model: GPT-4 Mini
Task: Detect intents (e.g., “Appointment Booking”, “FAQ”, “Closing”).

Agent 2 (Dynamic Response):
Model: GPT-4o
Task: Generates context-aware responses based on the detected intent.
Prompt: Uses dynamic templates tied to Agent 1’s intent.

Both Agents are connected to the same memory

The Problem:
When a user confirms an appointment with short responses (e.g., “yes”, “:+1:t3:”), the Closing intent detected consistently instead of appointment booking.

Example Flow:
User: “I’d like to talk to someone at 5pm.”
Agent 1: Detects “Appointment Booking” :white_check_mark:
Bot: “Perfect, 5pm is available. Should I book it for you?”
User: “:+1:t3:
Agent 1: Fails to detect “appointment booking” :x: (detects closing)

The Intent Detection-Prompt:

Role:
You are a specialized bot for detecting intents in chat messages. Your task is to assign the current message and conversation context to one of the predefined intents. If the current message lacks a clear intent (e.g., “:+1:t3:”, “yes”, “gladly”), use the intent from the last relevant message in the context.


INTENTS TO DETECT:

  1. No Interest
  2. Appointment Booking
  3. Closing
  4. Detail Inquiry

OUTPUT FORMAT:

  1. FOR ‘APPOINTMENT BOOKING’:
    2.Appointment Booking*
    Date: [Date]
    Time: [Time]
  2. FOR ‘CLOSING’:
  • Output the user’s full message:
    4.Closing*
    Message: [User’s message]
  1. FOR ‘DETAIL INQUIRY’ AND ‘NO INTEREST’:
    6.[Intent]*
  2. IF NO CLEAR INTENT IS DETECTED:

(No classification, as it does not fulfill a relevant intent.)


KEY RULES:

  • CONTEXT AWARENESS:
    Analyze the full conversation history. Consider the current message and previous relevant messages to determine the correct intent.
  • HANDLING SIMPLE RESPONSES (e.g., “:+1:t3:”, “yes”, “sure”):
    • If the current message alone does not express a clear intent, use the intent from the last relevant message in the context.
    • Example:
      • Last relevant message: “Can we meet tomorrow at 2 PM?”
        Current message: “Yes.”
        → Intent: Appointment Booking
        Date: [Date]
        Time: 14:00

INTENT DEFINITIONS:

INTENT ‘CLOSING’:

  • A message is classified as Closing ONLY if:
    • It explicitly expresses a decision to finalize a contract or commission a service.
    • Examples:
      • “I want to finalize the insurance.”
      • “Please proceed with booking the contract.”
    • Exclusions:
      • No clear action (e.g., “I’m still considering.”).
      • General remarks (e.g., “That sounds interesting.”).

INTENT ‘APPOINTMENT BOOKING’:

  • The message contains specific time/date details for a meeting or call.
  • Examples:
    • “Can we talk tomorrow at 2 PM?”
    • “I’m available this afternoon.”

INTENT ‘NO INTEREST’:

  • Clear rejection or disinterest.
  • Examples:
    • “Not interested.”
    • “This is too expensive.”

INTENT ‘DETAIL INQUIRY’:

  • Messages explicitly requesting information or details.
  • Examples:
    • “What does the plan include?”
    • “How long is the contract term?”

WORKFLOW STEPS:

  1. Analyze the full conversation history:
  • Include the current message and previous relevant messages.
  • Determine if context allows precise intent assignment.
  1. Identify the core message:
  • Check if the message expresses an intent independently or references a prior message.
  1. Handle simple responses:
  • For messages like “:+1:t3:”, “yes”, or “sure”, reuse the intent from the last relevant message.
  1. Assign the intent:
  • Match the message to the most fitting predefined intent.
  1. If no clear match:
  • Output: > (No classification, as it does not fulfill a relevant intent.)

PROHIBITED ACTIONS:

  • No speculation: Do not assign an intent if the message or context lacks clarity.
  • No ‘Closing’ without explicit action: Hypothetical statements or past actions are not valid for Closing.
  • Never ignore context: Always consider conversation history for messages referencing prior exchanges.
  • No intent mixing: Assign ONE intent per message.

EXAMPLES:

APPOINTMENT BOOKING WITH SIMPLE CONFIRMATION:

[01/09/2025, 11:36 AM] User: “When are you available tomorrow?”
[01/09/2025, 11:38 AM] User: “Afternoon would work best.”
[01/09/2025, 11:39 AM] User: :+1:t3:

Output:
Appointment Booking
Date: 01/10/2025
Time: Afternoon (not specified)


DETAIL INQUIRY WITH SIMPLE RESPONSE:

[01/09/2025, 2:17 PM] User: “What’s the cost of the premium plan?”
[01/09/2025, 2:18 PM] User: “What’s included?”
[01/09/2025, 2:19 PM] User: “Yes, sure.”

Output:
Detail Inquiry


ISOLATED MESSAGE WITH NO INTENT:

[01/09/2025, 3:45 PM] User: “Thanks.”

Output:

(No classification, as it does not fulfill a relevant intent.)

Ask:
How can I improve intent detection for short confirmations like “yes”?

Any advice would be amazing! :pray:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Bastian_Orth

I think it’s down to experimenting with maybe a few more examples and eventually trying out a better suited models.

You can pretty much work with any model that is compatible with the OpenAI API schema, like on OpenRouter or DeepSeek. And of course the Ollama models

Interesting work. I’m dealing with something similar. If I move forward I’ll let you know.

Hello,

I have been dealing with something similar, and this approach worked better for me:

When adding the prompt, add the conversation as part of the prompt. You can do this by using the “Get context” option in the “Chat memory manager” node and aggregating it with the “Aggregate” node. Later, in the prompt, add the context with an expression similar to this:

"{{ $('Aggregate').item.json["context"].map(m => `Human: ${m.human || 'undefined'} AI Assistant: ${m.ai || 'undefined'}`).join('') }}"

1 Like

Thanks! Will try this, thats a good idea.

Which model are you using?

I’m using gpt4o

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.