← Build an AI Team Lesson 4 of 12

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.

Make the chat longer. Watch what one reply costs.

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

Tap a status to move a task along.

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.

Pick a window. See what Production reads.

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

Work each one out. Type the answer, press Check.
A chat has 200 messages of about 20 words. How many words does one reply read, if the bot reads the whole chat?
The board has 5 tasks. The window is 4. How many lines does a bot read?
Same board and window, but now the chat has 500 messages. How many lines does a bot read?
A bot reads 13 lines. The board has 4 tasks. How big is the window?

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

Step through. Watch the board.

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

The board, before. What happens after each reply? Pick one.

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.

Work each one out. Type the answer, press Check.
3 tasks, all 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?
Same run. How many tasks are doing at the end?
Marketing writes HANDOFF to Production: done with your check too!. How many of Production's tasks are done after this?
4 bots, one task each, in a chain: Marketing → Production → Operations → Analyst → CEO. Every handoff works. How many bot replies are posted?

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

Production's last line, in example replies made for this page. Does the work move on?

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())

The 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.

1. WhyWhy not let every bot read the whole chat?
2. Count6 tasks, a window of 2, and 400 messages in the chat. How many lines does a bot read?
3. PredictProduction writes HANDOFF to Operations: 6 frocks, Friday. What happens?
4. Spot the mistakeA friend says: “Operations can mark Production's task done by writing a handoff.” What's wrong?
5. PredictA real Production bot ends with: 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?

This leaves a question
Your bots only use tools you wrote. How do they plug into everything else?
Lesson 5 answers it.
For your business: write the board for one real job. 3 to 5 tasks, each with its owner bot. Then write the first handoff line.