Agent Client Side API
This section describes the classes and methods available in the client-side Agent API.
Agent
The agent is the class responsible for controlling an AI Agent's execution flow. The system creates an instance of this class for every agent execution.
The agent instance is available in UI components using:
let agent = component.getAgent();
In all Agent Components created in the agent builder, you access the agent instance using:
let agent = this.agent;
To debug agent code: lib/components-ui2/taskAgent/agent.js - emitEvent method
To debug event handler code of UI Component: lib/components-ui2/base-component.js - handleEvent method
Fields
Property | Data Type | Description |
|---|---|---|
| object | Agent data. (Object of key, value pairs) |
| String | ID of the agent. This is the UID of the agent. The system assigns this value to the agent. This is the same as the one on the Agent details screen. |
| boolean | Boolean indicates if the system has saved all data. |
| Agent | Returns parent agent that started this agent. |
Methods
Method | Parameters | Return Type | Description |
|---|---|---|---|
getWidgets |
| Map<String, Widget> | Returns widgets loaded during this agent flow. To get the individual widget from the agent builder flow, use the widget components ID or ResourceID: let widget = this.agent.getWidgets()['myCustomWidget']; |
emitEvent | event: { name: String, sourceId: String, …. } | void | Emits an event with the given name event.name: This should match with event names of the component in the agent builder diagram. event.sourceId: This should match with the component's ID in the agent builder diagram You can provide Additional data in the event JSON. The entire event object is available in the event trigger's target component in args.$event |
getElement | elementId: String | Agent Component | Get any component in the agent process flow. elementId: Id or ResourceID of element provided in Agent Builder. |
startSubAgent | agentId: String | void | Starts a sub-agent. This sub-agent becomes the active agent until you call its end method. The end method of the sub-agent causes the control to pass back to the parent agent. agentId: Id of agent to load. The system pushes the agent onto the stack and becomes the active agent. This is the UID of agents. The system assigns this value to the agent. You can get this from the Agent details screen. |
end |
| void | Ends the agent. If the parent agent exists, the system pops this agent from the parent's stack, and the parent becomes the active agent. |
getActiveAgent |
| Agent | Gets the current active agent that controls the UI. |
setData | key: String | void | Saves agent data. The system stores every field in the data separately in the database. |
async save |
|
| Saves the agent and all its unsaved data.Methods |
Sample Scripts
Script to call Server-side APIs
// Call the getMyData API, passing the dataId as a parameter// The API is created in the Designer Studio appexecuteAppAPI("getMyData", { dataId: 123}, null, (response) => { if (response.status === "OK") { // If the API call is successful, log the data to the consoleconsole.log("Data retrieved successfully:", response.result); } else { // If the API call fails, log the error message to the consoleconsole.error("Error retrieving data:", response.message); }});Note:
You can create a server-side API in the Designer app in your app palette.
Script to call Data APIs
// This function is used to call the Data API for task// Call the executeDataAPI function to insert data into the task// Other API calls can be made in a similar way for update, delete, list and getexecuteDataAPI("task/insert", { name: "New Task", description: "This is a new task", dueDate: "2023-10-31"}, null, (response) => { if (response.status === "OK") { // If the API call is successful, log the data to the consoleconsole.log("Data retrieved successfully:", response.result); } else { // If the API call fails, log the error message to the consoleconsole.error("Error retrieving data:", response.error); }});The format of the data API name is: <Entity_Resource_Id>/<Operation_Id>.
You can see the resource ID of all entities in the Designer app in your app palette.
The Operation ID can be one of: insert / update / delete / list / get.
Script to call Agent Component method
// Get the element with the ID "callImageAnalysisPipline" from the agentlet genAIPipelineCall = this.agent.getElement("callImageAnalysisPipline");// Invoke the execute method on the elementgenAIPipelineCall.execute();Script to Emit Event from Agent Component
// Emit a custom event named "onMyCustomEvent" with some data// It triggers the event handler for "onMyCustomEvent" in this agent component// The event is available in the target component as args.$eventthis.agent.emitEvent({ sourceId: this.id, name: 'onMyCustomEvent', data: { message: 'Hello from the custom event!' }});Script to show button options in the chat
// Get Chat widget by its resource Idlet widget = this.agent.getWidgets()['aiChat'];// Get Chat component by its resource Idlet chatComponent = widget.getElements({ resourceId: 'chat1' });// Create message object to add to chatconst messageObj = { text: this.messageText, sender: 'NeoPilot', avatar: 'https://contineo.world/imgs/genaipro.svg', actionOptions: [ { messageId: "msg-001", label: { default: "Continue" }, resourceId: "continueButton", emitEventName: "onContinue", styleClasses: '', outline: true, color: 'blue-8', eventHandlers: { onclick: 'onContinueButtonClick' } }, { messageId: "msg-002", label: { default: "Cancel" }, resourceId: "cancelButton", emitEventName: "onCancel", styleClasses: '', outline: true, color: 'grey-8', eventHandlers: { onclick: 'onCancelButtonClick' } } ]};chatComponent[0].addMessage(messageObj);Script to Emit Event from a Custom widget
asyncfunction(component, data, event) { // Emit the event to the agent. In this example "component" is the button option in the chat window component.getAgent().emitEvent({ // Name of the event to be emittedname: component.uiprops.emitEventName, // Source Id of the widgetsourceId: component.widget.uiprops.id, // The widget referencewidget: component.widget });}You specify this code in the controller code of your custom widget.
Script to display locale-specific messages to the user
// Define label for response from Agent.// In this case we are specifying a Japanese language label.// For other languages the "default" value is used.labels["UnderstandMessage"] = new contineo.Label({ "default": `I understand that you want to build the <b>{0}</b> application. Please specify more details regarding the system or business operations and the users who can use this system. You may also specify business workflows such as review/inspection and approval or data analytics and dashboard visualization or reporting. Alternatively, if you want me to help you elaborate the requirements, click <b>HELP ME ELABORATE THE REQUIREMENTS</b> button.`, "ja": `あなたは「<b>{0}</b>」を作成したいのですね。 実現したいシステムの機能概要や業務運用上行いたい操作、そしてこのシステムを使用するユーザーについて、もう少し詳細を教えてください。 また、レビュー・検査・承認などの業務フロー、データ分析、ダッシュボードの可視化や帳票作成など要件を指定することもできます。 もしくは、要件の詳細化を手伝って欲しい場合は、「<b>要件の詳細化を手伝って</b>」ボタンをクリックしてください。`});// Get Chat Widgetlet widget = this.agent.getWidgets()['aiChat'];// Get Chat component in widgetlet chatComponent = widget.getElements({ resourceId: 'chat1' });// Get App Namelet appName = this.agent.data.app_name || " ";// Get message as per locale selected by userlet messageText = app.getLabel('UnderstandMessage');// Replace app name in messagemessageText = messageText.replace('{0}', appName);// Add message to chat componentchatComponent[0].addMessage({ text: messageText, sender: "NeoPilot", size: 6, avatar: "https://contineo.world/imgs/genaipro.svg"});