Skip to main content
Version: 5.1

Building an IT Helpdesk AI Agent with Persistent Memory

What you will build​

In this tutorial, you will build an IT helpdesk AI agent that assists employees with technical support issues and remembers conversations across service restarts using persistent MSSQL-backed memory.

The AI agent exposes a chat interface using ai:Listener, responds to employee questions, searches an internal knowledge base for troubleshooting guidance, and maintains conversation history using ballerinax/ai.memory.mssql.

By persisting chat history using a database-backed memory store, employees can continue conversations using the same session ID without repeating previously shared information, even after the integration service restarts.

What you will learn​

In this tutorial, you will learn how to:

  • Create an AI agent using the Chat Agent Service artifact
  • Expose the agent through ai:Listener
  • Persist conversation history across service restarts using MSSQL-backed memory
  • Maintain employee-specific conversations using a session ID

Prerequisites​

Before getting started, ensure that the following requirements are met:

  • Install the WSO2 Integrator
  • Have an MSSQL database reachable (host, port, user, password) for agent memory persistence. Have the chat messages table (and, if you plan to use human-in-the-loop, the checkpoint table) created ahead of time. See Memory for the required schemas.
  • Have a basic understanding of memory configuration concepts. For more information, refer to Memory

Architecture​

Build the integration​

In this section, you will create the integration project and configure the AI agent for the IT helpdesk system.

Step 1: Create the integration project​

Create a new integration project by following the instructions in Create a project.

Step 2: Define the data type​

Define the following data type.

# types.bal
type KbArticle record {|
string articleId;
string title;
string content;
string category;
string[] tags;
float relevanceScore;
|};

Initialize the kbArticles.

final KbArticle[] & readonly kbArticles = [
{
articleId: "KB-101",
title: "VPN Troubleshooting",
content: "Restart the VPN client and reconnect.",
category: "network",
tags: ["vpn"],
relevanceScore: 0.95
},
{
articleId: "KB-102",
title: "Password Reset",
content: "Use the self-service password reset portal.",
category: "account",
tags: ["password"],
relevanceScore: 0.9
}
];

The tool you add in Step 4 searches kbArticles by matching tags against the employee's query, and returns the content of the highest-relevanceScore match.

Step 3: Create and configure the agent​

  1. Open WSO2 Integrator, create or select your project.
  2. On the Design tab, select Add Artifact manually (below the WSO2 Integrator Copilot's quick-start cards).
  3. On the Artifacts page, under AI Integration, select Chat Agent Service.
Artifacts page with Chat Agent Service highlighted under AI Integration, alongside Durable Agentic Workflow and MCP ServiceArtifacts page with Chat Agent Service highlighted under AI Integration, alongside Durable Agentic Workflow and MCP Service
  1. On the Create Chat Agent Service form, set:
    • Role to itHelpDesk.
    • Instructions to:
You are an IT Helpdesk Assistant.

Rules:
- ALWAYS call searchKnowledgeBase first.
- ONLY use information returned by tools.
- Do NOT generate additional troubleshooting steps.
- Keep responses short.
- Remember previous conversations.
  • Model as Default WSO2 Model Provider.
  • Leave Maximum Iterations at its default (INFER_TOOL_COUNT).
Create Chat Agent Service form with Role set to itHelpDesk, Instructions filled in, Model set to Default WSO2 Model Provider, and Maximum Iterations defaulting to INFER_TOOL_COUNTCreate Chat Agent Service form with Role set to itHelpDesk, Instructions filled in, Model set to Default WSO2 Model Provider, and Maximum Iterations defaulting to INFER_TOOL_COUNT
  1. Leave Verbose, Tool Loading Strategy, and Execute Tool Calls In Parallel at their defaults.
  2. Set Agent Name to itHelpDeskAgent.
  3. Set Service Base Path to expose the chat service, for example /it-helpdesk.
  4. Select Create.
Bottom of the Create Chat Agent Service form with Agent Name set to itHelpDeskAgent and Service Base Path set to /it-helpdeskBottom of the Create Chat Agent Service form with Agent Name set to itHelpDeskAgent and Service Base Path set to /it-helpdesk

This creates an AI Agent Service with a POST /chat resource and a chatAgentListener, plus the itHelpDeskAgent agent under Agents. Select itHelpDeskAgent under Agents to open its canvas: the AI Agent node is connected to the model provider, with a + Add Memory button and a + icon at its bottom-right corner for adding tools.

AI Agent node for itHelpDeskAgent connected to the model provider, with an Add Memory button and a + icon for adding toolsAI Agent node for itHelpDeskAgent connected to the model provider, with an Add Memory button and a + icon for adding tools

Step 4: Add a tool to the agent​

  1. Select the + at the bottom-right corner of the AI Agent node. The Add Tool panel opens, listing Use Connection, Use Function, Use Agent, Use MCP Server, and Create Custom Tool. Select Create Custom Tool.
Add Tool panel listing Use Connection, Use Function, Use Agent, Use MCP Server, and Create Custom Tool (highlighted), each with a short descriptionAdd Tool panel listing Use Connection, Use Function, Use Agent, Use MCP Server, and Create Custom Tool (highlighted), each with a short description
  1. Set:
    • Name to searchKnowledgeBase.
    • A parameter of Type string and Name query.
    • Return Type to string.
  2. Leave Requires Approval unchecked and select Create Tool.
Add Tool - Create Custom Tool form with Name searchKnowledgeBase, a string query parameter, and Return Type stringAdd Tool - Create Custom Tool form with Name searchKnowledgeBase, a string query parameter, and Return Type string
  1. The tool now shows as a node connected to the agent. Select it to open its flow, and build the logic shown below: normalize the query, declare a bestMatch variable, loop over kbArticles and their tags to find the highest-relevanceScore match, then return its content, or fall back to a "no matching article" return.
Agent Tool searchKnowledgeBase flow: declaring normalizedQuery and bestMatch, looping over kbArticles and their tags to update bestMatch, then returning bestMatch.content or a fallback messageAgent Tool searchKnowledgeBase flow: declaring normalizedQuery and bestMatch, looping over kbArticles and their tags to update bestMatch, then returning bestMatch.content or a fallback message

This searches the kbArticles array you defined in Step 2 by matching tags against the query, so adding a new topic is a matter of adding a KbArticle entry rather than editing the tool's logic.

note

New tools open with a placeholder panic error("not implemented") statement after the last node you add. It becomes unreachable once your final Return is in place, so it's safe to leave it or delete it from the pro-code view. Either way, it doesn't affect the build.

Step 5: Add persistent memory to the agent​

  1. Select + Add Memory on the AI Agent node. The Configure Memory panel opens with Select Memory set to Short Term Memory and Store defaulting to In-Memory Short Term Memory Store.
Configure Memory panel with Select Memory set to Short Term Memory and no memory store created yetConfigure Memory panel with Select Memory set to Short Term Memory and no memory store created yet
  1. Select + Create New Memory Store, then pick the MS SQL-backed store. Bind MS SQL Client to your database connection details using configurable values for host, user, password, database, and port (see the Ballerina Code tab for the corresponding config.bal declarations). Leave Max Messages Per Key, Cache Config, and Table Name at their defaults (the table name defaults to ChatMessages). Creating this table ahead of time is a prerequisite.
Create Memory Store panel with MS SQL Client bound to configurable host, user, password, database, and port valuesCreate Memory Store panel with MS SQL Client bound to configurable host, user, password, database, and port values
  1. Leave Memory Store Name at its default (for example mssqlShorttermmemorystore). Result Type is fixed to mssql:ShortTermMemoryStore. Select Save.
Bottom of the Create Memory Store panel with Memory Store Name set and Result Type locked to mssql:ShortTermMemoryStoreBottom of the Create Memory Store panel with Memory Store Name set and Result Type locked to mssql:ShortTermMemoryStore
  1. Back in the Configure Memory panel, the new store is selected under Store. Leave Memory Name at its default (for example aiShorttermmemory) and select Save.
Configure Memory panel with Store set to the newly created mssqlShorttermmemorystore and the AI Agent canvas showing a Memory node attachedConfigure Memory panel with Store set to the newly created mssqlShorttermmemorystore and the AI Agent canvas showing a Memory node attached

The AI Agent node now shows a Memory sub-node (ShortTermMemory) alongside its connection to the model provider and the searchKnowledgeBase tool.

Step 6: Run and test the integration​

  1. Select Run. WSO2 Integrator applies the --experimental flag and compiles and starts the service, with progress shown in the integrated terminal.
  2. Open the chat resource and select Chat in the toolbar (next to Tracing) to open the Agent Chat panel. Try the conversation below to exercise the tool and confirm the agent remembers earlier turns in the same session:
  • "My VPN is not working"
  • "I already restarted it"
  • "Any other suggestions?"
Chat Agent Service resource flow alongside the Agent Chat panel showing the VPN troubleshooting conversationChat Agent Service resource flow alongside the Agent Chat panel showing the VPN troubleshooting conversation
  1. To prove memory survives a service restart, you need the session ID the Chat panel is using. Select the ⓘ icon at the top-left of the Agent Chat panel. It shows the Session ID and Chat Endpoint for the current conversation.
Agent Chat panel's info popover showing Session ID (redacted) and Chat EndpointAgent Chat panel's info popover showing Session ID (redacted) and Chat Endpoint
  1. Stop the service, then select Run again to restart it. Once it's back up, send a request with the same session ID. Use either the one you copied from the info popover, or a session ID of your own choosing used consistently across requests. See the Ballerina Code tab for a full curl walkthrough using EMP-1001:
curl -X POST http://localhost:9090/it-helpdesk/chat \
-H "Content-Type: application/json" \
-d '{"sessionId": "<your session ID>", "message": "Do you remember my issue?"}'
Terminal showing the service restarting, then a curl request with a redacted session ID whose response confirms the agent still remembers the VPN issueTerminal showing the service restarting, then a curl request with a redacted session ID whose response confirms the agent still remembers the VPN issue

The response confirms the agent remembers the VPN issue and that you'd already restarted the client. This proves the conversation history survived the restart because it's persisted in MSSQL, not held in process memory.

The AI agent remembers previous conversations because the conversation history is stored in persistent MSSQL-backed memory and retrieved using the same session ID.