Skip to content

Commit 4bec7c0

Browse files
authored
Merge pull request #59 from MohamedSabthar/main
Add AI Agent Learn Page
2 parents 7fe97c8 + bc853f2 commit 4bec7c0

File tree

9 files changed

+104
-10
lines changed

9 files changed

+104
-10
lines changed
5.21 MB
Loading
5.44 MB
Loading
11.9 MB
Loading
19.8 MB
Loading
35.9 MB
Loading
19.3 MB
Loading
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# AI agent integration
2+
3+
In this tutorial, you'll create an AI-powered math tutor assistant capable of handling a variety of mathematical queries. The agent will be equipped with tools to perform fundamental arithmetic operations and intelligently combine and execute these tools to address user questions. By the end of this tutorial, you'll have built an interactive math assistant that can help users solve problems and provide clear, step-by-step explanations.
4+
5+
## Prerequisites
6+
7+
### Obtain OpenAI API key
8+
9+
- Sign up at [OpenAI](https://platform.openai.com/signup/).
10+
- Get an API key from the [API section](https://platform.openai.com/docs/api-reference/authentication).
11+
12+
### Step 1: Create a new integration project
13+
14+
1. Click on the **`Ballerina Integrator`** icon in the sidebar.
15+
2. Click on the **`Create New Integration`** button.
16+
3. Enter the project name as `MathTutor`.
17+
4. Select the project directory location by clicking on the **`Select Location`** button.
18+
5. Click the **`Create New Integration`** button to generate the integration project.
19+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step1.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step1.gif" alt="Create a New Integration Project" width="70%"></a>
20+
21+
### Step 2: Create an agent
22+
23+
1. Click the `+` button on the Ballerina Integrator side panel or navigate back to the Design screen and click on **`Add Artifact`**.
24+
2. Select **`AI Chat Agent`** under the **`AI Agent`** artifacts.
25+
3. Provide a **`Name`** for the agent. It will take a moment to create an agent with the default configuration.
26+
4. After creating the agent, you can configure it with a model provider, memory, tools, roles, and instructions.
27+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step2.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step2.gif" alt="Create an Agent" width="70%"></a>
28+
29+
### Step 3: Configure the agent behavior
30+
31+
1. Click on the **`AI Agent`** box to open the agent configuration settings.
32+
2. Define the agent's **`Role`** and provide **`Instructions`** in natural language. These instructions will guide the agent’s behavior and tasks.
33+
3. Click **`Save`** to finalize and complete the agent behavior configuration.
34+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step3.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step3.gif" alt="Configure the Agent Behavior" width="70%"></a>
35+
36+
### Step 4: Configure the agent model
37+
38+
1. Locate the circle connected to the **`AI Agent`** box. This circle represents the LLM model used by the agent.
39+
2. Click on the circle to open the model configuration options.
40+
3. In the **`Select Model Provider`** dropdown, choose **`OpenAiProvider`**.
41+
4. Next, provide the OpenAI API key in the **`API Key`** input field.
42+
!!! note
43+
Since the API key is sensitive it's recommended to create a configurable named `openAiApiKey` and use it as the value for the **`API Key`** field.
44+
5. In the **`Model Type`** dropdown, select `ai:GPT_40`.
45+
6. Click **`Save`** to complete the LLM model configuration.
46+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step4.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step4.gif" alt="Configure the Agent Model" width="70%"></a>
47+
48+
### Step 5: Configure agent memory
49+
50+
1. By default, the agent is preconfigured with memory.
51+
2. For this tutorial, we will keep the default memory configuration and not make any changes.
52+
3. If you prefer to run the agent without memory (in a stateless fashion), follow these steps:
53+
- Click on the three vertical dots in the **`Memory`** box.
54+
- Select the **`Delete`** option to remove the memory.
55+
56+
### Step 6: Add tools to the agent
57+
58+
Ballerina Integrator (BI) allows you to create tools using existing functions. It also supports automatically generating tools from connector actions or OpenAPI specifications by leveraging BI’s capability to generate local connectors from an OpenAPI spec.
59+
60+
However, in this tutorial, we will create simple functions to perform arithmetic operations and use them as tools.
61+
62+
#### To create a function:
63+
64+
1. Click the **`+`** button in the Ballerina Integrator side panel under the **`Functions`** section.
65+
2. Provide the required details to create the function. For this example, use `sum` as the function name, and specify the parameters and return types.
66+
3. Implement the function logic in the flow node editor that opens.
67+
68+
#### To add the created function as a tool:
69+
70+
4. Go to the agent flow view.
71+
5. Click the **`+`** button at the bottom-left corner of the `AI Agent` box.
72+
6. Click the **`+`** button under the **`Tools`** section.
73+
7. Select the created function from the **`Current Integration`** list — in this case, `sum`.
74+
8. Then provide the **`Tool Name`** and **`Description`** of the tool
75+
76+
Follow steps 1 to 3 to create functions named subtract, multiply and divide to perform subtraction, multiplication, and division operations respectively. Define the appropriate parameters and return types, and implement the corresponding logic in the flow node editor.
77+
78+
Then repeat steps 4 to 8 to add each of these functions as tools in the agent by selecting them from the Current Integration list and providing a relevant tool name and description for each.
79+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step6.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step6.gif" alt="Add Tools to the Agent" width="70%"></a>
80+
81+
### Step 7: Interact with the agent
82+
83+
After completing the above steps, your math tutor assistant is now ready to answer questions. Ballerina Integrator provides a built-in chat interface to interact with the agent.
84+
85+
To start chatting with the agent:
86+
87+
1. Click the **`Chat`** button located at the top-left corner of the interface.
88+
2. You will be prompted to run the integration. Click **`Run Integration`**.
89+
3. Since we have created a configurable variable for `openAiApiKey` in step 4, provide it in the `Config.toml` file.
90+
91+
!!! note
92+
A temporary OpenAI API key is used in the GIF below to showcase the steps.
93+
<a href="{{base_path}}/assets/img/ai-agent/ai-agent-step7.gif"><img src="{{base_path}}/assets/img/ai-agent/ai-agent-step7.gif" alt="Interact With the Agent" width="70%"></a>

en/docs/learn/data-mapping.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Data Mapping
1+
# Data mapping
22

33
The following instructions demonstrate how to build an integration that transforms a JSON payload into a different JSON structure using Ballerina Integrator Data Mapper. An HTTP service with a single resource (`transform`) will be created to receive a JSON payload and return the transformed result.
44

@@ -89,7 +89,7 @@ The following instructions demonstrate how to build an integration that transfor
8989
To learn more about resources, see [Ballerina Resources](https://ballerina.io/learn/by-example/resource-methods/).
9090

9191

92-
### Step 5: Add Data Mapper
92+
### Step 5: Add data mapper
9393
1. Click on the `transform` resource to navigate to the resource implementation designer view.
9494
2. Delete the existing **`Return`** node in the flow diagram.
9595
3. Hover to the arrow after start and click the ➕ button to add a new action to the resource.
@@ -106,23 +106,23 @@ The following instructions demonstrate how to build an integration that transfor
106106

107107
<a href="{{base_path}}/assets/img/data-mapping/data-mapper-added.png"><img src="{{base_path}}/assets/img/data-mapping/data-mapper-added.png" alt="Data Mapper Added" width="70%"></a>
108108

109-
### Step 6: Create Mappings
109+
### Step 6: Create mappings
110110
1. First click on the input field and then click on the desired output field to create a mapping
111111
2. When you are done click on the **`Go Back`** Button to return to the flow diagram
112112

113-
#### Create Simple Mapping
113+
#### Create simple mapping
114114
<a href="{{base_path}}/assets/img/data-mapping/simple-mapping.gif"><img src="{{base_path}}/assets/img/data-mapping/simple-mapping.gif" alt="Simple Mapping" width="70%"></a>
115115

116-
#### Auto Mapping
116+
#### Auto mapping
117117
<a href="{{base_path}}/assets/img/data-mapping/auto-mapping.gif"><img src="{{base_path}}/assets/img/data-mapping/auto-mapping.gif" alt="Auto Mapping" width="70%"></a>
118118

119-
#### Many-to-One Mapping
119+
#### Many-to-one mapping
120120
<a href="{{base_path}}/assets/img/data-mapping/many-to-one-mapping.png"><img src="{{base_path}}/assets/img/data-mapping/many-to-one-mapping.png" alt="Many to One Mapping" width="70%"></a>
121121

122-
#### Edit Mapping Expression
122+
#### Edit mapping expression
123123
<a href="{{base_path}}/assets/img/data-mapping/edit-mapping.gif"><img src="{{base_path}}/assets/img/data-mapping/edit-mapping.gif" alt="Edit Mapping Expression" width="70%"></a>
124124

125-
#### Resolving Errors
125+
#### Resolving errors
126126
<a href="{{base_path}}/assets/img/data-mapping/error-resolving.png"><img src="{{base_path}}/assets/img/data-mapping/error-resolving.png" alt="Error Resolving" width="70%"></a>
127127

128128

en/mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ nav:
8080
- Message routing: learn/message-routing.md
8181
- Service orchestration: learn/service-orchestration.md
8282
- AI-assisted integration: learn/integration-ai.md
83+
- AI agent integration: learn/ai-agent-integration.md
8384
- Data mapping: learn/data-mapping.md
8485
- Natural functions: learn/natural-functions.md
8586
- File integration: learn/file-integration.md
@@ -170,5 +171,5 @@ extra:
170171
- type: linkedin
171172
link: https://www.linkedin.com/company/wso2
172173
# site_version: Uncomment to specify a version
173-
base_path: https://wso2.github.io/docs-bi
174-
# base_path: http://localhost:8000
174+
# base_path: https://wso2.github.io/docs-bi
175+
base_path: http://localhost:8000

0 commit comments

Comments
 (0)