Jul 23, 2025

Build an SMS AI Agent with Human-in-the-Loop Support

Download the step-by-step guide or follow instructions below

You don’t need to be a developer to build a powerful AI agent that can handle SMS conversations and know when to ask for help. In this guide, we’ll show you how to:

✅ Build an SMS AI agent using n8n and Twilio
✅ Add Poku's human-in-the-loop tools (via our MCP server) so your agent can:

  • 🟡 Flag conversations for human review

  • 🟢 Ask a human for help in real time

Step 1: Set Up Your Prerequisites

  • A Twilio number (A2P 10DLC registered)

  • Your Twilio SID and Auth Token

  • A free Poku account

  • An n8n account with OpenAI or another LLM connected

Step 2: Build the Flow in n8n

  1. Twilio Trigger: Start your scenario with a trigger for new inbound SMS.

  2. Poku Node (HTTP Request): POST to https://api.pokulabs.com/chats/inbound with the message body and metadata. This enables Poku to identify and track the conversation.

  3. Filter: Check if the agent is in "human intervention mode"—if so, stop the automation here. Check {{json.isDisabled}} is not equal to true.

  4. AI Agent: Pass the inbound SMS into your LLM. Use message history keys like {{json.data.to}}{{json.data.from}} to enable the agent to use the MCP tools.

  5. Add MCP Tools: Configure your agent to add a MCP Client Connection
    Server URL (Streamable): https://mcp.pokulabs.com
    Server URL (SSE): https://mcp.pokulabs.com/sse
    Headers: Authorization: Bearer YOUR_POKU_KEY

    Select the following tools

    • flag_chat: to mark a conversation for human review in the Poku dashboard.

    • contact_human: to escalate to a human when the agent gets stuck.

Step 3: Prompt Your Agent to Use the Tools with Your Criteria

Add logic to your system prompt, for example:

1. If user mentions an existing appointment, use flag_chat.
2. If the user asks for a discount, use contact_human to escalate.
3. If the user asks to speak with a human, use contact_human

Step 4: Configure Escalation on Poku

In the Poku dashboard, configure who your agent should notify when contact_human is triggered.

Step 5: Send the AI’s Response

Use a final Twilio SMS node in n8n to send the AI-generated reply back to the user.

Got questions? Reach out to us at hello@pokulabs.com or schedule a call with us here.
Happy building! 🛠️