# Many agents writing code at once **🔵 Expert · Lesson 21** REAL CODEGEN, AND SEVERAL AGENTS DOING IT AT ONCE. Expert 12 drove the loop once, on one thread. This is the shape melder is actually built for: four agents, four rooms, one shared world, concurrent. HOW DATA COMES BACK OUT OF GENERATED CODE The executor runs the source in a controlled namespace and lifts ONE name out of it: code = "total = 0\nfor n in range(1, 101):\n total += n\n" "result = total\n" payload = commands.execute_codegen(code, frame_name=...) payload["result"] # 5050 `result` is the convention, not a guess - `CodegenExecutionResult` is built with `result=` taken from the namespace after the code runs. Anything else the code computed stays in the sandbox and dies with it. One name out means the boundary is a value, not a scope an agent can leak through. THE PAYLOAD IS A VERDICT, NOT A RETURN VALUE `accepted` and `frame_name` are always there; `reason`, `runtime_error`, `validation_issues` and `result` fill in according to what happened. So the SAME shape describes a refusal, a crash, and a success - an agent branches on `accepted` instead of catching, exactly as expert 12 established. FOUR AGENTS, FOUR ROOMS, ONE WORLD Each agent opens its OWN rift, so it gets its own room, its own workstation, and its own memory. What they SHARE is the target frame - the world their code lands in. That is the isolation melder actually offers: private benches, shared world. WHAT IS AND IS NOT SERIALIZED Nothing in this lesson opens a transaction, because generated code that computes a value mutates no structure. Melder serializes STRUCTURAL change; arithmetic in a sandbox is not structural, so four agents run genuinely in parallel and none of them waits. The moment one of them binds or links, the plane underneath arbitrates - and still none of this vocabulary appears in the agent's code. A ROOM'S MEMORY IS ITS OWN Subscribe on one room and you see that room's commands. The other three are running the same verbs at the same time and none of them appears in your log. Per-agent audit falls out of per-agent rooms rather than being a feature anyone had to add. ## Before you run Use the [Expert guide](../../expert/index.md) for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules. ## Run the saved script ```bash python UX_and_AIX_experiences/04_expert/21_many_agents_writing_code_at_once.py ``` ```powershell py -3.14t UX_and_AIX_experiences/04_expert/21_many_agents_writing_code_at_once.py ``` {download}`Download this collection <../../downloads/expert-examples.zip>` · [Source on GitHub](https://github.com/Synaptic724/melder/blob/0895ce795453cd87e35d70665957b4e89aad3317/UX_and_AIX_experiences/04_expert/21_many_agents_writing_code_at_once.py) ## Public surface several codegen rifts driven from threads, validate_codegen / execute_codegen payloads, the `result` namespace lift, and per-room memory ## Code ```{literalinclude} ../../downloads/04_expert/21_many_agents_writing_code_at_once.py :language: python :linenos: ``` ## Check the outcome The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here. [More expert examples](index.md) · [Level guide](../../expert/index.md) ## Related guides - [Several rooms and shared worlds](../../expert/concurrency.md) - [Complete operational walkthroughs](../../expert/walkthroughs.md)