Shared notes and handoffs
The chat gets long
So far, a bot reads the whole chat before every reply. A week of jobs at Amal Designers can mean 300 messages. If a message is about 25 words, that's 300 × 25 = 7,500 words to read, for every single reply. That's slow, it costs money, and important details get lost in the middle.
whole chat: every reply reads every message
What does a bot really need to know?
A shared board
Mostly, a bot needs to know what the jobs are, who has each one, and how far along it is. So the team keeps a board, like a to-do list on a wall: one line per task, with its owner and its status: todo (not started), doing, or done.
board = one line per task: task · owner · status
The board is short. Can a bot read it instead of the whole chat?
Read less
Now a bot reads its instructions, the board, and only the last few messages, however long the chat gets. How many is set by the window. With the headings, that's:
lines = tasks + window + 6
3 tasks, window 3 → 3 + 3 + 6 = 12 lines, even with 300 messages in the chat.
Why 6? The instructions, an empty line, Board:, another empty line, Last messages:, and the bot's name.
Count it on new numbers.
✏️ Practice 4.1
Remember:
whole chat: every reply reads every message
lines = tasks + window + 6
Who updates the board, and how?
Handoffs
When a bot finishes its part, it ends its reply with a handoff line, like HANDOFF to Production: check sizes 1 to 8. The program reads that line and does three things: the bot's own task becomes done, Production's next task becomes doing, and Production writes next.
HANDOFF to X → my task done, X's task doing, X writes next
Could one bot mark another bot's task done?
Only your own task
A handoff only ever closes the writer's own doing task. So a bot can't mark someone else's work as done. And when the handoff goes to CEO, or a reply has no handoff line at all, no bot is next: the chat waits for the CEO.
a bot can only close its own task
Try it on new boards.
✏️ Practice 4.2
Remember:
HANDOFF to X → my task done, X's task doing, X writes next
a bot can only close its own task
Handed to the CEO, or no handoff line: wait for the CEO.
todo. Marketing starts. It hands off to Production, who hands off to Operations. Operations replies but forgets its HANDOFF line. How many tasks are done?doing at the end?HANDOFF to Production: done with your check too!. How many of Production's tasks are done after this?Real LLMs don't always write the line just right.
A real LLM
In Colab, real bots write their own handoffs. The program only accepts a line that starts with exactly HANDOFF to and a bot's name. Anything else isn't a handoff: the chat waits for the CEO, and the board shows where the work stopped.
no exact HANDOFF line → wait for the CEO
That's useful, not just strict: a task stuck at doing tells the CEO exactly which bot to check.
Here's all of it in Python.
The code
Guess what each print shows. Then press ▶ Run.
# The board: one dictionary per task. What, who owns it, and its status.
board = []
def add_task(task, owner):
board.append({"id": len(board) + 1, "task": task, "owner": owner, "status": "todo"})
def show_board():
lines = []
for t in board:
lines.append(f'{t["id"]}. {t["task"]} | {t["owner"]} | {t["status"]}')
return "\n".join(lines)
add_task("Write the post", "Marketing")
add_task("Check sizes and stock", "Production")
add_task("Book the courier", "Operations")
print(show_board())
# The chat, as before
chat = []
def post(who, text):
chat.append({"who": who, "text": text})
print(f"{who}: {text}")
BOTS = ["Marketing", "Production", "Operations"]
INSTRUCTIONS = {
"Marketing": "Write the Instagram post. When done, write: HANDOFF to Production: what to check",
"Production": "Check sizes and stock. Catalogue: pastel frock, sizes 1 to 8 years, 6 ready on Friday. When done, write: HANDOFF to Operations: what is ready",
"Operations": "Book the courier. When done, write: HANDOFF to CEO: what you booked",
}
# What a bot reads now: its instructions, the board, and only the last few messages
WINDOW = 3
def text_for(name):
lines = [INSTRUCTIONS[name], "", "Board:", show_board(), "", "Last messages:"]
for m in chat[-WINDOW:]: # chat[-3:] is the last 3 messages
lines.append(m["who"] + ": " + m["text"])
lines.append(name + ":")
return "\n".join(lines)
# Find a bot's task with a given status, or None if it has none
def task_of(name, status):
for t in board:
if t["owner"] == name and t["status"] == status:
return t
return None
# A handoff line moves the work on: my task is done, the next bot's task starts
def handoff(name, reply):
for line in reply.split("\n"):
if line.startswith("HANDOFF to "):
to = line.split(":")[0].replace("HANDOFF to ", "")
mine = task_of(name, "doing")
if mine is not None:
mine["status"] = "done"
if to in BOTS:
nxt = task_of(to, "todo")
if nxt is not None:
nxt["status"] = "doing"
return to
return None # handed to the CEO: wait
return None # no handoff line: wait for the CEO
# Fake LLM replies
replies = {
"Marketing": ["Caption: “Twirl-ready pastel frock 💫 Sizes 1 to 8 years.”\nHANDOFF to Production: check sizes 1 to 8"],
"Production": ["Sizes 1 to 8 are right. 6 frocks ready on Friday.\nHANDOFF to Operations: 6 frocks, Friday"],
"Operations": ["Courier pickup booked for Saturday, 4 PM.\nHANDOFF to CEO: pickup Saturday 4 PM"],
}
def fake_llm(name, text):
return replies[name].pop(0)
# The loop: whoever got the handoff writes next
def run(first, turn_limit=6):
name = first
task_of(name, "todo")["status"] = "doing"
for i in range(turn_limit):
reply = fake_llm(name, text_for(name))
post(name, reply)
name = handoff(name, reply)
if name is None:
return "Waiting for the CEO."
return "Stopped: the turn limit was reached."
print(run("Marketing"))
print(show_board())
$ python lesson4.py
1. Write the post | Marketing | todo
2. Check sizes and stock | Production | todo
3. Book the courier | Operations | todo
Marketing: Caption: “Twirl-ready pastel frock 💫 Sizes 1 to 8 years.”
HANDOFF to Production: check sizes 1 to 8
Production: Sizes 1 to 8 are right. 6 frocks ready on Friday.
HANDOFF to Operations: 6 frocks, Friday
Operations: Courier pickup booked for Saturday, 4 PM.
HANDOFF to CEO: pickup Saturday 4 PM
Waiting for the CEO.
1. Write the post | Marketing | done
2. Check sizes and stock | Production | done
3. Book the courier | Operations | doneThe notebook has all of this, then real bots writing their own handoffs. Its first run downloads the model (about 3 GB), so it takes a few minutes. You just need a Google account.
Quick check: did it all make sense?
Lesson 4 test
5 questions, one for each idea in this lesson. Answer them all right to pass. A wrong answer tells you why, and which page to look at again.
HANDOFF to Operations: 6 frocks, Friday. What happens?Passing this to Operations now. What happens?What the team still can't do.
Tools from outside
Your team now keeps track of its work. But each bot only has the tools you wrote yourself. Amal Designers also lives in Instagram, WhatsApp, a spreadsheet of orders and a courier's website. Writing a tool for each one, for every bot, would never end.
I'd love to read the real order sheet. Do you have to write that tool from scratch?