Yes. It is possible to start or stop agent using a button in UI by invoking an activity which in turn invokes OOTB API to start or stop agents as mentioned below:
To start an agent:
boolean result = tools.getAgentUtils().startQueue(RulesetName, AgentIndex);
To stop an agent:
boolean result = tools.getAgentUtils().terminateQueue(RulesetName, AgentIndex);
RulesetName is the name of the agent ruleset. AgentIndex is index of specific agent in the Rule-Agent-Queue instance.
To get the Agent Index based on agent name perform below steps:
Open the Rule-Agent-Queue instance by Obj-Open using agent ruleset name as key.
Get the Agent index based on agent name as ( @(Pega-RULES:Utilities).IndexInPageList("AgentName" , "pyAgentName" , .pyFutureQueues)) - 1.
To start or stop all agents in an agent rule do not pass the agent index.
It is advisable to create wrapper functions to start and stop agents which can take the Ruleset name and agent Index as input variables. The activity thus can invoke this wrapper functions rather than hard-coding the API invocation within the java step.
Curios to know the reason behind not able to access SMA. I definitely agree after seeing the solutions that it is possible but this reinventing of wheel is really necessary and aboslute for business to have?
I also agree its good to know how pega achieves these things which will help us in some difficult scenarios.