# Set up Twigg in n8n This guide is for an AI assistant helping someone add Twigg to an n8n workflow. The person is usually not an engineer: they run an AI chatbot in n8n (WhatsApp, Telegram, website chat, support or lead qualification) and want it to remember conversations without setting up a database. ## How to guide them - Go one step at a time. Give one instruction, wait for them to confirm it worked, then give the next. - Use the exact button and field names below, in bold, because they will look for those words on screen. - Ask before assuming: which trigger their bot uses, whether they are on n8n Cloud or self-hosted, and whether the bot already has conversations stored somewhere. - Never ask them to paste their API key into the chat with you. It goes only into n8n's credential form. - If something fails, use **Troubleshooting** at the end before guessing. ## What Twigg does Twigg keeps each conversation on its servers. The **Twigg** node, on its **Agent** resource (the default), replaces n8n's AI Agent, Chat Model and Memory nodes in one: it picks the model, stores the conversation, keeps it short enough for the model to read, and fixes broken tool calls on the next message. The conversation survives n8n restarts, updates and queue mode. The person needs no database, no Memory node and no tables. Storing conversations on Twigg is free. They pay for the model's replies from a prepaid balance. ## Step 1: Create an account and add credit 1. Go to https://twigg.ai/login and sign up. 2. Open **Billing** (https://twigg.ai/dashboard/billing), add a card, and choose **Add funds**. A small amount is enough to start. 3. Recommend turning on **Auto top-up** on the same page, with a threshold and an amount. Without it, the bot stops replying when the balance reaches zero. Without credit, every message fails with `payment_required`. ## Step 2: Create an API key 1. Open **API keys** (https://twigg.ai/dashboard/api-keys) and choose **Create key**. 2. Tell them to copy it straight away: it is shown once. 3. In n8n, open **Credentials**, create a new **Twigg API** credential, paste the key into it and save. The connection test should pass. Leave the credential's base URL at `https://api.twigg.ai`. ## Step 3: Install the node and put it in the workflow ### Install Twigg is a verified n8n community node, so it installs from the nodes panel on both n8n Cloud and self-hosted n8n. Only an **owner** or **admin** account can install it; once installed, everyone on that n8n can use it. 1. Open a workflow and open the nodes panel with **+** (or press N). 2. Search for **Twigg**. It appears under **More from the community** at the bottom of the panel. 3. Select it and choose **Install**. If it does not appear: - **n8n Cloud:** the owner checks that **Verified community nodes** is turned on under **Instance settings** in the n8n Cloud admin panel. - **Self-hosted n8n:** verified nodes may be turned off on that instance. Install it by name instead: **Settings → Community nodes → Install**, enter `@twigg/n8n-nodes-twigg`, and confirm. This needs n8n 2.16 or later. ### Replace the old agent In their workflow: 1. Add a **Twigg** node next to their current AI Agent. It opens on the **Agent** resource; leave it there. 2. Connect the same trigger to its input, and the same output nodes (the reply) to its output. 3. Move each tool from the old agent to the Twigg node's **Tool** input. 4. Set **Model Name or ID** from the list. Any model works, and it can be changed later without losing history. 5. Copy the old agent's system prompt into **System Message**. 6. Set **Prompt (User Message)** to the incoming message. The default, `{{ $json.chatInput }}`, is right for a Chat Trigger. For Telegram it is usually `{{ $json.message.text }}`. 7. Set **Chat ID** (below). 8. Delete the old AI Agent, its Chat Model and its Memory node. The Twigg node puts its reply in the same `output` field as n8n's AI Agent, so nodes after it keep working unchanged. ### Chat ID The Chat ID is what tells one conversation from another. Each different value is its own conversation. | Trigger | Chat ID | |---|---| | Chat Trigger | `{{ $json.sessionId }}` (the default; leave it) | | Telegram Trigger | `{{ $json.message.chat.id }}` | | WhatsApp or another messaging app | The sender's phone number or user id from the trigger's output | | They used a Memory node before | Whatever that Memory node used as its session key | If you are unsure which field holds the sender's id, ask them to run the trigger once and read its output panel with you. If the Chat ID is a phone number, suggest turning on **Options → Hash Chat ID** so the raw number is not sent to Twigg. ### Test it Ask them to send the bot two messages, the second one referring to the first ("My name is Sam", then "What's my name?"). If it answers correctly, memory is working. ## If the bot already has stored conversations Only applies if their old agent used a Memory node that stores to a database (Postgres, Redis, MongoDB and so on). Simple Memory keeps nothing, so there is nothing to move. **Gradually (simplest):** in the Twigg node (Agent) turn on **Use External Memory**. An **External Memory** input appears. Connect their *existing* Memory node to it: the same node, with the same name, moved across rather than recreated, because n8n stores Chat Trigger sessions under the node's name. Each conversation then moves to Twigg the first time that person messages again. The old memory is only read, never changed. **All at once:** add a **Twigg** node with **Chat → Import All**, feed it one item per session, and run it. Running it again is safe: chats already moved are skipped. When it reports every chat is moved, turn **Use External Memory** off and remove the Memory node. Importing costs a one-off $0.25 per million tokens. Conversations longer than 500 messages keep their newest 500. ## Optional - **Keep n8n's own AI Agent.** Instead of the Twigg node's agent, connect a **Twigg Chat Model** to n8n's AI Agent's **Chat Model** input and delete the Memory node. Set its Chat ID the same way. - **Let users start over.** Add a **Twigg** node with **Chat → Delete** and the same Chat ID, for example when the message is `/reset`. - **Keep costs down on long chats.** In the Twigg console's **Configuration** page, give the `n8n` namespace a context budget. Older messages are then summarised and old tool results trimmed, so long conversations cost less per message. Without a budget, Twigg only compacts when a chat nears the model's context limit. To set this from a terminal instead, see **Context settings with the Twigg CLI** below. - **Cap replies.** **Options → Maximum Number of Tokens** limits reply length, and **Options → Max Iterations** limits tool rounds per message (default 10). - **Example workflows:** https://github.com/Twigg-AI-Ltd/n8n-nodes-twigg/tree/main/examples has a Telegram bot, a website support bot and a WhatsApp lead qualifier, ready to import with **Workflows → Import from File**. ## Context settings with the Twigg CLI If they want to change how their chats are handled (context budgets, how older messages are summarised, retention) and you can run commands on their machine, the Twigg CLI, `@twigg/cli`, does it as a config file instead of console clicks. The node creates chats in the `n8n` namespace unless its **Namespace** field says otherwise, so pass that namespace as `--scope` and nothing else in their account is touched: ```bash npm install --save-dev @twigg/cli npx twigg config pull --scope n8n # writes twigg.config.yaml from what is set today npx twigg config plan --scope n8n # shows what would change npx twigg config apply --scope n8n # asks, then applies ``` It reads the API key from `TWIGG_API_KEY`. Ask them to set that in their own terminal; as above, never ask for the key itself. Edit the `n8n` entry under `namespaces`, show them the plan, and apply only once they agree. The file format, budgets and retention are in https://twigg.ai/docs/context.md, and the CLI's commands in https://twigg.ai/docs/sdks.md#cli. If you can't run commands for them, the same settings are on the console's **Configuration** page. ## Troubleshooting | What they see | What to do | |---|---| | `payment_required` | The balance is empty. Add funds in **Billing**, and turn on **Auto top-up**. | | The credential test fails | The key was copied wrong or revoked. Create a new key and paste it again. | | The bot forgets between messages | The Chat ID changes every message, or is empty. Check it against the table above. | | A warning about replayed history | A Memory node is still attached. Delete it, or connect it to **External Memory** only if they are importing. | | `external_id_namespace_mismatch` | That Chat ID already exists in another namespace. Clear the **Namespace** field, or use a different Chat ID. | | `validation_error` mentioning a tool | One of the tools has a schema the chosen model cannot take. Try another model, or remove that tool to find which one. | | Can't find the node in the nodes panel | Search for **Twigg** and scroll to **More from the community**. If it is not there, see **Install** above: on Cloud, **Verified community nodes** must be on; on self-hosted, install it by name. | | No **Install** button | Only an owner or admin can install community nodes. Ask them to install it once; then everyone can use it. | | An old workflow has a "Twigg AI Agent" node that no longer loads | That node became the **Agent** resource of the **Twigg** node in version 0.2.0. Replace it with a **Twigg** node on **Agent**, with the same settings and connections. | More detail on every node option: https://github.com/Twigg-AI-Ltd/n8n-nodes-twigg#readme