Trigger AI agents from a script

karthiknarl
Giga Contributor

Hi, 
Does anyone has experience of invoking an AI agent from a script such as script include, business rule etc ? Is there an API existing for this ?

 

1 ACCEPTED SOLUTION

warren_chan
ServiceNow Employee

Not for an AI Agent specifically, but for an Agentic Workflow, you can do this:

 

var request = {
	targetRecordId: "25b65a1c936339100c8a30118bba10c7",
	targetTable: "incident",
	usecaseId: "78c687369f19d2d02b2d1597d90a1c97",
	conversationUser: "46d44a23a9fe19810012d100cca80666",
	objective: "Help me resolve the incident INC0010252",
	conversationLabel: "INC0010252: Incident Resolution"
};
var aiAgentRuntimeUtil = new AiAgentRuntimeUtil();
var response = aiAgentRuntimeUtil.startAiAgentConversation(request);
gs.info(JSON.stringify(response));

Also discussed here:

 

https://www.servicenow.com/docs/bundle/zurich-intelligent-experiences/page/administer/now-assist-ai-...

 

https://www.servicenow.com/community/developer-forum/how-to-call-agentic-ai-via-rest-api-call/td-p/3...

View solution in original post

3 REPLIES 3

Ratnakar7
Mega Sage

Hi @karthiknarl ,

"Use an AI agent" action in Flow Designer / Workflow Studio.
From a Script Include, Business Rule, or UI Action, you can call a Flow that contains the AI Agent action. Example syntax:

// Example: Trigger a flow from a Business Rule
var inputs = {
   short_description: current.short_description,
   sys_id: current.sys_id
};

sn_fd.FlowAPI.getRunner()
   .flow('your_flow_sys_id_or_name')
   .inForeground()
   .withInputs(inputs)
   .run();

This way, your script indirectly invokes the AI Agent by running the flow that contains it.
refer  https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/ScriptableFlowRunnerScopedAPI

https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/sn_fd-namespace/ScriptableFlow... 
 

Example:   Use an AI agent 

You can define triggers for Agentic Workflows and AI Agents - not only via chat, but also programmatically through APIs, GlideRecord queries, or Scripted REST APIs:
refer this thread - Trigger options for Agentic Workflow or AI Agent 

Thanks,
Ratnakar

abirakundu23
Giga Sage

Hi @karthiknarl ,
So far ServiceNow not release any API directly. There is another thread which will help for you.
Please check : https://www.servicenow.com/community/now-assist-forum/trigger-options-for-agentic-workflow-or-ai-age...

Please mark helpful and correct answer if it's worthy for you.


warren_chan
ServiceNow Employee

Not for an AI Agent specifically, but for an Agentic Workflow, you can do this:

 

var request = {
	targetRecordId: "25b65a1c936339100c8a30118bba10c7",
	targetTable: "incident",
	usecaseId: "78c687369f19d2d02b2d1597d90a1c97",
	conversationUser: "46d44a23a9fe19810012d100cca80666",
	objective: "Help me resolve the incident INC0010252",
	conversationLabel: "INC0010252: Incident Resolution"
};
var aiAgentRuntimeUtil = new AiAgentRuntimeUtil();
var response = aiAgentRuntimeUtil.startAiAgentConversation(request);
gs.info(JSON.stringify(response));

Also discussed here:

 

https://www.servicenow.com/docs/bundle/zurich-intelligent-experiences/page/administer/now-assist-ai-...

 

https://www.servicenow.com/community/developer-forum/how-to-call-agentic-ai-via-rest-api-call/td-p/3...