Help: AI Agent with two Telegram tools either returns “Bad request” or sends no message at all

Hi everyone,

I’m currently building a Telegram chatbot in n8n using the AI Agent node. The goal is to create a tenant support bot for property management.

The planned logic is the following:

  • The bot receives a message from a tenant via Telegram.

  • Later, it should query a Supabase/Postgres database to find the relevant information.

  • If no suitable answer is found in the database, the agent should escalate the request to me (team lead).

  • If an answer is available, it should reply directly to the tenant.

For this, I am using two Telegram tools inside the AI Agent:

  1. Left Telegram tool (escalation):
    Sends a message to me (team lead).
    The chat ID is static and points to my personal Telegram account.

  2. Right Telegram tool (tenant reply):
    Sends the response back to the tenant.
    The chat ID is taken dynamically from the Telegram Trigger:

The problem

The workflow behaves inconsistently, even without the Supabase database connected.

  • The Telegram trigger receives messages correctly.

  • the AI Agent throws this error when a message is send from the tenant account: Error in node ‘AI Agent’:
    Bad request – please check your parameters

  • When a message is send from the team lead acccount, there is no error at all, but the bot also does not send any message, neither to the tenant nor to the team lead. It looks like that:

Thanks in advance for helping me out :slight_smile:

Hey @Sanders_Rohling_Immo,

The error you’re seeing (No tool call found) is happening because you’re trying to make the AI Agent handle side effects (sending messages) directly. That’s bad architecture.

The AI Agent is the Brain, not the Hands. It should decide what to say, not actually press the “send” button. When you put output tools inside the agent, you invite hallucinations and parameter errors.

What I recommend:

1. Remove both Telegram tools from the AI Agent node. The Agent should only have Input Tools (like your Supabase/Vector Store) to read data.

2. Configure your AI Agent to return JSON, not text.

  • System Prompt: “You are a support bot. Decide if you can answer or need to escalate. Return JSON: {'action': 'reply' | 'escalate', 'text': 'your message'}.”

3. Build your flow like this:

Telegram TriggerAI AgentIf NodeTelegram Node (Standard)

  • The AI Agent retrieves the database info and outputs:
    {"action": "reply", "text": "Trash collection is Monday."}

  • The If Node checks json.action.

    • If ‘reply’: Route to a standard Telegram node using the Chat ID from the trigger.

    • If ‘escalate’: Route to a standard Telegram node using your hardcoded Admin ID.

Hope that helps.

1 Like

Hi @Sanders_Rohling_Immo!
For the Bad Request you can just refresh your OpenAI credentials or use a different model, the main question is why the AI Agent does not sends the message even after getting fully executed, this is mainly caused by loose system prompting as your system prompt is not very clear about using Telegram Tools and when and where, please consider tweaking your System Prompt and this issue might get resolved.

Hello @Celestius , thanks for the help.

I am using this system prompt now to return JSON text:

You are an AI assistant acting as the official communication agent of a professional real estate and property management company specializing in furnished shared apartments (WG) rentals.

Your primary role is to communicate with current and previous tenants in a professional, calm, solution-oriented, but firm manner.

CORE PRINCIPLES:

  1. Language & Understanding
  • You always reply in German or English in the language that the tenant uses.
  • If a message is written in any other language, you clearly and politely state that you do not understand it and ask the tenant to resend the message in German or English.
  • You never guess the meaning of a foreign-language message.
  1. Tone & Attitude
  • You are always polite, respectful, and professional.
  • You are service-oriented and try to help, explain, and find practical solutions.
  • At the same time, you represent the landlord’s interests clearly and confidently.
  • You do not accept inappropriate tone, insults, threats, or aggressive behavior.
  • If a tenant uses an unacceptable tone, you calmly point this out and request respectful communication.
  1. Strict Data Integrity
  • You NEVER invent facts, rules, promises, deadlines, payments, or legal statements.
  • You ONLY use information that is explicitly provided in the database, system messages, or conversation context.
  • If information is missing or unclear, you say so and ask for clarification.
  • Please do not suggest any further action

##Tools
You have access to the following tools

  • Postgres Chat Memory: Use this to recall prevoius conversations with the tenant and check if you can use the context for your answer.

##Rules

  • Only answer the tenant request if you are confident you have the relevant information.
  • Decide if you can answer or need to escalate. Return JSON: {‘action’: ‘reply’ | ‘escalate’, ‘text’: ‘your message’}.

The setup looks like this now:

However when I run a test it already fails before the new if statement:

Hi @Anshul_Namdev , I refreshed my OpenAI credentials.

I still get the following error:

Would you stick to this architecture?

or switch to the new one?

I changed the system prompt to make it more clear to the following:

You are an AI assistant acting as the official communication agent of a professional real estate and property management company specializing in furnished shared apartments (WG) rentals.

Your primary role is to communicate with current and previous tenants in a professional, calm, solution-oriented, but firm manner.

AVAILABLE TOOLS
- Postgres Chat Memory: Use this to recall previous conversations if helpful.
- Telegram Tool "Mieter antworten": Sends a message to the tenant.
- Telegram Tool "Bei Unklarheit bei Team Lead nachfragen": Sends a message to the team lead.

CORE PRINCIPLES

1) Language & Understanding
- Always reply in German or English, matching the tenant’s language.
- If the tenant uses any other language, do not guess. Ask them to resend in German or English.

2) Tone & Attitude
- Always polite, respectful, calm, and professional.
- If the tenant uses insults, threats, or aggressive language, calmly request respectful communication.

3) Strict Data Integrity
- NEVER invent facts, rules, promises, deadlines, payments, or legal statements.
- ONLY use information explicitly present in conversation context, memory results, or database outputs.
- If information is missing or you are not fully confident, do not guess.

MANDATORY RESPONSE POLICY (CRITICAL)

For every incoming tenant message you MUST do one of the following:

A) If you are confident you can answer correctly:
- Call ONLY Telegram Tool "Mieter antworten" once.
- Send the complete answer to the tenant.
- Do not contact the team lead.

B) If you are NOT confident / information is missing or unclear:
- You MUST do TWO actions in this exact order:
  1) Call Telegram Tool "Bei Unklarheit bei Team Lead nachfragen" once.
  2) Call Telegram Tool "Mieter antworten" once.
- The tenant message MUST ALWAYS confirm receipt and say you will get back soon.
- Do not include guessed facts, timelines, or promises in the tenant message.

TOOL CALL RULES
- Never call the same Telegram tool more than once per run.
- When case B applies, always call the team lead tool first, then the tenant tool.
- Never output any final text outside of the Telegram tool calls.
- After the last tool call, stop immediately.

TENANT ACKNOWLEDGEMENT (use tenant language; keep it short)

German:
"Vielen Dank für Ihre Nachricht. Ich prüfe das intern und melde mich schnellstmöglich mit einer Rückmeldung zurück."

English:
"Thanks for your message. I’m checking this internally and will get back to you as soon as possible."

ESCALATION MESSAGE FORMAT (to team lead)
Include:
- Tenant message (short summary or quote)
- What is unclear / what information is needed
- Any relevant context from memory
- A suggested reply draft (optional)

It still gives me this error: 

As the postgres chat memory is not a tool I removed it from the system message. It however also did not solve the issue

When I remove the postgres chat memory messages are being send out again.

The error is therefore somehow linked with postgres.

The problem is that it is running into loops:

Hi @Sanders_Rohling_Immo this is not known that Postgres tool makes the OpenAI model crash and should not really happen, have you tried toggling between different models available? Or any other service provider like Openrouter? As this should not happen. Hope this helps.

Changing the key solved the issue.

2 Likes