Step-by-step course guide
Audience: developers learning multi-agent orchestration before (or alongside) AI-Factory.
Languages:COURSE_LANG=en|ru|es|fr|zh· UI strings ini18n/· this guide in English. Русский · Español · Français · 中文
Check against the current ecosystem
The Python labs teach orchestration patterns with deterministic inputs. For a current Hub path, open HEPHAESTUS Studio, inspect a proposed graph and its catalogue estimate before running it, then compare an authorized run’s per-step costs and signed bill of materials. Record which steps returned evidence. A catalogue estimate can change before execution.
Table of contents
- Choose your track
- Setup (10 minutes)
- Module M1 — Agent loop & tool use
- Module M2 — Topologies
- Module M3 — Handoffs & delegation
- Module M4 — Discovery & invocation
- Module M5 — State, memory, context
- Module M6 — Guardrails & safety
- Module M7 — Trust, verification, provenance
- Module M8 — Economics of orchestration (advanced)
- Optional LLM demo (Module M1)
- Exercises & certificate
- Module M9 — Observability in every lab
- Bridge: from course to AI-Factory
- Self-check checklist
- Troubleshooting
Choose your track
| Track | Modules | Time | LLM | Hub |
|---|---|---|---|---|
| Basic | M1 → M2 → M3 → M4 | ~2 h | No | Sandbox only in M4 |
| Advanced | Basic + M8 | +1 h | Optional | Embedded sandbox hub |
| Factory bridge | After M4 or M8 | +30 min | Yes (your keys) | Real factory + Hub |
Read M9 after each lab — every script prints a Trace you can inspect.
Setup (10 minutes)
Step 1 — Clone and install
git clone https://github.com/alexar76/aimarket-courses.git
cd aimarket-courses/orchestration-course
pip install -e ".[dev]"
For economy labs (M4 sandbox, M8):
pip install -e ".[sandbox,dev]"
Step 2 — Verify tests
pytest -q
Expected: all tests pass (i18n parity, orchestration primitives, economy helpers).
Step 3 — Pick a language (optional)
export COURSE_LANG=ru # or es, default en
python labs/lab01_agent_and_tool.py
Step 4 — Colab alternative
- Open course site → Open in Colab on any lab.
- Run the setup cell (clone + pip).
- Set
os.environ["COURSE_LANG"] = "ru"in setup if needed. - Run the lab cell.
Module M1 — Agent loop & tool use
Concept: An agent is a policy that decides which tool to call.
Lab: labs/lab01_agent_and_tool.py · Time: ~15 min · Prerequisites: setup done
Steps
-
Open
labs/lab01_agent_and_tool.pyand read the module docstring (industry map: MCP, function calling). -
Run locally:
python labs/lab01_agent_and_tool.py -
Watch the output for two tasks (translate / summarize). Each shows:
- chosen tool name
- result string
- trace block at the end
-
Change
COURSE_LANGand re-run — task text changes; tool mapping includes RU/ES keywords. -
Open
courselib/orchestration.py— findAgent,Tool,Trace,keyword_policy(5 min skim).
Expected output (EN)
- Line
== Agent loop & tool use == - Two task/result pairs
- Trace with
eventslisting tool invocations
Self-check
- [ ] You can explain: policy → tool → result → trace event
- [ ] You see why the lab uses no LLM (deterministic policy for teaching)
Module M2 — Topologies
Concept: Sequential, parallel, and routing — shapes of multi-agent flows.
Lab: labs/lab02_topologies.py · Time: ~20 min · Prerequisites: M1
Steps
- Run
python labs/lab02_topologies.py. - Identify three sections in output: sequential, parallel, router.
- Read the
Traceblock the lab prints at the end — the orchestration is logged, not magic. - Contrast the shapes in the trace: ordered
pipeline_stageevents (sequential) vs thefanout/gatherpair (parallel) vs a singleroute(router).Parallelhere is deterministic (no real threads) — the distinction is structural, visible in the events, not in wall-clock. - Edit the router keywords in the lab (optional) — add one route and re-run.
Self-check
- [ ] Sequential = A then B
- [ ] Parallel = A and B without waiting for each other
- [ ] Router = one branch chosen by policy
Module M3 — Handoffs & delegation
Concept: Transferring control to a specialist agent, bounded against loops.
Lab: labs/lab03_handoff.py · Time: ~20 min · Prerequisites: M2
Steps
- Run
python labs/lab03_handoff.py. - Find tasks that delegate to
legalvs stay onassistant. - Read trace handoffs section — who handed off to whom.
- Find the loop guard (max handoffs) in
courselib/orchestration.pyif curious.
Self-check
- [ ] Delegation happens when policy returns
delegate:<agent> - [ ] Loop guard prevents infinite ping-pong
Module M4 — Discovery & invocation
Concept: Finding and calling capabilities across a federated hub.
Lab: labs/lab04_discover_invoke.py · Time: ~20 min · Prerequisites: [hub-lite] (~5 MB)
Steps
- Install:
pip install -e ".[hub-lite,dev]". - Run
python labs/lab04_discover_invoke.py— hub-lite starts in ~2 s. - Note output: discover → capability list → invoke → result + receipt nonce.
- Cross-read: hub-integration-guide.md § discovery.
Self-check
- [ ] Discovery returns capability metadata (id, price)
- [ ] Invoke returns a structured result + receipt
Module M5 — State, memory, context
Lab: labs/lab05_state_context.py · Time: ~20 min · Prerequisites: M2
Steps
- Run
python labs/lab05_state_context.py. - Watch the Context bag grow:
brief→plan→artifacts→summary. - Read trace
context_stageevents — keys after each stage. - Exercise: extend the pipeline (see lab footer). Check:
python labs/run_exercises.py --module m5.
Module M6 — Guardrails & safety
Lab: labs/lab06_guardrails.py · Time: ~20 min
Steps
- Run
python labs/lab06_guardrails.py. - Compare safe task vs injection attack — note
guardrail_blockin trace. - Exercise: add a guardrail blocking
SECRET. Check:python labs/run_exercises.py --module m6.
Module M7 — Trust, verification, provenance
Lab: labs/lab07_receipt_verify.py · Time: ~25 min · Prerequisites: [hub-lite]
Steps
- Run
python labs/lab07_receipt_verify.py. - Valid receipt →
True; tampered price →False. - Skim
courselib/trust.py— HMAC signing (stdlib, same idea as production). - Exercise:
python labs/run_exercises.py --module m7.
Module M8 — Economics of orchestration (advanced)
Concept: Payment channels, escrow, revenue routing for paid calls.
Lab: labs/lab08_metered_economy.py · Time: ~45 min · Prerequisites: [sandbox] (~50 MB, install once)
Steps
- Install once:
pip install -e ".[sandbox,dev]"(Colab: reuse session if lab04/07 already ran). - Run
python labs/lab08_metered_economy.py. - Follow output: channel → invoke(s) → total spent → receipt.
- Read ai-market-protocol-v1.md § HTTP 402 and channels.
Self-check
- [ ] You can name: discover → pay → invoke → receipt
- [ ] Channel amortizes multiple calls vs per-call 402
Optional LLM demo (Module M1)
Default labs stay deterministic for reproducible learning. To see the same tool-routing pattern with a real model:
export USE_LLM=1
export OPENAI_API_KEY=sk-...
python labs/lab01_agent_and_tool.py
The policy calls an OpenAI-compatible API (LLM_BASE_URL, LLM_MODEL optional).
Exercises & certificate
After labs, run DIY checks:
python labs/run_exercises.py
python labs/run_exercises.py --certificate "Your Name" --lang ru
Opens certificate.html — print to PDF from the browser. Credential ID is derived from name + date.
Module M9 — Observability in every lab
Concept: Tracing multi-agent runs so behaviour is inspectable.
Covered in: every lab via Trace · Time: 5 min after each lab
Steps (repeat after M1–M4, M8)
- Scroll to trace section in lab output.
- Count
events— map each to a step you saw in stdout. - Compare M2 sequential vs parallel event ordering.
- Production path: observability-langsmith.md — factory OTel + LangSmith (not required for course).
Self-check
- [ ] Trace is the lab’s “unit test log” for agent behaviour
- [ ] You can correlate one failed invoke to one trace event
Live hub: the same calls on modelmarket.dev
Set COURSE_HUB_URL=https://modelmarket.dev and use courselib.economy.connect() instead of embedded_sandbox(): discover, invoke and hire run against the live federation. Priced calls need payment there — get a key at modelmarket.dev/start, top it up with USDC (from $0.01) and set COURSE_API_KEY=aimk_…; it travels as X-API-Key and each call is paid from the prepaid balance. Without a key a priced call answers payment_required and lists the ways to pay.
Bridge: from course to AI-Factory
Goal: Run the same patterns on the full factory pipeline (~30 min).
-
Start factory (from monorepo root):
docker compose up -d app # → http://localhost:9080 -
Guest landing — homepage phrase box → get
prod-…→/product/{id}. -
Admin path — USER_GUIDE.md § “Your first 15 minutes”:
/admin/login- New product → submit idea
- Pipeline → watch stage strip (real agents, not course stubs)
-
Map course → factory
Course Factory M1 tool loop Developer + QA tool calls M2 topologies Pipeline stage graph M3 handoffs Agent handoff audit log M4 discover/invoke Hub catalog + /ai-market/v2/invokeM8 economy Hub channels + storefront checkout M9 trace Pipeline telemetry + Live Monitor -
List on Hub — ecosystem-architecture.md — product → capability → invoke.
Self-check checklist
After the basic track you should be able to:
- [ ] Run all of lab01–lab04 locally and in Colab
- [ ] Explain sequential vs parallel vs router with trace evidence
- [ ] Describe discover → invoke without opening HTTP docs
- [ ] Read a
Traceblock and find the failing step - [ ] Name where factory pipeline extends M1–M4 (optional bridge)
After the advanced track add:
- [ ] Run lab08 and explain channel + receipt
- [ ] Open
ai-market-protocol-v1.mdand find 402 flow
Troubleshooting
| Problem | Fix |
|---|---|
ModuleNotFoundError: courselib |
Run from repo root; labs prepend parent to sys.path |
| M4/M8 hang on start | Wait for embedded hub; check port not in use |
[sandbox] install fails |
Need git + network for GitHub deps |
| Empty RU/ES strings | Set COURSE_LANG; check i18n/ru.json keys match en.json |
| pytest i18n failure | Add missing keys to all three JSON files |
| Colab old code | Re-run setup cell; pin main branch |
Factory issues: FAQ.md
Regenerate site & notebooks
After editing labs or i18n:
python3 scripts/build_course_assets.py
Guides in docs/ are hand-maintained — update EN first, then RU/ES mirrors.