← Lesson
The Dispatcher
Joeven
Run
Reset
Python loads on first run
def get_job(job_id): return {"job_id": job_id, "status": "ok"} def finish(answer): return {"final": answer} REGISTRY = { "get_job": get_job, "finish": finish, } def dispatch(name, args): if name not in REGISTRY: return {"error": "unknown_tool", "name": name} fn = REGISTRY[name] try: return {"ok": True, "result": fn(**args)} except TypeError: return {"error": "bad_args", "name": name} print(dispatch("get_job", {"job_id": 17})) print(dispatch("finish", {"answer": "done"})) print(dispatch("os.system", {"cmd": "rm -rf /"})) print("bound names", sorted(REGISTRY.keys()))
Run to execute this in your browser. Nothing is sent to a server.