Repository navigation
Known analysis procedures as documents the model fetches on demand (NEMAR first) - #720
Conversation
…em in the report (tested)
…ts; data lane reads them (tested)
…at can run code (tested)
… and the changelog
Preview Deployment
This preview will be updated automatically when you push new commits. |
…andled in procedure config (tested)
…r plan-first text (tested below)
…etic 10 Hz signal (tested)
|
Review round 1: outcomes (commits 2c759d4, db3db35, 6f43f0b, 21eb180 on this branch).
Tested: |
… before the behavioural checks (tested)
… when strerror is empty, make the reader public (tested)
…pt text unchanged)
|
Review round 2: outcomes
Tested: |
|
PM verdict: acceptance criteria checked against the diff and tests, both review rounds have outcomes, all checks pass (Lint, Test 3.11/3.12, Frontend Tests, Docker, docs build). Branch is up to date. Merging (squash). |
Plan consistency on develop after this PRRun on develop 0.8.20.dev36 (this PR plus its version bump),
What it shows:
Full reportNEMAR plan consistency (E2.5, #663)Deployment:
Caveats
Plans, run by runERP by condition (xx099904)
Band power (xx099906)
Epoch counts (xx099904)
Raw segment plot (xx099905)
Topography (xx099905)
Normalization rulesFirst match wins, top to bottom; title first, then detail.
|
Summary
A community can now declare known analysis procedures as Markdown documents that the model fetches on demand, so their text and code cost context only on the turns that use them.
NEMAR's four (power spectrum, band power, ERP by condition, ERP image by condition) moved out of its system prompt.
procedures: [{id, title, when, file}]onCommunityConfig(ProcedureConfig). Shape checks (slug id, unique ids, at most 20, one-linetitleandwhen,filethroughruntime_lock.relative_community_path_problem(path, '.md')) run in the model. Existence, containment (resolved, so a symlink cannot escape the folder), UTF-8, non-blank and the 32,000 character bound run inCommunityConfig.from_yaml, which reads each file once and holds the text in a private attribute. A config built any other way with procedures but no texts raises when the assistant is built.get_procedure(server tool,GET_PROCEDURE_TOOL_NAME) and a generated## Known proceduressection (id, title,when, and the rule: fetch beforepropose_plan, propose the document's steps as written, fill in only the specifics; a request that matches none uses the plan-first step rules). Both exist only when the community has procedures andexecute_codeis among the client tools built, so a quick turn and a widget that does not declare it get neither. The decision is stored on the assistant and read again byget_system_prompt(). The section namespropose_planonly when that client tool is bound, and otherwise says "before running code".get_procedureis listed in/{community}/metrics/publicavailable_tools_list.propose_plan;src/agents/plan_first.pyonly decides whether the text is sent.tests/test_api/test_procedures_gate.pyproves it through the real app: an analysis turn callsget_procedure, thenpropose_plan, the plan reaches the widget as atool_request, and the run parks with no browser run spent.plan_first_instructionsis untouched.src/assistants/nemar/procedures/*.md, each opening with its fixed plan (step titles, what each step's one run does, its memory behavior). Kept in the prompt: the runtime intro and first-figure paragraph, "Which channels", the whole "Events" bullet, the nm000132 worked example and the "give the recipe" line; only "the block below prints the count" now names the procedure documents. The plans use titles thatscripts/plan_consistency.normalize_stepmaps to spectrum > plot, spectrum > plot, load > filter > epoch > average > plot and load > filter > epoch > plot;RULESis unchanged. Band power is two steps, decided once in its header: the same Welch block and the integration over the bands run as one step. The integration (a 12 line block usingscipy.integrate.trapezoid) is the only code added.RunRecord.tools_before_plan(names oftool_startevents before the outcome), saved in the raw JSON, defaulted to[]byrecords_from_raw, shown as a report column.frontend/test-data-lane.jsandfrontend/browser-harness/spectrum-real-recording.mjsread their code fences from the documents; the data lane runs the same code. No new frontend test, so no workflow change.docs/community-widget.md, aproceduresrow in.context/yaml_registry.md. The docs.osc.earth registry reference lives in another repository and is not updated here.Refs #719
Refs #714
Prompt size
system_promptas the model gets it (CommunityAssistant.get_system_prompt()on the real NEMAR config with its MCP servers emptied, plus the quick-mode or plan-first text the router adds). Tokens are estimated as characters / 4.execute_codedeclared, tier quick)execute_code,get_full_output,propose_plandeclared)execute_codedeclaredThe config's own
system_promptstring went from 20,370 to 12,914 characters. A document costs its size only when fetched: 5,822 (power spectrum), 7,457 (band power), 4,443 (ERP by condition) and 5,712 (ERP image by condition) characters.One-off check: moved code fences are byte-identical
A scratch script (not committed) loaded
origin/develop:src/assistants/nemar/config.yaml, took every python fence of the old prompt dedented by its own indent, and compared the bytes with the fences in the new documents:The read snippet and the events
sample_indexsnippet stay in the prompt unchanged. The band integration block was also run once by hand over a synthetic 10 Hz signal (alpha mean 4.53 uV^2 against 4.5 expected). The consistency check was not run.Commands run
uv run python -c "...len(system_prompt)"before editing: 20370uv run pytest tests/test_core/test_config tests/test_agents tests/test_assistants tests/test_scripts tests/test_api/test_propose_plan.py tests/test_api/test_community_router.py -q: 1738 passed, 8 skippeduv run pytest tests/ -q -m 'not network and not llm' --cov=src: 6246 passed, 9 skipped, 144 deselected, 85% coverage; two failures that do not touch this change (see below)bun frontend/test-data-lane.js: 178 passed, 0 faileduv run ruff check . && uv run ruff format --check .: cleanTwo failures outside this change, seen locally on Python 3.14:
tests/test_core/test_llm_service.pydoes not collect (apydantic.v1error from the Langfuse import) and is ignored with--ignore, andtests/test_tools/test_hed_suggest.py::test_real_program_suggests_a_schema_tagfails because the external HED suggestion program reports an error.Notes for the reviewer
scripts/plan_consistency.py --repeats 4should show every request at 3 of 4 or better, and its new "Tools before the plan" column should showget_procedurebefore the plan for requests that match a procedure. That is why this PR saysRefs, notCloses.