Back to trackLesson 15 of 25

Support Desk 5: An Agent Who Takes Breaks

Uses Only Free-Tier SpiceGrinder

Problem statement

So far the desk has had one agent who is always at their desk. A real agent takes breaks, steps into meetings and goes home, and a manager looking at a staffing plan sees one number: the agent is available 90% of the time. Customers arrive at 0.6 a minute and the agent serves one a minute while working, so the desk is loaded at 0.6 / 0.9 = 67% of the time it is staffed. That sounds comfortable. But a desk that is 90% staffed in scattered gaps of a minute or two behaves very differently from one where the agent is gone for fifteen minutes at a stretch.

The questions:

  • Hold the availability at 90% and change only how the absences cluster. How much longer do customers wait when the breaks come in long stretches?
  • How does the wait grow as the typical away spell gets longer?
  • What happens with more than two states: working, on a break, in a meeting?

The model has an exact answer for the waits, so we can check the simulation against it, as in lessons 3.2 to 3.4.

The model

One row is one minute, as in lesson 3.4. What is new is the agent. Lesson 3.4 held a regime for a random number of rows with Pool and Switch, which needs the regimes to take turns. An agent is simpler to describe as a chain: in each minute the agent is in one of a few states, and the state of the next minute depends only on the state of this one. The Markov generator does exactly that. It takes a transition matrix, one row per state, and emits the state number each row.

Here are two states, 0 for working and 1 for away. The matrix has one row for each state you are in and one column for each state you go to:

to workingto away
from working134/1351/135
from away1/1514/15

Written the way Markov wants it, each row in the order working, away, and the rows separated by a semicolon:

0.9925925925925926, 0.007407407407407408; 0.06666666666666667, 0.9333333333333333

so the first row is for working: stay working with probability 134/135, go away with 1/135; the second row is for away: come back with 1/15 and stay away with 14/15. (Each row must sum to 1; Markov refuses a matrix whose rows are off by more than 1e-6, unless normalize is set to scale counts or weights into probabilities.)

How to read it:

  • Spell lengths. A state that is left each minute with probability p stays for 1/p minutes on average (the same Geometric idea as lesson 3.4’s busy and quiet periods). Working is left with probability 1/135, so a working stretch lasts 135 minutes on average. Away is left with probability 1/15, so an away spell lasts 15 minutes. In general the expected spell in a state is 1 / (1 - the diagonal entry of its row).
  • Availability. In the long run the share of time in each state is fixed by a balance: the flow from working to away must equal the flow back, so (share working) x (1/135) = (share away) x (1/15), which with the two shares adding to 1 gives share working = (1/15) / (1/135 + 1/15) = 9/10 = 90%. For any two-state chain the share working is (probability of coming back) / (probability of leaving + probability of coming back).
  • The first row. Markov emits initial (0, working) in the first row without a random draw, then makes one draw per row from the row of the current state.

Here is the model, samples/simulation/support-desk-breaks.xml, four nodes, seed 305:

<dataset columns="backlog, agentState, arrivals" seed="305">
  <root node="Desk"/>
  <nodes>
    <Markov name="Agent" matrix="0.9925925925925926, 0.007407407407407408; 0.06666666666666667, 0.9333333333333333" initial="0"/>
    <Poisson name="Arrivals" lambda="0.6"/>
    <Append name="Minute">
      <input name="Agent"/>
      <input name="Arrivals"/>
    </Append>
    <Recur name="Desk" initial="0" expression="y[0] = max(0, s[0] + x[1] - (x[0] == 0))" appendInput="true">
      <input name="Minute"/>
    </Recur>
  </nodes>
</dataset>
  • Agent is the chain. Arrivals is Poisson with mean 0.6 customers a minute.
  • Minute is an Append: Recur takes a single input, so the agent’s state and the arrivals are put side by side, state first. In the expression they are x[0] and x[1].
  • Desk is the Recur of lessons 3.2 and 3.4 with one change. The backlog is Q = max(0, Q + arrivals - capacity) and the capacity is (x[0] == 0): one customer served in a working minute, none in an away minute. (A comparison in a Calculate or Recur expression gives 1 when it holds and 0 when it does not, so the capacity needs no if; the parentheses are needed because a comparison binds more loosely than the minus sign.) The state is the first column, so the agent’s state in a minute is known before the customers of that minute are served.
  • The output has three columns: the backlog Q after the minute, the agent’s state (0 working, 1 away) and the arrivals that minute.

What “wait” means here. As in lesson 3.4, a customer who arrives during a minute waits as many minutes as the backlog the previous minute left behind, and each minute counts once per arrival. This is exact to the minute for a desk with a one-minute service time and, as in 3.4, customers who arrive in the same minute are not counted ahead of one another. When the agent is away, the backlog still counts the customers ahead, so the wait includes the rest of the spell. The arrivals do not depend on the agent, so the customer-weighted waits are just the distribution of the backlog before a minute.

To run it, with the model’s own seed (305) the first ten rows are:

grind --count 10 samples/simulation/support-desk-breaks.xml
RowBacklog QAgentArrivalsCheck: previous Q + arrivals - capacity (not below 0)
10010 + 1 - 1 = 0
20000
30000
40000
51020 + 2 - 1 = 1
61011 + 1 - 1 = 1
70001 + 0 - 1 = 0
80000
90010
100000

The first away spell starts at row 256. grind --quiet --count 290 samples/simulation/support-desk-breaks.xml | tail -36 prints rows 255 to 290, and these are a few of them:

RowBacklog QAgentArrivalsCheck
255000last working minute
256010the agent leaves: 0 + 0 - 0 = 0
2570100
2581110 + 1 - 0 = 1
2591101 + 0 - 0 = 1
2602111 + 1 - 0 = 2
283231122 + 1 - 0 = 23, the last away minute
2842200back at work: 23 + 0 - 1 = 22
285220122 + 1 - 1 = 22
288210022 + 0 - 1 = 21
290190020 + 0 - 1 = 19

That spell was 28 minutes long (the average is 15). Nobody was served during it and the backlog went up by the arrivals, to 23. Then the agent is back, but a working agent only gets ahead of the line at the rate of the unused capacity, 1 - 0.6 = 0.4 a minute, so clearing 23 customers takes about an hour (23 / 0.4 = 58 minutes) after the agent is back. The absence is paid for several times over.

The comparison desks. The other desks are the same model with a different matrix and the same seed, so every desk sees exactly the same customers (the Poisson node has its own random stream, and changing the matrix does not touch it):

  • No breaks. The matrix 1, 0; 0, 1 never leaves state 0: a state with a 1 on its diagonal is absorbing. The agent is available 100% of the time. This file is not shipped: it is the shipped sample with that one matrix.
  • Breaks spread out, samples/simulation/support-desk-breaks-spread.xml: both rows are 0.9, 0.1. Whatever the agent is doing now, next minute they are away with probability 0.1. That is an independent coin flip every minute: 90% available, with away spells that last 1 / (1 - 0.1) = 1.11 minutes on average, the longest ones a few minutes.
  • Breaks in stretches, the model above: 90% available, away spells of 15 minutes on average.

Every desk is 90% available except the first, which is 100%. Each model was run at 20,000,000 rows (20 million minutes, about 12.0 million customers each, the same customers in all), measuring the average wait, the 95th percentile (the smallest wait w such that at least 95% of the customers wait w minutes or less) and the share who waited more than 10 minutes, with standard errors from 100 batches of 200,000 minutes.

Result: the same time away, four times the waiting

No breaksBreaks spread outBreaks in 15-minute stretches
Agent available100%90.0%90.1%
Average wait (minutes)0.450 (0.001)0.799 (0.001)3.287 (0.020)
95th percentile of the wait (minutes)2419
Customers waiting more than 10 minutes0.002%0.040%10.4%
Longest wait seen in the run (minutes)1523125

Average waits of 0.8 and 3.3 minutes, from the same 90% availability and the same customers. The 95th percentile goes from 4 to 19 minutes and the share who wait more than ten minutes from 0.04% to 10.4%: about one customer in ten. Taking away 10% of the minutes is the same in both desks; what differs is that the 15-minute stretches let a backlog of customers build up that the agent cannot clear quickly. Here is the same eight hours (a window of a real run, chosen as the one whose peak backlog is closest to the median of the first 200 windows) for the three desks:

Three panels of backlog against time for the same eight hours and the same customers. Top, no breaks: the backlog never goes above 8. Middle, breaks spread out, 63 away minutes in 52 short spells: the backlog never goes above 9. Bottom, breaks in stretches, 29 away minutes in two spells of 5 and 24 minutes: the backlog is as small as the others until the 24-minute spell near hour 7, when it climbs to 19 and is still coming down at the end of the window

The middle desk is away for twice as many minutes as the bottom desk in this window (63 against 29), in 52 separate spells, and its backlog never goes above 9. The bottom desk is away for 29 minutes in two spells and its backlog reaches 19. Until the 24-minute spell the backlogs of the three desks are all small and look alike, because they have the same customers: it is only when the agent is gone for long enough for the line to grow that the desks differ.

The whole distribution of the wait shows more than the averages do:

Four lines, measured dots on exact lines, on a logarithmic scale of the share of customers waiting longer than t minutes against t from 0 to 60. No breaks and breaks spread out fall very steeply, reaching under 1 in 10,000 by 10 and 15 minutes. Breaks in 15-minute stretches fall slowly: 10% wait more than 10 minutes, 1.7% more than 30, 0.12% more than 60. The three-state desk is above it: 25% wait more than 10 minutes, 9% more than 30

On a log scale a straight line is an exponential tail. The first two desks fall by a factor of 10 about every 2.4 and 3.4 minutes. The 15-minute-stretch desk falls by a factor of 10 every 26 minutes or so: one customer in 200 waits more than 45 minutes. The shape is the same as lesson 3.4’s, and so is the reason: customers are not hurt by the total time away, but by the long spells, which are the rare cases that fill the backlog.

Check: do the numbers match the math?

The matrix and the chain. Each matrix has rows that sum to 1 (the generator checks that), and the empirical transitions in the run agree with it. In the 20,000,000 minutes of the stretches desk, the agent moved from working to away 132,850 times out of 18,013,623 minutes spent working (0.737%, against the matrix’s 1/135 = 0.741%; 1.6 standard errors of a binomial count) and came back from 1,986,376 away minutes 132,850 times (6.69%, against 1/15 = 6.67%; 1.2 standard errors). The complete spells averaged 14.95 minutes away (exact 15) and 135.6 minutes working (exact 135). For the spread desk, the empirical rows were 0.9000 / 0.1000 and 0.9002 / 0.0998 against 0.9, 0.1 in both (0.8 standard errors at worst).

The availability. The exact stationary share of time working, from the balance above, is 90%. Measured by batch means: 90.00% (standard error 0.01 percentage points) for the spread desk and 90.07% (0.03) for the stretches desk. That is +0.2 and +2.0 standard errors. The second is the largest gap in the lesson and it matters a little below.

The exact waits. The exact distribution of the wait comes from a Markov chain over the pair (the agent’s state in the coming minute, the backlog before it): in one minute the backlog moves to max(0, Q + A - capacity) with A Poisson(0.6), and the agent’s state moves by the matrix. That chain was iterated on a grid of backlogs from 0 to 1,799 (the probability of reaching the last grid cell is under 1e-30 for every desk) until the distribution stopped changing, which gives the exact waits of a desk that has been running for a long time. Against the measured values, with standard errors from the batches:

Measured (SE)ExactGap in SE
No breaks: average wait0.450 (0.001)0.450-0.6
No breaks: 95th percentile22
Spread out: average wait0.799 (0.001)0.800-0.8
Spread out: 95th percentile44
Spread out: share waiting more than 10 min0.040% (0.002)0.042%-0.9
Stretches: average wait3.287 (0.020)3.300-0.7
Stretches: 95th percentile1919
Stretches: share waiting more than 10 min10.39% (0.07)10.46%-1.0

For the no-breaks desk there is a closed form too: with Poisson(0.6) arrivals and capacity 1, the mean wait is 0.6 x 0.6 / (2 x (1 - 0.6)) = 0.45. The whole tail agrees as well, not just these. Take the times t = 0, 1, 2, 3, 5, 7, 10, 15, 20, 30, 45, 60, 90 and 120 minutes where the exact share waiting longer than t is at least 0.1%: the measured shares are within 0.8 standard errors of exact for the no-breaks desk (5 such times), within 1.6 for the spread desk (6 times) and within 1.9 for the stretches desk (12 times).

The stretches desk sits a little low across the board: at each of the first seven times its measured share is 1.0 to 1.9 standard errors under exact. Those values are not independent of one another (one long spell raises all of them together), and this run happened to have 0.07 percentage points more working time than the exact 90% (the +2.0 above), which means fewer long waits. It is the same effect as the 80/240 run in lesson 3.4: the longer the spells, the fewer of them 20 million minutes hold, and the noisier the estimate. The standard errors above already say so, 0.020 on the stretches desk against 0.001 on the spread one.

How long is a spell?

The two extremes are one run each, but nothing is special about 15 minutes. At the same 90% availability, the matrix for a typical away spell of L minutes is: from working, away with probability 1 / (9 L); from away, back with probability 1 / L. (The share working is (1/L) / (1/(9L) + 1/L) = 90% for every L.) For 5-minute spells that is 0.9777777777777777, 0.02222222222222222; 0.2, 0.8. Change the matrix in support-desk-breaks.xml and nothing else. Spell lengths of 3, 5, 10 and 30 minutes were run (not shipped), each for 20,000,000 minutes with the same seed, and measured as before:

Typical away spellAverage wait (SE)Exact95th percentile (exact)Waiting more than 10 minExact
coin flip (1.11 min)0.799 (0.001)0.8004 (4)0.040%0.042%
3 min1.139 (0.003)1.1405 (5)0.62%0.64%
5 min1.503 (0.005)1.5007 (7)2.26%2.25%
10 min2.401 (0.012)2.40013 (13)6.95%6.95%
15 min3.287 (0.020)3.30019 (19)10.39%10.46%
30 min6.056 (0.064)6.00036 (36)16.06%16.03%

Every 95th percentile equals the exact one, no average wait is more than 0.9 standard errors from exact (the 30-minute run is the largest), and the largest gap among the shares over 10 minutes is 1.4 (the 3-minute run). The exact averages sit on a straight line: 0.6 + 0.18 L fits all six rows to the digits shown (0.8, 1.14, 1.5, 2.4, 3.3 and 6.0). That was not derived: it is what the exact chain gives for these six spell lengths.

Two charts against the typical away spell, from 1 to 30 minutes, always at 90 percent availability. Left, the average wait rises from 0.8 minutes to 6.1. Right, the share of customers who wait more than 10 minutes rises from 0.04 percent to 16.1 percent. Measured dots sit on the exact line

The companion page lets you pick the spell length and compare the average wait, the 95th percentile and the share who wait over 10 minutes against the agent who never leaves, with the exact value beside each.

Three states

A real agent has more than one way to be away. Take three states: working, on a break (15 minutes on average) and in a meeting (30). From working they go on a break with probability 1/150 a minute and to a meeting with probability 1/300; from either away state they come back to working. The matrix has three rows now:

0.99, 0.006666666666666667, 0.0033333333333333335; 0.06666666666666667, 0.9333333333333333, 0.0; 0.03333333333333333, 0.0, 0.9666666666666667

Row 0 (working): stay 0.99, break 1/150, meeting 1/300. Row 1 (break): back to work 1/15, stay 14/15, never straight to a meeting (the 0.0). Row 2 (meeting): back 1/30, stay 29/30. The model is samples/simulation/support-desk-three-state.xml: the same four nodes, with the three-row matrix instead; because only state 0 serves, if(x[0] == 0, 1, 0) is still the capacity. (Without Markov and if, a three-state chain in one Recur expression needs a polynomial through the three state values to pick the next state, and every state added makes it longer. Now it is the matrix.)

The stationary shares follow from the same balances: break to working, (share working) x (1/150) = (share break) x (1/15), so the break share is 0.1 of the working share; the meeting share is also (1/300) / (1/30) = 0.1 of it. The three shares are in the ratio 1 : 0.1 : 0.1, so working is 1 / 1.2 = 83.3% of the time and each away state 8.3%. The desk is therefore loaded at 0.6 / 0.833 = 72% of the time staffed.

20,000,000 minutes, seed 305 (the same customers once more):

Measured (SE)ExactGap in SE
Time working83.37% (0.05)83.33%+0.7
Time on a break / in a meeting8.33% / 8.31%8.33% / 8.33%
Average wait (minutes)8.865 (0.083)8.807+0.7
95th percentile (minutes)4444
Share waiting more than 10 minutes24.51% (0.13)24.54%-0.2
Share waiting more than 30 minutes9.22% (0.11)9.14%+0.7
Longest wait seen in the run (minutes)281

Customers at this desk wait 8.8 minutes on average and a quarter of them wait more than ten, with an agent who is at their desk five minutes in six. The empirical transitions agree with the matrix (the largest gap is 1.4 standard errors), the mean spells were 15.05 minutes (break, exact 15) and 29.9 (meeting, exact 30), and all 14 points of the tail from 0 to 120 minutes are within 1.2 standard errors of exact.

What this gives you: an agent with states, in a few lines. A Markov node takes a transition matrix, with one row per state and the spell length of each state fixed by its diagonal, and emits the state each minute; Append puts that next to the arrivals; and a Recur with if(x[0] == 0, 1, 0) turns the state into the capacity of the desk. Two comparisons show that the availability alone does not decide the waits: at the same 90% availability and the same customers, spread-out breaks give an average wait of 0.80 minutes, a 95th percentile of 4 and 0.04% waiting over ten minutes, and breaks in 15-minute stretches give 3.29, 19 and 10.4% (20,000,000 minutes each; exact 0.800 / 4 / 0.042% and 3.300 / 19 / 10.46%). Across spell lengths from a coin flip to 30 minutes the exact average wait runs from 0.8 to 6.0 minutes. The same matrix scales to three states: an agent who is available 83.3% of the time, with 15-minute breaks and 30-minute meetings, makes customers wait 8.9 minutes on average (exact 8.81), with a 95th percentile of 44.

This finishes Module 3, on state: a quantity that carries from one row to the next (a backlog, a balance), a regime that lasts for a while (busy and quiet, an agent’s states), and a clock that gives a row its meaning. Everything so far has been one system, studied by running it. Module 4 changes the question: with a model of one system in hand, how do you compare scenarios fairly, with the same randomness in both, and say whether a change is real or noise?