← Forward Deployed Engineering Lesson 6 of 12

Agents and workflows

From answering to acting

So far the model answers. Booking a counselling call takes more: find free slots, ask which one suits, book it, confirm.

A system that repeats a loop of decide → use a tool → look at the result until the job is done is called an agent.

Step through the agent booking a call
  1. them"I'm Tom, Python course. Can I book a call Saturday morning?"
  2. decideI need free slots. Use find_slots.
  3. resultAnand 10:00 and 11:00, Divya 10:00 and 11:00, Meera 10:00.
  4. reply"Saturday at 10:00 or 11:00?" Tom: "10:00 please."
  5. decideBook it. Use book_call(Anand, Sat 21 Nov 10:00, Tom).
  6. resultBooked.
  7. reply"Done! Anand will see you Saturday at 10:00."

Does everything need an agent?

Workflow or agent?

When the steps are always the same, write them in code, in order. That's a workflow. It's predictable, cheap and easy to test.

Use an agent only when the next step depends on what the person says.

Good FDEs use the simplest thing that works.

Sort each job

An agent also has to remember things.

Remember the conversation

People give details bit by bit, across many messages. The agent keeps what it has learned so far in a small record, and updates it each turn.

That record is the conversation's state. It's also what gets saved to the lead tracker at the end.

Watch the state fill in

State

Now, booking safely.

Book without double booking

In discovery you found Rohan and Kavya both booked into Divya's 11:00 slot on 17 November. People were booking from an old view of the calendar.

An agent can make the same mistake: it finds a free slot, chats for a minute, then books, and meanwhile someone else took it.

The agent offered Divya, 17 Nov, 15:00. Two minutes later the parent says yes. What should it do?
Tap an action.

Let's read the calendar.

✏️ Practice 6.1

Remember:
Only a slot marked Free can be booked. Booked, Blocked and Leave slots can't.

Counselling slots, Tuesday 24 November

Counsellor11:0015:0018:00
AnandFreeFreeFree
DivyaFreeFreeBooked (Abdul)
MeeraFreeFreeFree
1. How many slots are free on 24 November?
2. A working parent can only talk at 18:00. How many counsellors are free then?
3. Divya is on leave on 19 and 20 November (both weekdays). How many of her slots does that take out?

Hand over to a person

Some chats need a person: money trouble, grief, refunds, complaints, or when the agent isn't sure. Passing the chat to a person is a handover.

A good handover includes a short note, so the counsellor knows the story and the family doesn't have to repeat it.

Which handover note would you want as the counsellor?
Tap a note.

What if the agent itself goes wrong?

Stop it going wrong

Tools sometimes fail or time out. An agent that simply tries again can book the same call twice.

An action that's safe to repeat, because doing it twice has the same effect as doing it once, is called idempotent. Make booking idempotent, and cap how many steps one message may take.

book_call timed out and the agent retried. Tom now has two bookings. What's the fix?
Tap a fix.

How many steps can it afford?

✏️ Practice 6.2

Remember:
reply time ≈ steps × time per step
1. Each step (a model call or a tool) takes about 2 seconds. A booking takes 3 steps. About how long until the reply, in seconds?
2. Northstar wants every reply within 10 seconds. What's the most steps one message can take?
3. 2,500 enquiries a month take 2.4 steps on average. How many steps is that a month?

Do it for real

Now build the agent that books calls. In the notebook it remembers the conversation, finds the real double booking in Northstar's calendar, and books without stealing anyone's slot.

You'll also make retries safe, hand a worried parent to a counsellor with a note, and add a step limit for when a tool breaks.

Build the booking agent in Google Colab

Colab runs Python in your browser for free. Replay mode needs no key. About 45 minutes.

Then check what stuck.

Lesson test

Five questions, all on new examples.

Question 1A gym wants an SMS sent the day before every class booking. Workflow or agent?
Question 2A hotel bot keeps asking for the guest's dates, which they gave three messages ago. What's missing?
Question 3A restaurant bot found a free table 5 minutes ago. The diner now says yes. What should it do?
Question 4On an insurance bot, someone writes that their husband just died and they need to claim. What should happen?
Question 5A payment tool times out and the agent retries. Which design is safe?

What's next?

This leaves a question
How do you prove it works before real people use it?
Lesson 7 answers it.