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.
- 1A parent messages: "wat is fees for full stack?"
- 2Your code sends the model your rules plus that message.
- 3The model writes a reply, one token at a time.
- 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.
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.
What does all this cost?
✏️ Practice 4.1
In English, 1 token is about ¾ of a word, so tokens ≈ words ÷ 0.75
cost = tokens ÷ 1,000,000 × price per million tokens
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.
- them"Any counselling slot on Saturday morning?"
- modelAsks for a tool:
find_slots(day="Sat 21 Nov", part="morning") - codeChecks the calendar: Anand 11:00, Divya 10:00 and 11:00, Meera 10:00.
- 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.
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.
Now count the calls.
✏️ Practice 4.2
Each tool result goes back to the model, so a reply that uses n tools takes n + 1 model calls
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.
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.