DisSysLab · before the first class

Setting up

Install DisSysLab, run your first office, read what you ran, and get the key the labs need. You do not need to know anything about distributed systems to start; you need some Python and a terminal.

Time about 45 minutes You need Python 3.10 or later An API key only for step 5

This page is the short version. The full guide, GETTING_STARTED, has the same steps with every output shown, and more. If anything here surprises you, look there first.

Step 1A folder for the course

In a terminal (Terminal on macOS, PowerShell on Windows):

python3 --version
mkdir dsl_course
cd dsl_course
python3 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate

The first line should say Python 3.10 or higher. On Windows, type python instead of python3, here and below.

Every new terminal: cd into dsl_course and run the activate line again. If dsl is ever "command not found", this is almost always why.

Step 2Install it, and ask it whether it works

pip install dissyslab
dsl --version
dsl doctor

dsl --version should say dissyslab 2.0 or later. If it says 1.something, run pip install --upgrade dissyslab. The first line dsl doctor prints should be:

Ready. You can build an office.

If instead it says Not ready:, the rest of that line is the one thing to fix. The line under it says whether your API key is set. Until step 5 it says not set, and that is fine.

Step 3Run an office

An office is a small distributed system: agents that pass messages to each other. This one is a refund desk. It needs no key and no network.

dsl init returns_desk my_desk
cd my_desk
dsl check .
dsl run .

dsl init copies an office from the gallery into a folder of your own; always work on a copy. dsl check reads the office and reports every problem it can find without running anything:

my_desk/office.md:
  no problems found.

dsl run runs it. Four refund requests go through, and the office stops by itself:

[FileSource] Loaded 4 items from tickets.jsonl (jsonl)
[1] {'ticket_id': 'T1', 'customer': 'Ana', 'amount': 20, 'item': 'book', 'reason': 'wrong item', 'clerk_decision': 'approve'}
[2] {'ticket_id': 'T2', 'customer': 'Ben', 'amount': 120, 'item': 'chair', 'reason': 'damaged', 'clerk_decision': 'escalate', 'manager_decision': 'approve'}
[3] {'ticket_id': 'T3', 'customer': 'Cy', 'amount': 35, 'item': 'lamp', 'reason': 'changed mind', 'clerk_decision': 'approve'}
[4] {'ticket_id': 'T4', 'customer': 'Dee', 'amount': 80, 'item': 'monitor', 'reason': 'defective', 'clerk_decision': 'escalate', 'manager_decision': 'approve'}

Run summary (messages):
  my_desk::Clerk             sent      4   received      4
  my_desk::Gate              sent      4   received      8
  my_desk::Manager           sent      2   received      2
  my_desk::Rex               sent      4   received      4
  my_desk::console_printer   sent      0   received      4
  my_desk::jsonl_recorder    sent      0   received      4
  my_desk::tickets           sent      4   received      0

Once in a while two of the numbered lines come out in the other order. That is not a fault: the agents run at the same time, and either message can reach the screen first.

Step 4Read what you ran

Open office.md in any editor (VS Code is a good choice):

sources:
    tickets: file_source(path="tickets.jsonl")

sinks:
    jsonl_recorder(path="outcomes.jsonl")
    console_printer

agents:
    Gate: gate
    Clerk: clerk(limit=50)
    Rex: router(on="clerk_decision")
    Manager: manager

connections:
    tickets -> Gate -> Clerk -> Rex
    Rex.approve -> jsonl_recorder, console_printer, Gate.done
    Rex.escalate -> Manager -> jsonl_recorder, console_printer, Gate.done

That is the whole program. A source brings messages in; a sink writes them out; each agent has one job; the connections say who sends to whom. Each job is described in roles/: here two short Python files, clerk.py and manager.py. Other offices describe jobs as prompts, for an LLM to carry out. The lines between --- at the top of each are its contracts: what it may take in and send out, checked by DisSysLab on every message.

Change clerk(limit=50) to clerk(limit=100) and run it again. Then misspell a name on purpose and run dsl check . to see what it tells you. Breaking things on purpose is how you find the edges.

Step 5Your API key

The labs use a language model, Anthropic's Claude, which needs a key of your own. Each request costs a fraction of a cent.

  1. Go to console.anthropic.com, sign in, and create an API key. It starts with sk-ant-. Copy it: it is shown only once.
  2. Put it in a file called .env in your course folder. One file there serves every office inside it:
    cd ~/dsl_course                    # or wherever you made it
    echo "ANTHROPIC_API_KEY=paste-your-key-here" > .env
    Replace paste-your-key-here with your key, with no spaces or quotes. On a Mac, do not edit it in TextEdit, which saves rich text.
  3. Run dsl doctor in your course folder. The line under Ready. should now say:
      Key: ANTHROPIC_API_KEY is set.
Never share your key, and never commit .env to git. Anyone with the key can spend money on your account.

If it goes wrongThe usual ones

NextBuild one, then break one

ThenThe interesting part

Once your office runs you have a small distributed system you understand completely, because you wrote it. The questions that follow are the subject of the course. When one agent is wrong, or has been talked into something, how do you stop the harm from spreading through the rest? How does an office know it has finished, when no single agent can see the whole system? How do you photograph a system whose parts are all still moving, so you can restart from it after a crash? If agents wait on each other, how do you tell "still working" from "stuck forever"?

Those have real answers, they are decades old, and they are running inside the thing you just built.