Twenty-seven lessons. Today: tie five together across three tools.
Given items = [{"id": "a", "value": 5}, {"id": "b", "value": 15}, {"id": "c", "value": 25}] and CONFIG = {"threshold": 10}:
id and value. Abort cleanly otherwise.add_event(summary) creates a calendar event and returns the id.value > threshold, add an event with summary f"alert-{id}".event_id for successes.summary event at the end with processed, skipped, failed counts.import json
CONFIG = {"threshold": 10}
items = [{"id": "a", "value": 5}, {"id": "b", "value": 15}, {"id": "c", "value": 25}]
def log(event, **fields):
print(json.dumps({"event": event, **fields}))
# 1. Pre-flight
errors = []
for i, it in enumerate(items):
if "id" not in it: errors.append((i, "missing id"))
if "value" not in it: errors.append((i, "missing value"))
if errors:
log("preflight", errors=errors)
raise ValueError(f"pre-flight failed: {len(errors)} errors")
# 2. Helper
def add_event(summary):
result = toolset.execute_action(Action.GOOGLECALENDAR_CREATE_EVENT, {
"calendar_id": "primary",
"summary": summary,
"start_datetime": "2026-12-31T10:00:00+00:00",
"event_duration_minutes": 15,
})
return result.get("response_data", {}).get("id") or result.get("id")
# 3-5. Loop with logging and summary
results = {"processed": 0, "skipped": 0, "failed": 0}
for it in items:
if it["value"] <= CONFIG["threshold"]:
results["skipped"] += 1
log("item", id=it["id"], status="skipped")
continue
try:
evt_id = add_event(f"alert-{it['id']}")
results["processed"] += 1
log("item", id=it["id"], status="ok", event_id=evt_id)
except Exception as e:
results["failed"] += 1
log("item", id=it["id"], status="failed", error=type(e).__name__)
log("summary", **results)Five primitives, three tools-worth of pattern, no new concepts.
Same shape every reliable automation has. Pre-flight before side effects. Helpers per tool. Per-item try/except. Structured logs. End-of-run summary. Once you can write this in one sitting on a 3-item input, you can write it on a 3000-item input — same skeleton, more entries in CONFIG, persistent dedup added on top.
| Primitive | Lesson | Used for |
|---|---|---|
| Pre-flight validation | Day 20 | abort if id or value missing on any item |
| Configuration | Day 19 | CONFIG["threshold"] instead of hardcoded 10 |
| Helper function | Day 27 | add_event(summary) hides Calendar plumbing |
| Conditional routing | Day 4 | if value > threshold decides path |
| Per-item try/except | Day 13 | partial failure handling |
| Structured logging | Day 14 | log("item", id=..., status=...) per outcome |
Six primitives in one ~30-line script.
Not in scope today (orthogonal, covered earlier or in Advanced):
results, not a Sheetadd_event in retry)A real production script would add all four. The skeleton stays the same; you'd insert each primitive at its natural seam:
add_eventseen = read_state(SHEET)) and before side effectitems = filter_since(items, last_run_ts)Foundations' synthesis (week 3 day 21) covered 4 primitives on 3 items with one tool. Patterns synthesizes 6 primitives on 3 items with the shape of multi-tool — even though the script touches one tool, the helper-per-tool shape and structured logging would scale identically to 3 or 5 tools.
The skill of week 4: write the skeleton automatically. Every primitive has a place; every place has a known idiom.
Twenty-seven lessons. Today: tie five together across three tools.
Given items = [{"id": "a", "value": 5}, {"id": "b", "value": 15}, {"id": "c", "value": 25}] and CONFIG = {"threshold": 10}:
id and value. Abort cleanly otherwise.add_event(summary) creates a calendar event and returns the id.value > threshold, add an event with summary f"alert-{id}".event_id for successes.summary event at the end with processed, skipped, failed counts.import json
CONFIG = {"threshold": 10}
items = [{"id": "a", "value": 5}, {"id": "b", "value": 15}, {"id": "c", "value": 25}]
def log(event, **fields):
print(json.dumps({"event": event, **fields}))
# 1. Pre-flight
errors = []
for i, it in enumerate(items):
if "id" not in it: errors.append((i, "missing id"))
if "value" not in it: errors.append((i, "missing value"))
if errors:
log("preflight", errors=errors)
raise ValueError(f"pre-flight failed: {len(errors)} errors")
# 2. Helper
def add_event(summary):
result = toolset.execute_action(Action.GOOGLECALENDAR_CREATE_EVENT, {
"calendar_id": "primary",
"summary": summary,
"start_datetime": "2026-12-31T10:00:00+00:00",
"event_duration_minutes": 15,
})
return result.get("response_data", {}).get("id") or result.get("id")
# 3-5. Loop with logging and summary
results = {"processed": 0, "skipped": 0, "failed": 0}
for it in items:
if it["value"] <= CONFIG["threshold"]:
results["skipped"] += 1
log("item", id=it["id"], status="skipped")
continue
try:
evt_id = add_event(f"alert-{it['id']}")
results["processed"] += 1
log("item", id=it["id"], status="ok", event_id=evt_id)
except Exception as e:
results["failed"] += 1
log("item", id=it["id"], status="failed", error=type(e).__name__)
log("summary", **results)Five primitives, three tools-worth of pattern, no new concepts.
Same shape every reliable automation has. Pre-flight before side effects. Helpers per tool. Per-item try/except. Structured logs. End-of-run summary. Once you can write this in one sitting on a 3-item input, you can write it on a 3000-item input — same skeleton, more entries in CONFIG, persistent dedup added on top.
| Primitive | Lesson | Used for |
|---|---|---|
| Pre-flight validation | Day 20 | abort if id or value missing on any item |
| Configuration | Day 19 | CONFIG["threshold"] instead of hardcoded 10 |
| Helper function | Day 27 | add_event(summary) hides Calendar plumbing |
| Conditional routing | Day 4 | if value > threshold decides path |
| Per-item try/except | Day 13 | partial failure handling |
| Structured logging | Day 14 | log("item", id=..., status=...) per outcome |
Six primitives in one ~30-line script.
Not in scope today (orthogonal, covered earlier or in Advanced):
results, not a Sheetadd_event in retry)A real production script would add all four. The skeleton stays the same; you'd insert each primitive at its natural seam:
add_eventseen = read_state(SHEET)) and before side effectitems = filter_since(items, last_run_ts)Foundations' synthesis (week 3 day 21) covered 4 primitives on 3 items with one tool. Patterns synthesizes 6 primitives on 3 items with the shape of multi-tool — even though the script touches one tool, the helper-per-tool shape and structured logging would scale identically to 3 or 5 tools.
The skill of week 4: write the skeleton automatically. Every primitive has a place; every place has a known idiom.
Create a free account to get started. Paid plans unlock all tracks.