Build an AI Agent
An AI agent uses an LLM to reason about user queries and call tools to retrieve information or perform actions. This quick start shows the full cycle: create a project, add an AI Chat Agent artifact, configure its instructions, and test it in the built-in chat panel.
Prerequisites
A working WSO2 Integrator environment.
WSO2 Cloud setupSign up and launch WSO2 Integrator in the browser-based cloud editor.
Architecture
Step 1: Create the integration
In the cloud editor, you're already inside a project. Skip to Step 2.
- Open WSO2 Integrator.
- Select Create in the Create New Integration card.
- Set Integration Name to
AIAgent. - Set Project Name to
QuickStart. - Select Create Integration.


Step 2: Add an AI chat agent
- Select your integration from the project overview canvas.
- Select + Add Artifact in the design canvas.
- Select AI Chat Agent under AI Integration.
- Set Name to
Wso2IntegratorAssistant. - Select Create.


Step 3: Configure the AI agent
- Select the Wso2IntegratorAssistant node on the canvas.
- Set Instructions to
You are a highly skilled WSO2 Integration Architect. Your goal is to assist developers in building, debugging, and optimizing integration flows.. - Select Save.


By default, the agent is configured to use the WSO2 model provider. If you want to use a different LLM, see Model providers for the full list of supported providers (OpenAI, Azure OpenAI, Anthropic, and others).
If you are using the WSO2 model provider, the access token is obtained through WSO2 Integrator Copilot. If you have not already signed in, you will be prompted to do so.
Step 4: Run and test
- Select Run.
- Select Chat from the AI Chat Agent title bar or select Test from the pop-up.
- Type
Helloto check if it works.


Step 5: Deploy to WSO2 Cloud
Deploy your integration to WSO2 Cloud. Check Save and deploy.
Source code
View the generated Ballerina code
The steps above generate two files: agents.bal for the agent definition and main.bal for the listener and service.
agents.bal
import ballerina/ai;
final ai:Agent wso2IntegratorAssistantAgent = check new (
systemPrompt = {
role: string `Wso2IntegratorAssistant`,
instructions: string `You are a highly skilled WSO2 Integration Architect. Your goal is to assist developers in building, debugging, and optimizing integration flows.`
},
model = wso2ModelProvider,
tools = []
);
main.bal
import ballerina/ai;
import ballerina/http;
listener ai:Listener chatAgentListener = new (listenOn = check http:getDefaultListener());
service /wso2IntegratorAssistant on chatAgentListener {
resource function post chat(@http:Payload ai:ChatReqMessage request) returns ai:ChatRespMessage|error {
string stringResult = check wso2IntegratorAssistantAgent.run(request.message, request.sessionId);
return {message: stringResult};
}
}