Optimize Prompts with n8n, LangChain AI & Telegram

This workflow improves vague user prompts by leveraging LangChain AI for clarity and detail enhancement, then sends the refined prompts back via Telegram, streamlining prompt optimization for better automation outcomes.
executeWorkflowTrigger
agent
telegram
+3
Workflow Identifier: 2184
NODES in Use: Execute Workflow Trigger, AI Agent, Telegram, OpenAI Chat Model, Code, Simple Memory
Optimize prompts with n8n and LangChain AI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow gets a prompt input and makes it clearer and detailed using AI.
It fixes unclear prompts so AI gives better results.
After improving the prompt, it breaks long text into smaller parts to send via Telegram.
Finally, it sends the improved prompt back to the user in Telegram.
The workflow also remembers past inputs a little to keep context.
This saves time and gives higher quality AI answers.


Who should use this workflow

Anyone who uses AI but faces problems with unclear prompts and wants better answers quickly.
It is great for content creators, writers, and automation users who want less editing.


Tools and services used

  • n8n Automation Platform: Runs automation workflows.
  • OpenAI API (GPT-4o mini): Improves prompts using AI.
  • LangChain AI Agent: Connects AI and n8n for prompt refinement.
  • Telegram Bot API: Sends and receives messages.
  • Simple Memory node: Keeps short conversation memory for AI context.

Inputs, processing steps, and output

Inputs

The workflow accepts prompt text
Either from another workflow or a Telegram message.

Processing Steps

  • Receive the raw prompt with Execute Workflow Trigger node.
  • Send the prompt to AI Agent node, which uses a special system message to improve clarity and detail.
  • OpenAI Chat Model node with GPT-4o mini runs the AI for prompt rewriting.
  • Simple Memory node connects to AI Agent to keep short context.
  • Split long AI output text in the Code node to fit Telegram limits.
  • Send the optimised prompt back with Telegram node.
  • Handle errors smoothly if Telegram has problems.

Output

User gets a clearer prompt text in Telegram
Split into parts if it is very long.


Beginner step-by-step: How to use the workflow in n8n

Step 1: Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. Go to the n8n editor, click on “Import from File”.
  3. Choose the downloaded workflow to add it.

Step 2: Configure credentials and details

  1. Add your OpenAI API Key in n8n credentials.
  2. Add your Telegram bot API Key in n8n credentials.
  3. Check if chat ID, email, channel, or other ID inputs need updating.
  4. If the Code node or AI Agent node has any custom prompts or code, just copy and paste them as they are.

Step 3: Test and activate

  1. Run the workflow once in n8n to verify outputs.
  2. If Telegram message sends successfully, activate the workflow.
  3. Now the workflow can be used inside other workflows or triggered as needed.

For users doing self-host n8n, make sure API and webhook access are set up properly.


Customizations and tips

  • You can choose a different GPT model for the OpenAI Chat Model node.
  • Modify the system message inside AI Agent node to change how prompts are improved.
  • Increase the buffer size in the Simple Memory node to keep longer chat history.
  • Add more output nodes like Slack or Email after the Code node to send prompts to other platforms.
  • Replace the Execute Workflow Trigger node with Telegram Trigger to start the flow from Telegram messages directly.

Edge cases and failure handling

  • If AI Agent gives vague output, check if the system message is correct.
  • If Telegram messages don’t send, look at the Code node that splits messages to keep length under limits.
  • If OpenAI Chat Model node throws errors, verify API Key settings.

Summary

✓ Clearer and detailed prompts from raw user input
✓ Chat memory boosts AI understanding
✓ Long messages split for Telegram delivery
✓ Saves time revising AI prompts
✓ Easy to use in many n8n automations


Optimize prompts with n8n and LangChain AI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes, users can select other GPT variants in the OpenAI Chat Model node depending on their API access and preferences.
A Code node splits long AI responses into smaller message chunks to fit Telegram’s character limits.
Users should verify that the system message for the AI Agent node matches the recommended text exactly.
Yes, the workflow can run on self-hosted n8n setups; users should ensure API and webhook configurations are correct.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.