← Forward Deployed Engineering Lesson 4 of 12

Building with LLMs

What a model call is

The admissions agent runs on a large language model, or LLM: a program trained on huge amounts of text that writes a likely reply to whatever you send it.

Your code sends it some text and gets text back. That's one model call.

The model reads and writes in small pieces of text called tokens, and you pay for every token in and out.

Step through one model call
  1. 1A parent messages: "wat is fees for full stack?"
  2. 2Your code sends the model your rules plus that message.
  3. 3The model writes a reply, one token at a time.
  4. 4Your code checks the reply and sends it on WhatsApp.

What rules does it need?

Write the rules

On its own, a model doesn't know Northstar's fees or rules. It fills the gaps with guesses that sound confident.

So every call starts with instructions it must follow: who it is, the facts it may use, and what it must never do. These are called the system prompt.

Switch rules on and see how the reply changes

But your code needs more than a friendly reply.

Answers your code can use

Your code has decisions to make: is this about fees, does it need a person? It can't read a paragraph reliably.

So you also ask the model for a few fields in a fixed shape, in a format called JSON. The code reads the fields, and the friendly reply is just one of them.

"My father passed away. We can't pay full fees. Any scholarship?" Which output is best?
Tap an output.

What does all this cost?

✏️ Practice 4.1

Remember:
In English, 1 token is about ¾ of a word, so tokens ≈ words ÷ 0.75
cost = tokens ÷ 1,000,000 × price per million tokens
1. Northstar's system prompt is 600 words. About how many tokens is that?
2. Each enquiry uses 1,500 tokens in total. Northstar gets 2,500 enquiries a month. How many tokens is that a month?
3. At an example price of $2 per million tokens, what does that cost a month, in dollars?

Prices change often, and differ between models. Always check the current price list before you quote a client.

Let the model use tools

The model can't see today's calendar. But your code can.

So you tell the model which functions it may ask for, like find_slots. When it needs one, it replies with a request instead of an answer. Your code runs the function and sends the result back.

A function the model can ask your code to run is called a tool.

Step through one tool call
  1. them"Any counselling slot on Saturday morning?"
  2. modelAsks for a tool: find_slots(day="Sat 21 Nov", part="morning")
  3. codeChecks the calendar: Anand 11:00, Divya 10:00 and 11:00, Meera 10:00.
  4. modelGets those slots back, and writes: "Yes! Saturday at 10:00 or 11:00. Which suits you?"

Which tool does each message need?

Pick the right tool

The admissions agent has three tools: get_fee reads the current fee sheet, find_slots reads the counselling calendar, and hand_to_human passes the chat to a counsellor.

Choosing well is the model's job, but you must know the right answer, so you can test that it chooses well.

Which tool should the agent use?

Ask twice, and you may get two different answers.

Same question, different answers

A model picks each token with a little randomness. A setting called temperature controls how much.

High temperature gives more varied, creative wording. Low temperature gives nearly the same answer every time.

For fees and bookings, you want the same correct answer every time.

Ask "fees for full stack?" three times
Temperaturelow

Now count the calls.

✏️ Practice 4.2

Remember:
Each tool result goes back to the model, so a reply that uses n tools takes n + 1 model calls
1. "What's the fee for Python & AI, and is there a slot on Monday?" The agent uses get_fee, then find_slots. How many model calls is that?
2. 1,000 messages a day. Half use one tool, half use none. How many model calls a day?
3. If each model call costs ₹0.10 (an example price), what do those calls cost a day, in rupees?

Do it for real

Now build it. In the notebook you'll call a real model, write Northstar's system prompt, ask for JSON your code can read, and give the agent two tools: get_fee and find_slots.

No account? Start in replay mode, which shows recorded answers. When you're ready, make a free Gemini key, or use a Claude or OpenAI key.

Build the agent's first version in Google Colab

Colab runs Python in your browser for free. You just need a Google account. About 45 minutes.

Then check what stuck.

Lesson test

Five questions, all on new examples.

Question 1A clinic's bot tells patients the wrong opening hours. What's the most likely cause?
Question 2Your code must decide whether to send a support email to the billing team. What should you ask the model for?
Question 3A month of chats uses 2,000,000 tokens. At $3 per million tokens, what does it cost?
Question 4A shop's bot needs to say whether a shoe is in stock right now. How should it find out?
Question 5Which temperature suits a bot that quotes insurance prices?

What's next?

This leaves a question
How does it answer from the client's own documents?
Lesson 5 answers it.