- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
2 hours ago - edited 2 hours ago
You may find yourself in a situation where you want your AI agent to use a data point directly from it's own Execution Plan in the middle of runtime. One way to do this is to create a Conversation Topic tool to get the conversation ID on-the-fly.
Conversation Topic Setup
Go to All > Conversational Interfaces > Virtual Agent > Designer:
In the Assistant Designer experience, select the Create asset button:
In the Create asset popup modal, select Topic:
In the New Topic tab, fill out the form as follows:
| Field | Value |
| Application scope | Global (or whatever you scope you are using) |
| Model Type | LLM |
| Type | Topic |
| Internal name | Get Conversation ID |
| Display name | Get Conversation ID |
| Topic description used for discovery | Gets the Conversation ID from a current Agentic execution plan |
| Select LLM assistants to make topics available to them and any primary assistants |
All selected/checked: AIA Assistant, Now Assist in Virtual Agent (default), Now Assist Panel - Platform (default) |
| Advanced properties (optional) |
No changes |
Select the Create button. After a few seconds, the Topic's Flow builder view should load:
In the Add Script Variable modal, for Variable Name, enter conversationID. Default value can be left blank.
Select the Save button. The conversationID Script Variable should now be defined in the Variables list:
Select the Components sub-tab. Scroll down to the Utilities section. Click and drag the Script Action utility between the Start and End blocks of your Topic's Flow:
In the Script action utility node, enter the following details:
- Node name: Get Conversation ID
- Action expression:
(function execute() {
/* Code your scripted action here. For example, you might update a
record based on conditional logic:
if (vaVars.my_flag == 'say hello') {
gs.info('hi there');
} else {
gs.info('bye now');
}
*/
// Get the Conversation ID
vaVars.conversationID = vaSystem.getConversationId();
})()
Refer to the Virtual Agent scripts Documentation page for more details on the vaSystem.getConversationId() method call: https://www.servicenow.com/docs/r/zurich/conversational-interfaces/virtual-agent/virtual-agent-scrip...
In the Components sub-tab, scroll down to the LLM-enabled bot response section. Click and drag the Text utility between the Get Conversation ID and End blocks of your Topic's Flow:
In the Text response node, enter the following details:
- Node name: Display Conversation ID
- Tell the LLM how to respond: Looking up Execution Plan for Conversation ID: <data picker for Script Variables > conversationID>
Your completed Topic Flow should look like this:
In the top right, select the Save button. In the top right, select the Publish button. Your Topic Flow should now be Active:
Agent Configuration
- Select topic: Get Conversation ID
- Name: Get Conversation ID
- Tool description: Gets the Conversation ID from the current execution.
- Execution mode: Autonomous
- Display output: No
Select the Add button. This creates our Conversational Topic tool.
- Select a type of script to add: A new script
- Name: Get Execution Plan
- Tool description: Gets the Execution Plan
- Script inputs:
- (Add an input)
- Input name: conversationID
- Description: Conversation ID
- Mandatory: false (unchecked)
- Execution mode: Autonomous
- Display output: No
- Script:
(function(inputs) {
// only string inputs are allowed
// return outputs object where the keys in it are understandable by LLM
// Get the Execution Plan
var execution_plan_gr = new GlideRecord('sn_aia_execution_plan');
execution_plan_gr.addQuery('conversation', inputs.conversationID);
execution_plan_gr.query();
// Execution Plan found
if (execution_plan_gr.next())
{
// Do whatever you want with the Execution Plan record
return "Execution Plan ID: " + execution_plan_gr.sys_id;
}
// Execution Plan not found
else
{
return "No Execution Plan found for Conversation ID: " + inputs.conversationID;
}
})(inputs);
Add the Tool. Include the tool calling prompts in your AI agent instructions. Save and test. You should be able to reference the Execution Plan record attributes freely in your runtime execution now:
