← Lesson
Production Architecture
Joeven
Run
Reset
Python loads on first run
def handle_user(message, user, jobs, queue): # Gateway: authenticate (skipped), mint a job, enqueue, return fast. job = { "id": "job_" + str(len(jobs) + 1), "user": user, "goal": message, "status": "queued", "versions": {"worker": "sha-abc", "prompt": "p12", "model": "fake-small"}, } jobs[job["id"]] = job queue.append(job["id"]) return {"job_id": job["id"]} def worker_once(job_id, jobs, tools): # Worker: bounded slice, checkpoint, status. Not the HTTP handler. job = jobs[job_id] job["status"] = "running" obs = tools["search_kb"](job["goal"]) job["checkpoint"] = {"obs": obs} job["status"] = "succeeded" job["final"] = obs["text"] return job jobs, queue = {}, [] ack = handle_user("How long are refunds?", "u1", jobs, queue) print("GATEWAY", ack) print("QUEUE", queue) print("WORKER", worker_once(queue.pop(0), jobs, {"search_kb": lambda q: {"text": "5-7 days"}})) print("pieces: gateway, queue, worker, tools, job store")
Run to execute this in your browser. Nothing is sent to a server.