The agent knew the opening hours. It couldn’t tell if the office was open.
A client’s phone agent read the opening hours back perfectly, then forwarded calls at the wrong times. A bigger model fixed it but made every reply 1.5 seconds slower. The fix kept the model, the speed and the cost.
- Latency kept. GPT-5.1 took 2.1 s
- 0.6 s
- Model and API cost per call
- Same
- Small workflow, on the client’s own n8n
- 1
Stack: GPT-4.1 · n8n · Langfuse · Tuner
GPT-4.1, as it was
0.6 sWrong about open and closed
Upgrade to GPT-5.1
2.1 sRight, but slower and costs more per call
GPT-4.1 + an open/closed checkThe fix
0.6 sRight, same speed and cost
The problem
A client had a voice agent taking real calls. It answered callers’ questions well, with one exception: anything to do with time.
The business kept different hours on different days. Monday had one schedule with a break in the middle, Tuesday had another, and so on through the week. Putting that timetable in the prompt was easy. Ask the agent “When are you open on Thursday?” and it read the hours back correctly.
The trouble was what the agent had to do with the time. The client wanted it to:
- forward calls to the office only during opening hours
- handle calls differently during a break
- handle them differently again once the office had closed
To do that, the agent had to work out whether the office was open right now. That’s where it guessed, and it often guessed wrong.
The obvious fix, and what it costs
The client ran the agent on GPT-4.1. The textbook answer is a stronger model, so we tried GPT-5.1. It fixed the mistakes.
On an agent taking a lot of calls, though, it brought two new problems:
- Cost. A bigger model costs more on every call.
- Latency. It went from about 0.6 seconds to 2.1 seconds. On the phone, that’s a pause every caller hears, on every reply.
The bigger model swapped one problem for two.
What I tried
First, the prompt. I rewrote and tightened the opening-hours instructions. It didn’t hold.
Then I traced calls in Tuner and Langfuse to see where the agent got confused. The mistakes came from one job: deciding whether “now” fell inside the opening hours.
That isn’t a language task. It’s clock maths: take today’s day and time, find that day’s schedule, and check it against every opening window and break. A language model gets it right most of the time. A phone line needs it right every time.
The fix: give the agent the answer, not the timetable
I moved the clock maths out of the model and into code.
- One small n8n workflow, on the n8n the client already ran. A code node holds the opening hours and breaks for each day, in one place the client can edit.
- A check at the start of every call. Before the agent says hello, it calls the workflow’s webhook and stores the reply in a pre-call variable.
- One answer back:
trueorfalse. The office is open, or it isn’t. The prompt no longer asks the model to work out the time. It says what to do in each case.
Here is a simplified version of the code node. It’s a sketch of the idea, not the client’s code.
// n8n Code node: is the office open right now?
const zone = 'America/New_York'; // the business's time zone, not the server's
// Opening hours per day. Two ranges means a break in between.
const hours = {
Mon: [['09:00', '12:30'], ['13:30', '17:00']],
Tue: [['10:00', '18:00']],
Wed: [['09:00', '12:30'], ['13:30', '17:00']],
Thu: [['09:00', '12:30'], ['13:30', '19:00']],
Fri: [['09:00', '14:00']],
Sat: [],
Sun: [],
};
const now = $now.setZone(zone);
const time = now.toFormat('HH:mm');
const today = hours[now.toFormat('ccc')] ?? [];
const isOpen = today.some(([from, to]) => time >= from && time < to);
return [{ json: { is_open: isOpen } }];
The result
- The agent stopped guessing. It acts on a fact the code worked out, not on its own maths.
- The model stayed GPT-4.1, so latency stayed at about 0.6 seconds and the API cost didn’t change.
- The prompt and the voice stayed the same, so the agent still sounded like itself.
What agencies can take from this
- Don’t make the model do clock maths. Anything that depends on the current day or time (opening hours, holidays, “is it too late to book today?”) is better worked out in code and handed to the agent as a fact.
- A bigger model isn’t free. It may fix the problem, but you pay for it on every call, and callers hear it in every pause.
- Trace before you tune. Rewriting the prompt didn’t fix this. Seeing exactly where the calls went wrong did.