Week 1 — Lesson 5: Workflow patterns and limits

3 min

One model call is rarely a product. A diagnostic application at NorthPeak will classify an incident, then look up a count in SQLite, then open a manual. Those steps can be wired as a fixed chain, a router that picks a path, or a loop that repeats until the answer is ready. Every pattern runs on the same model, so every pattern has the same five limits.

Three patterns

A chain is a fixed sequence. The output of one step is the input of the next. Example: read an incident description, then summarise it, then translate the summary. Every run does the same three steps in the same order.

A router chooses one path among several. A first call reads the question and decides where it goes. "How many machines in Toronto?" goes to the database. "How do I fix a leaking pump?" goes to the manuals. You will build one in Week 12.

An agent loop repeats four moves until the goal is reached: perceive, think, act, observe. The agent reads the situation. It decides the next step. It calls a tool. It reads the result. Then it starts again. The loop stops when the answer is ready, or after a fixed number of turns.

Exercise 3 is one turn of this loop, written by hand. The model thinks and asks for count_machines. Your code acts. The model observes the result and answers.

Five limits

Every pattern runs on the same model. So every pattern has the same limits. Know them before you build anything.

LimitWhat it meansWhat you saw or will see
HallucinationThe model invents a confident answer27 machines in Brampton, in Exercise 2
Context windowThe model forgets what does not fit in the windowollama show says 131,072 tokens; Ollama uses 4,096 by default
Non-determinismThe same question can give different answersNova then Zeta at temperature 1
CostEvery call takes time, memory or moneyAbout one second per answer on our laptop, after the first load
No memory between callsEach call starts from zeroSee below

The last one surprises everyone. We told the model "My favourite machine is M007." Then, in a new call, we asked "What is my favourite machine?" Its answer:

text
I don't have any information about your preferences or interests. I'm a large language
model, I don't have the ability to know your personal preferences or opinions. Each time you
interact with me, it's a new conversation and I don't retain any information from previous
conversations.

The model is right. Memory is not in the model. It is in your code. If you want the model to remember, you send the earlier messages again in the next call. That is what the assistant role is for.

On the NorthPeak application

NorthPeak has 155 incident descriptions. A chain can classify each one. A router can send count questions to machines.csv and repair questions to the manuals in docs/manuals. An agent loop can read a reading, call a model that predicts fault_next_7d, then look up the manual for that machine type. Every one of these needs the five limits handled: a tool for the facts, a window that fits, temperature 0, a time budget, and a history you keep yourself.

A common mistake

Beginners jump to the agent loop because it sounds smart. A loop is the hardest pattern to debug. It can run forever. It can call the wrong tool. Start with a chain. Add a router when you have two kinds of questions. Add a loop only when the number of steps is unknown in advance. Always set a maximum number of turns.