In this post we will see in details about Agent and Agent Schedule in Pega.
Most of the applications rely on processes that operate at the background without human intervention.
Imagine there is a requirement to send a status report to the reporting manager every day by 8 p.m.
You can code it like ‘providing a button and by clicking on that, we send an email containing the status report’. But if you do like this people will laugh at you.
Here comes the Internal background process to provide solution for this requirement.
In Pega platform, ‘Agent’ rule serves as an Internal background process.
To know about requestor type involved in batch processing, please visit my post below.
Agent and Agent schedule in pega, both belongs to background processing
What is an Agent rule?
- An agent is an internal background process operating in the server on a periodic basis.
- Each agent rule can contain individual agent activities for different processes.
- Agents come under SysAdmin category and each ruleset can contain only one Agent rule.
How to configure an Agent rule?
Agent rule don’t belong to any class.
In the Agent rule form, we have three main tabs.
a) Scheduled agents
In the scheduled agents, you can add ‘n’ number of activities.
Agent Name – Provides the name of the agent (Appropriate description).
Pattern – Periodic/Recurring/Startup.
- Periodic scenario: Imagine you need to update a work item every one hour. In the interval field, you specify the seconds as 3600.
- Recurring scenario: You need to send mail daily at 1 pm. Use Interval field advanced option, to set the time daily to 1 pm.
- Startup: Only when the server starts ( not used often).
Mode – Standard / Advanced (We will have deep explanation below).
Category – Not a required field. Use it for recording purpose.
Enable – True/False. We can enable or disable the agent.
Class – Class of the Agent activity rule.
Activity Name – Agent activity name.
Params – Activity parameters.
Max Records – Shows how many records the agent should process before going to sleep. Usually applicable for standard agents.
Auto Queue Management – True/False.
What is Auto Queue Management (AQM)?
This is applicable only for standard agents.
Imagine a scenario where you need to update a work item in the background based on SLA.
The agent activity tries to acquire the lock for the work item, but is already locked by other agent. Now basically the agent activity cannot update the work item (fails). In this scenario, if
- AQM is checked, then the agent re-queue the item for later processing.
- If not checked, then the agent gets only one chance to process it and do not persist the queue item.
Agent wide settings
Enable this agent – True / False. Enable the Overall agent rule.
Interval – Default interval seconds. Used when if we don’t provide the Interval for Individual agent activity configurations.
Note: these configurations can be updated in agent & agent schedule
Access Group – Applicable only for Advanced agents. Used to identify the agent activity rule.
Access group -> Application -> Builds ruleset list -> Agent activity rule.
Bypass Authentication – True / False – Agent activities may be configured to use authentication (Activity security tab). You can bypass those authentication by selecting true.
We know Pega system can run on different nodes using different servers.
This tab lists the nodes, where the agent schedules are created. We will discuss about Agent schedule later in this post.
How a standard agent works?
Requirement: Route the Leave request case to manager queue for approval.
- If the manager didn’t approve the next day, the send an Email to him.
- Even after 3 days if he didn’t approve, then Auto-approve the request.
This requirement can be achieved using SLA on the assignment shape of manager queue.
As part of development, we just configure an SLA and don’t mind how the background SLA works.
I am going to take you to a trip and explain in detail how the background SLA process works.
To know the basic of SLA, please visit my exclusive post on Service level agreement.
- When the Leave request case reaches the assignment shape Assign-.AddAssign gets called.
- This activity queues an entry with Event as “goal” to agent “Pega-ProCom:ServiceLevelEvents”.
- Expand 2nd & 3rd step to get the details.
- Now the Goal event (1 day) is queued to standard agent.
- Agent – Pega-ProCom
- System-Queue-ServiceLevel.EstablishContext is responsible for Open & lock the assignment and Switching the access group. (AQM functionality)
- Process Event – SLA agent activity.
a) When the manager didn’t approve the next day
The agent activity runs and starts processing the queued Goal event. Use activity ExecuteSLA to set the Urgencies and execute the escalation activities. It Re-queues the entry again for Deadline event.
b) When the Manager didn’t approve for the third day
The agent activity runs and starts processing the queued Deadline event. Use ExecuteSLA to set the Urgencies and execute the escalation activities. Here no passed deadline, so no more queue entries are added again. Leave is auto approved after deadline.
Go through the activities ProcessEvent & EstablishContext in System-Queue-ServiceLevel class.
How an Advanced agent works?
Advanced agent do not automatically use the Auto Queue Management (AQM).
All the transaction items need to be carried out in agent activity. We can configure the activity to re-queue if some error occurs.
Key differences between Standard agent and advanced agent:
- Standard agent uses the access group of the user who queues the entry, while the advanced agent uses the access group specified in Agent rule or requestor type.
- Standard agent supports AQM, while advanced agent do not.
- Standard agent wake and run only when there are queue entries with available lock, while the advanced agent runs even if there are no queue entries. This is because advance agent is responsible for agent queue processing.
Issues you may face in advanced Agent:
Imagine the same scenario discussed above. You need to configure an agent to update a work item. Now you configured the agent as Advanced agent and made it available in 3 nodes. Here, Object contention occurs, since advanced agent activity should handle the locks. If the same is configured using Standard agent, then there won’t be any locking issue.
“Prefer using standard agent over advanced agent”.
What is Agent Schedule?
- Here you can see the relation between agent and agent schedule in pega.
- As we discussed before Agents can run in multi nodes.
- Imagine a scenario where you need to update agent run Interval from 300 seconds to 30 seconds in particular node. To solve this Agent schedule comes in Handy.
- Agent schedule is a data instance and can be updated in any environment.
- Here Pattern, Interval, Enabled, Access group etc., are editable and can be updated for a particular node.
- You can check the node ID in the ID header field.
- The changes reflect immediately once updated and saved.
How to create Agent schedule?
There is no need to create the agent schedule manually. There is an OOTB Master agent which monitors the Agent rules. If there is any new agent rules or if there is any update the Master agent generates, then the appropriate agent is scheduled. This is the relation between agent and agent schedule in Pega 🙂
How to debug an agent?
- In the Agent management, you can check if the agent is running or not. If there is some error and the agent has stopped, then you can see the stack trace or log files.
- Tracing the Requestor.
We may be aware of a mantra,
Stop -> start -> Delay -> go the requestor management and trace.
Have you ever wondered, why you do this?
- As per my previous post, I mentioned Agents use batch requestor type.
- Requestors will be assigned to agent activities, only when it runs. When agent runs, it requests a batch requestor.
- So when you stop and start the agent, a new batch requestor (B) is assigned. You will delay and trace that requestor from requestor management page.
Hope you get the basics about agent and agent schedule in Pega