warren_chan
ServiceNow Employee

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:

 

warren_chan_0-1775245477897.jpeg

 

In the Assistant Designer experience, select the Create asset button:

 

warren_chan_1-1775245505597.jpeg

 

In the Create asset popup modal, select Topic:

warren_chan_2-1775245525945.jpeg

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

 

warren_chan_3-1775245666969.jpeg

warren_chan_4-1775245676656.jpeg

Select the Create button. After a few seconds, the Topic's Flow builder view should load:

 

warren_chan_5-1775245705823.jpeg

 

 
On the left side of the Topic Flow builder, select the Variables sub-tab. Then select the (+) sign to add a new Script variable:
 
warren_chan_6-1775245745846.jpeg

 

 

In the Add Script Variable modal, for Variable Name, enter conversationID. Default value can be left blank.

 

warren_chan_7-1775245835661.jpeg

 

Select the Save button. The conversationID Script Variable should now be defined in the Variables list:

 

warren_chan_8-1775245877769.jpeg

 

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:

 

warren_chan_9-1775245906854.jpeg

warren_chan_10-1775245926423.jpeg

 

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:

 

warren_chan_11-1775246016191.jpeg

 

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:

 

warren_chan_12-1775246050825.jpeg

warren_chan_13-1775246061474.jpeg

 

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>

warren_chan_14-1775246113219.jpeg

 

warren_chan_15-1775246132417.jpeg

Your completed Topic Flow should look like this:

 

warren_chan_16-1775246150707.jpeg

 

In the top right, select the Save button. In the top right, select the Publish button. Your Topic Flow should now be Active:

 

warren_chan_17-1775246179136.jpeg

 

Agent Configuration

 

 
Go to AI Agent Studio > Create and manageSelect your AI agent.
 
Under Add tools and information, select Add toolSelect Conversational topicIn the Add a conversational topic modal, fill in the form as follows:
 
  • 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
warren_chan_18-1775246351291.jpeg

 

warren_chan_19-1775246360664.jpeg

Select the Add button.​ This creates our Conversational Topic tool.

 
We need to add a second Tool for processing the result of this Conversation Topic. Under Add tools and information, select Add tool.​ Select Script.
 
  • 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);

 

Screenshot 2026-04-03 at 1.11.01 PM.png

Screenshot 2026-04-03 at 1.11.14 PM.png

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:

 

Screenshot 2026-04-03 at 1.14.05 PM.png

Version history
Last update:
2 hours ago
Updated by: