Skip to content

Commit 89102c8

Browse files
committed
docs(comses-plan): tighten v5 per reviewer round 4
1 parent 0ae42c2 commit 89102c8

1 file changed

Lines changed: 42 additions & 13 deletions

File tree

docs/COMSES_PLAN.md

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,36 @@ async def open_comses_model(
332332
version: Version string or 'latest'.
333333
max_mb: Max download size cap.
334334
335-
Returns:
336-
- NetLogo case: "Loaded NetLogo model: <filename> (cached)" or "(downloaded)"
337-
- Non-NetLogo case: structured JSON, see below.
335+
Returns structured JSON in both NetLogo and non-NetLogo cases. See
336+
shapes below. Always includes `resolved_version` so the caller can
337+
pass it back into `read_comses_files` and guarantee it inspects the
338+
same cache slot that was just opened.
338339
"""
339340
```
340341

341342
This is the **single entry point** for "I want this model ready to use." It subsumes downloading. Users who want to download without opening can call `download_comses_model` directly; most AI flows will call this tool.
342343

344+
The NetLogo response shape:
345+
346+
```json
347+
{
348+
"status": "loaded_netlogo",
349+
"resolved_version": "1.2.0",
350+
"loaded_netlogo_file": "code/WolfSheep_3.0.nlogo",
351+
"all_netlogo_files": ["code/WolfSheep_3.0.nlogo", "code/WolfSheep_2.0.nlogo"],
352+
"extracted_path": "models/comses/{uuid}/1.2.0/",
353+
"cached": true,
354+
"language": "NetLogo",
355+
"title": "Wolf Sheep Predation"
356+
}
357+
```
358+
359+
Callers (including the `explore_comses` prompt) must read `resolved_version`
360+
from this response and pass that concrete string into every subsequent
361+
`read_comses_files` call. Never re-pass `"latest"``"latest"` could resolve
362+
to a newer version published between calls, causing the AI to inspect a
363+
different cache slot than the model it just loaded.
364+
343365
#### Selecting which NetLogo file to load (when the archive has more than one)
344366

345367
Some COMSES archives contain multiple `.nlogo` / `.nlogox` files (e.g.,
@@ -364,9 +386,11 @@ The non-NetLogo response shape:
364386
```json
365387
{
366388
"status": "not_runnable_in_netlogo",
389+
"resolved_version": "1.0.0",
367390
"language": "Python (Mesa)",
368391
"title": "SIR Epidemic Model",
369-
"extracted_path": "models/comses/{uuid}/{resolved_version}/",
392+
"extracted_path": "models/comses/{uuid}/1.0.0/",
393+
"cached": false,
370394
"code_files": ["code/model.py", "code/agents.py"],
371395
"odd_doc": "docs/ODD.md",
372396
"message": "This model is in Python, not NetLogo. The source is saved locally. You can read it with the read_comses_files tool if you want to understand or adapt it. Translating it to NetLogo is possible but not automatic — ask explicitly if that's what you want."
@@ -489,10 +513,13 @@ def explore_comses(topic: str) -> list[Message]:
489513
The prompt instructs the AI to:
490514
1. Search COMSES for models matching the topic; prefer peer-reviewed + NetLogo-tagged.
491515
2. Show the user the top match with title, authors, description, **citation text**.
492-
3. Call `open_comses_model`.
516+
3. Call `open_comses_model`. **Capture `resolved_version` from the JSON
517+
response** and reuse it for every subsequent `read_comses_files` call in
518+
this flow. Never pass `"latest"` again after this point — doing so risks
519+
re-resolving to a newer version than the one just loaded.
493520
4. If the model is NetLogo (happy path):
494-
a. Call `read_comses_files` with `extensions=[".nlogo", ".nlogox"]` to
495-
get the source content of whichever variant was loaded. Always include
521+
a. Call `read_comses_files(version=resolved_version, extensions=[".nlogo", ".nlogox"])`
522+
to get the source content of whichever variant was loaded. Always include
496523
both extensions — Section 4.4 may have selected an `.nlogox` file.
497524
b. Scan the source for `to <name>` procedure names and `to-report <name>` reporters (treat the latter as candidates for plausible state metrics; the AI cannot reliably classify utility reporters every time, and that's accepted for v1).
498525
c. **Fallback if nothing useful is found:** if no procedure with a name resembling `setup` / `initialize` / `start` exists, OR no candidate reporters are found, **stop after loading.** Do not force-run commands the model doesn't define. Report the discovered procedures/reporters (if any) and ask the user which to run.
@@ -501,7 +528,9 @@ The prompt instructs the AI to:
501528
f. Summarize results, referencing the ODD doc content obtained via `read_comses_files`.
502529
5. If not NetLogo:
503530
a. The `open_comses_model` call already downloaded and extracted the archive.
504-
b. Call `read_comses_files` to get the ODD doc and a summary of what the model does.
531+
b. Call `read_comses_files(version=resolved_version, ...)` — using the
532+
`resolved_version` captured in step 3 — to get the ODD doc and a
533+
summary of what the model does.
505534
c. State the language clearly, show citation, summarize the ODD findings, and stop.
506535
d. Do not auto-translate. If the user later explicitly asks to translate, see "On Translation" below.
507536

@@ -689,18 +718,18 @@ Server (happy path, NetLogo model):
689718
1. `search_comses("rumor spreading")` → N matches.
690719
2. AI picks a top peer-reviewed NetLogo match.
691720
3. `get_comses_model(uuid)` → AI presents title, authors, **citation text**, license.
692-
4. `open_comses_model(uuid)` → resolves `"latest"` to concrete version, downloads safely (or uses cache), extracts, picks the right `.nlogo` file per Section 4.4 rules, loads it into NetLogo.
693-
5. `read_comses_files(uuid, extensions=[".nlogo", ".nlogox"])` → AI reads the actual source (whichever variant was loaded per Section 4.4) to **discover** real procedure names and reporters. **The AI does not fabricate commands.**
721+
4. `open_comses_model(uuid)` → resolves `"latest"` to concrete version, downloads safely (or uses cache), extracts, picks the right `.nlogo` file per Section 4.4 rules, loads it into NetLogo. Returns JSON with `resolved_version` (e.g. `"1.2.0"`). **The AI pins this value and reuses it in every later call below.**
722+
5. `read_comses_files(uuid, version=resolved_version, extensions=[".nlogo", ".nlogox"])` → AI reads the actual source (whichever variant was loaded per Section 4.4) to **discover** real procedure names and reporters. **The AI does not fabricate commands.**
694723
6. **Branch based on discovery:**
695724
- **Plausible setup + useful reporters found:** `command("<discovered setup>")`. If that call returns an error, **stop and ask the user** — do not guess alternates. Otherwise → `run_simulation(<N ticks>, [<discovered reporters>])``export_view()`.
696725
- **No plausible setup OR no useful reporters found:** stop after loading. Report to the user what was found (maybe just `setup` with no reporters, or an unusual procedure name). Ask which procedure to run or whether they want to inspect the source first.
697-
7. `read_comses_files(uuid, extensions=[".md", ".txt"], max_total_bytes=50000)` → AI reads the ODD doc and summarizes what the model demonstrates.
726+
7. `read_comses_files(uuid, version=resolved_version, extensions=[".md", ".txt"], max_total_bytes=50000)` → AI reads the ODD doc and summarizes what the model demonstrates.
698727

699728
Non-NetLogo model flow:
700729
1. `search_comses("rumor spreading")` → top match is Python.
701730
2. `get_comses_model(uuid)` → citation text + metadata.
702-
3. `open_comses_model(uuid)` → downloads + extracts (but does NOT load NetLogo). Returns the non-NetLogo JSON with language, code paths, ODD doc path.
703-
4. `read_comses_files(uuid, extensions=[".md", ".txt"])` → AI reads the ODD doc.
731+
3. `open_comses_model(uuid)` → downloads + extracts (but does NOT load NetLogo). Returns the non-NetLogo JSON with `resolved_version`, language, code paths, ODD doc path. **The AI pins `resolved_version` for reuse.**
732+
4. `read_comses_files(uuid, version=resolved_version, extensions=[".md", ".txt"])` → AI reads the ODD doc.
704733
5. AI reports: "This model is in Python (Mesa). It was downloaded to models/comses/... and I read the ODD documentation — here is a summary: [...]. I can explain the source code, or, if you explicitly ask, translate it to NetLogo (approximately). Otherwise we stop here."
705734
6. Flow stops unless user asks to translate.
706735

0 commit comments

Comments
 (0)