Skip to main content

Build an AI Agent

TimeUnder 10 minutes
What you'll buildAn AI agent that connects to an LLM, uses tools, and responds to user queries in chat.

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.

Step 1: Create the integration​

  1. On the project home page, click Create on Cloud.

    WSO2 Cloud project home showing the Create on Cloud optionWSO2 Cloud project home showing the Create on Cloud option
  2. The WSO2 Integrator cloud editor opens in your browser.

    WSO2 Integrator cloud editor landing page showing an empty integration and the Deploy to WSO2 Cloud panelWSO2 Integrator cloud editor landing page showing an empty integration and the Deploy to WSO2 Cloud panel
Note

The cloud editor creates a default integration for you, so you don't need to name it now. You can change its name when you deploy it. For more information, see Save and deploy.

Step 2: Add an AI chat agent​

  1. In the design view, click Add Artifact manually.

    Integration design view with the Add Artifact manually button highlightedIntegration design view with the Add Artifact manually button highlighted
  2. Select Chat Agent Service under AI Integration.

    Artifacts page with Chat Agent Service highlighted under AI IntegrationArtifacts page with Chat Agent Service highlighted under AI Integration
  3. The Create Chat Agent Service form opens. Set Role to Wso2IntegratorAssistant.

  4. Set Instructions to:

    You are a highly skilled WSO2 Integration Architect. Your goal is to assist developers in building, debugging, and optimizing integration flows.
    Create Chat Agent Service form with Role and Instructions filled inCreate Chat Agent Service form with Role and Instructions filled in
  5. Leave the remaining configuration fields at their default values.

  6. Scroll down to Advanced Configurations at the bottom of the form, and set Agent Name to Wso2IntegratorAssistant.

  7. Click Create.

    Bottom of the Create Chat Agent Service form with Agent Name set to Wso2IntegratorAssistantBottom of the Create Chat Agent Service form with Agent Name set to Wso2IntegratorAssistant
Default model provider

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 3: Run and test​

  1. Click Run.

  2. Click Chat in the Chat Agent Service title bar, or click Test in the pop-up.

  3. Type Hello to check that the agent replies.

    The built-in chat panel with a Hello message sent to the running agentThe built-in chat panel with a Hello message sent to the running agent

Step 4: Deploy to WSO2 Cloud​

To deploy your integration to WSO2 Cloud from the cloud editor, see Save and deploy.

Skip ahead: deploy a ready-made sample

Rather not build it yourself? One-click deploy the AIAgent sample straight to WSO2 Cloud.

Deploy to WSO2 Cloud

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};
}
}