Skip to main content

Build an AI Agent

Cloud has the newest features. Some may not be in a release yet; the newest release is Integration 5.1.0.
  • 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 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 Choreo Integrator environment.

  • Choreo Cloud setup: Sign up and launch Choreo Integrator in the browser-based cloud editor.

Step 1: Create the integration​

  1. On the project overview page, click Open Cloud Editor.

    How would you like to create your integration page with Open Cloud Editor highlighted under Create on Cloud

  2. The Choreo Integrator cloud editor opens in your browser.

    Cloud editor landing page with Choreo Integrator Copilot, the Add Artifact manually button, and the Deploy to Choreo 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 highlighted

  2. Select Chat Agent Service under AI Integration.

    Artifacts page with Chat Agent Service highlighted under AI Integration

  3. The Create Chat Agent Service form opens. Set Role to ChoreoIntegratorAssistant.

  4. Set Instructions to:

    You are a highly skilled Choreo 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

  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 ChoreoIntegratorAssistant.

  7. Click Create.

    Bottom of the Create Chat Agent Service form with Agent Name set to ChoreoIntegratorAssistant

Default model provider

By default, the agent is configured to use the Default Choreo 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 Default Choreo Model Provider, the access token is obtained through Choreo 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 Test in the pop-up. The chat panel opens.

  3. Type Hello to check that the agent replies.

    Running the agent, clicking Test in the pop-up, and chatting with the agent in the chat panel

Step 4: Deploy to Choreo Cloud​


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

Skip ahead: deploy a ready-made sample

Rather not build it yourself? Deploy the AI Chat Agent sample straight to Choreo Cloud. See Start with sample integrations.

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 choreoIntegratorAssistantAgent = check new (
systemPrompt = {
role: string `ChoreoIntegratorAssistant`,
instructions: string `You are a highly skilled Choreo 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 /choreoIntegratorAssistant on chatAgentListener {
resource function post chat(@http:Payload ai:ChatReqMessage request) returns ai:ChatRespMessage|error {
string stringResult = check choreoIntegratorAssistantAgent.run(request.message, request.sessionId);
return {message: stringResult};
}
}

Was this page helpful?