Skip to main content

Build an AI Agent

  • Time: Under 10 minutes
  • What you'll build: An AI agent that connects to an LLM, uses tools, and responds to user queries in chat.

An AI agent uses an LLM to understand user queries, reason about them, and call tools to retrieve information or perform actions. This quick start walks you through the full process: creating a project, adding an AI Chat Agent artifact, configuring its instructions, and testing the agent in the built-in chat panel.

Prerequisites​

A working WSO2 Integrator environment.

Step 1: Create the integration​

Note

If you're using the cloud editor, a project is already open, so you can skip this step 1 and go directly to Step 2: Add an AI chat agent.

  1. Open WSO2 Integrator.

  2. Click Create in the Create a Project card.

    WSO2 Integrator home screen with the Create a Project card

  3. Set Project Name to QuickStart.

  4. Set Integration Name to AIAgent.

  5. Click Create.

    Create a Project form with Project name set to QuickStart and Integration name set to AIAgent

Step 2: Add an AI chat agent​

  1. Select your integration from the project overview canvas.

  2. In the design view, click Add Artifact Manually.

    Integration design view with the Add Artifact manually button highlighted

  3. Select Chat Agent Service under AI Integration.

    Artifacts page with Chat Agent Service highlighted under AI Integration

  4. The Create Chat Agent Service form opens.

  5. Set Role to Wso2IntegratorAssistant.

  6. 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 in

  7. Leave the remaining configuration fields at their default values.

  8. Under Advanced Configurations, set Agent Name to Wso2IntegratorAssistant.

  9. Click Create.

    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 from the Chat Agent Service title bar or click Test from the pop-up.

  3. Type Hello to check if it works.

    Chat Agent Service running with the chat panel showing a reply to Hello

Step 4: Deploy to WSO2 Cloud​

Deploy your integration to WSO2 Cloud - Integration Platform in any of the following ways:

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 the following complete, runnable Ballerina program. It has 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};
}
}

What's next​

Was this page helpful?