Self-Learning AI Agent
The Self‑Learning AI Agent improves automatically by learning from conversations resolved by human agents. When the bot cannot answer, the chat is seamlessly handed over to a human. Once the operator closes the request, an automated process analyzes the conversation, extracts useful knowledge, generates a new article, and adds it to your Knowledge Base so the bot can respond to similar questions in the future.
How the Self-Learning Flow Works
1. The AI Agent as First Responder
When a user sends a message, the AI Agent attempts to respond based on its knowledge base.
2. Escalation to a Human
If the AI cannot answer, the conversation is seamlessly transferred to a human operator.
3. Learning from Resolved Conversations
Analyzes the resolved conversation
Extracts relevant information
Generates new content
Automatically adds this content to the AI’s knowledge base
4. Continuous Improvement
The next time a similar question is asked, the AI Agent is able to respond without human intervention. It’s like having an AI that learns from every support case — automatically.
How to Get Started
The Self‑Learning AI Agent uses Code Action to interact with secure endpoints and update your Knowledge Base. Code Action enables server-side execution with authentication.
You have two ways to implement the Self-Learning flow:
Option A — Use the prebuilt template (fastest) You can download the ready-to-use Self‑Learning Flow template from the community and import it into your project. All necessary Code Action configurations are already included, so you don’t need Enterprise access to use it.

Option B — Build the flow from scratch If you prefer to customize or build the flow manually in Design Studio, Code Action must be activated — and this is only available under the Enterprise plan. If Code Action is not enabled in your workspace, contact us and we’ll activate it for you.
Self-Learning AI Agent – Build the Flow from Scratch
To build the Self-Learning AI Agent flow from scratch, you need to have a project under the Enterprise plan with Code Action enabled. This tutorial walks you through every step in detail to create the learning loop inside Tiledesk Design Studio.
Step 1: Create a New Flow
1. From the Tiledesk dashboard, go to the left-side menu and click on “Flows”. 2. On the new page, click the blue “New Flow” button at the top right. 3. Choose “Automation”, then select “Webhook” and give it a name (e.g., Self Learning Flow). 4. You’ll be redirected to the Design Studio.

Step 2: Add the Code Action
1. Hover over the “Special” actions and choose “Code Action”. 2. Click on the Code Action block. A right-side menu will appear. 3. Replace the default code with the following snippet, and optionally rename the block to “create_transcript”.


Here is the code you should use:
let payload = context.attributes["payload"];
let messages = payload?.payload?.messages;
messages?.shift();
let transcript = "";
messages?.forEach(message => {
// only unuseful messages have subtype
const subtype = message?.attributes?.subtype;
// only chatbots
const intentName = message?.attributes?.intentName;
// only end-users
// const requester_id = message?.attributes?.requester_id;
// only service messages
const messagelabel = message?.attributes?.messagelabel;
// human only messages
if (!subtype && !messagelabel && !intentName) {
//console.log("message:", message);
let text = message.senderFullname + ": " + message.text;
transcript += text + "\n";
}
});
context.setAttribute("transcript", transcript);
What it does: - Gets chat messages from the payload. - Filters out system messages, bot responses, and service messages. - Keeps only genuine human-to-human conversations. - Formats each message as “SenderName: MessageText”. - Creates a single transcript string stored as “transcript” in context. Why: The filtered transcript provides clean human conversation data without technical noise, making it ideal for training a self-learning AI agent on natural dialogue patterns.
Step 3: Add a Flow Log
1. Hover again on “Special” and select “Flow Log”. 2. Place it after the Code Action block and write “self learning start” in the log section.

Step 4: Add the ChatGPT Task
1. Add a new block and insert the “ChatGPT Task” from the action types.

2. Write a prompt that analyzes a support transcript and extracts reusable content. Use the following prompt: The transcript below is a support conversation where a user asks for a solution of a problem and someone replies providing the requested solution. If you evaluate that a solution was found, the solution was generic enough to be useful for other users - no user-specific solution regarding his personal account or the provisioning of sensible data are considered useful for someone else - please fillout the summary field of the json with a summary of the solution removing all sensible data. Otherwise set the summary field to null. Reply to me with this json: { "title":"a short title for this content", "summary": the summary you found out following the above instructions } conversation transcript: {{transcript}}
3. This prompt evaluates whether the conversation includes a reusable solution, excludes sensitive/user-specific info, and returns a JSON structure with a title and summary.

Step 5: Extract the Summary
1. Add a new block with the “Set Attributes” action from the “Flow” actions. 2. Use the value {{gpt_reply.summary}}. 3. Create a new attribute named “Summary”. This will store the AI-generated summary in a usable form.

Step 6: Add a Condition to Check Summary Validity
1. Add a “Condition w/else” block from “Flow” actions. 2. Configure the condition to check if Summary is Null, Undefined, or Empty. If it matches any of these, it means the summary is not usable.


Step 7: Handle Unusable Summaries
1. From the green end of the condition block (if invalid), add a new “Flow Log” action. 2. Write “discarded” in the log field.

3. Add a “Web Response” block to conclude the flow.

Step 8: Check If Content Already Exists
1. From the red end of the condition block (if summary is valid), add an “Ask Knowledge Base” action. 2. Use the Summary attribute in the “Use question” field. 3. Select the target Knowledge Base.

4. If found (green end), redirect back to the “discarded” log. 5. If not found (red end), continue to add the content.

Step 9: Add Content to the Knowledge Base
1. From the red end of the “Ask Knowledge Base”, add an “Add to Knowledge Base” action.

2. Set {{gpt_reply.title}} as the Question. 3. Set {{gpt_reply.summary}} as the Answer. 4. Choose the appropriate Knowledge Base for the content.
Step 10: Log the Action
1. Add another “Flow Log” action to mark the new entry. 2. Fill it with a meaningful message (e.g., “article added to KB”). 3. Click the blue "Publish" button in the top right corner.

Step 11: Register the Webhook to Trigger the Flow
After building the flow, you need to connect it to the “Request Close” event. This ensures the flow is executed automatically every time a human agent closes a support conversation.
Follow these steps to set up the webhook:
1- Click on the starting “Webhook” block at the top of the flow.
2- On the right-hand panel, locate the field labeled Production URL.
3- Copy the Production URL. You’ll need it in the next steps.

Register the Webhook in Tiledesk Dashboard
1- Go back to the Tiledesk dashboard.
2- From the left-side menu, click on Settings, then go to Project Settings.
3- Select the Developer tab at the top of the page.
4- Click the Manage Webhooks button (blue).

Create a New Subscription
1- Click the Add Subscription button.
2- Under Select Event, choose “Request Close” from the dropdown menu.
3- Paste the Production URL (copied earlier) into the Webhook URL field.
4- Click the Create Subscription button to finalize.

Once saved, your self-learning flow will now automatically be triggered each time a support request is closed — activating the entire learning process without manual intervention.
How to Test It
Ask a question your AI Agent doesn’t know.
Let the conversation escalate to a human agent.
Have the human respond and close the conversation.
Wait a few moments for the self-learning flow to activate.
If successful, new content will be added to your KB.


Need help transferring knowledge to your AI Agent?
If your support center handles a large volume of tickets and you’re unsure how to extract and structure that knowledge for your AI Agent, we’re here to help.
Our team can assist you in:
Analyzing historical conversations
Identifying reusable knowledge
Structuring and importing it into your Knowledge Base
Optimizing your AI Agent for autonomous responses
Contact us to get expert support and unlock the full potential of your self-learning AI Agent.
Last updated