gemot 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gemot/__init__.py +103 -0
- gemot/ablations.py +321 -0
- gemot/agent/__init__.py +122 -0
- gemot/agent/barebones.py +459 -0
- gemot/agent/biocurator.py +250 -0
- gemot/agent/circuit_breaker.py +1037 -0
- gemot/agent/claude.py +142 -0
- gemot/agent/cli_mcp.py +335 -0
- gemot/agent/cli_process.py +224 -0
- gemot/agent/cli_tracing.py +530 -0
- gemot/agent/codex.py +169 -0
- gemot/agent/dedup.py +61 -0
- gemot/agent/driver.py +1981 -0
- gemot/agent/finish_gate.py +794 -0
- gemot/agent/fit_cost.py +113 -0
- gemot/agent/guards.py +991 -0
- gemot/agent/literature.py +166 -0
- gemot/agent/mcp_tools.py +72 -0
- gemot/agent/native_cli.py +202 -0
- gemot/agent/probe.py +230 -0
- gemot/agent/provider_refusals.py +90 -0
- gemot/agent/sandbox.py +317 -0
- gemot/agent/subagents.py +308 -0
- gemot/agent/thinking.py +392 -0
- gemot/agent/token_usage.py +309 -0
- gemot/agent/tools.py +224 -0
- gemot/agent/uniprot.py +133 -0
- gemot/analysis.py +1159 -0
- gemot/bio_cache.py +242 -0
- gemot/bio_sessions.py +512 -0
- gemot/biology_blinding.py +415 -0
- gemot/causal_constraints.py +709 -0
- gemot/experiments.py +750 -0
- gemot/explorer/__init__.py +13 -0
- gemot/explorer/__main__.py +59 -0
- gemot/explorer/archive.py +235 -0
- gemot/explorer/bundle.py +892 -0
- gemot/explorer/server.py +163 -0
- gemot/explorer/static/app.css +216 -0
- gemot/explorer/static/app.js +1027 -0
- gemot/explorer/templates/index.html +97 -0
- gemot/explorer/templates/run.html +43 -0
- gemot/fit_budget.py +240 -0
- gemot/infrastructure.py +206 -0
- gemot/metrics.py +794 -0
- gemot/models.py +418 -0
- gemot/neural_ode/__init__.py +7 -0
- gemot/neural_ode/__main__.py +332 -0
- gemot/neural_ode/config.py +103 -0
- gemot/neural_ode/distil.py +454 -0
- gemot/neural_ode/heldout.py +201 -0
- gemot/neural_ode/judge.py +154 -0
- gemot/neural_ode/problem.py +628 -0
- gemot/neural_ode/pysr_worker.py +168 -0
- gemot/neural_ode/regularise.py +104 -0
- gemot/neural_ode/route.py +451 -0
- gemot/neural_ode/stage.py +516 -0
- gemot/neural_ode/train.py +943 -0
- gemot/neural_ode/worker.py +64 -0
- gemot/omnipath_local.py +278 -0
- gemot/paths.py +144 -0
- gemot/prompts.py +2126 -0
- gemot/runner/__init__.py +98 -0
- gemot/runner/barebones.py +831 -0
- gemot/runner/cli.py +284 -0
- gemot/runner/clock.py +443 -0
- gemot/runner/drive.py +458 -0
- gemot/runner/endpoints.py +19 -0
- gemot/runner/failure.py +179 -0
- gemot/runner/judge.py +1115 -0
- gemot/runner/main.py +381 -0
- gemot/runner/provenance.py +431 -0
- gemot/runner/scoring.py +660 -0
- gemot/runner/server.py +168 -0
- gemot/sbgn.py +1315 -0
- gemot/scenario.py +596 -0
- gemot/simulate.py +210 -0
- gemot/structure_eval.py +369 -0
- gemot/sweep/__init__.py +55 -0
- gemot/sweep/__main__.py +66 -0
- gemot/sweep/array_task.sh +342 -0
- gemot/sweep/explorer_ctl.sh +65 -0
- gemot/sweep/explorer_server.sh +131 -0
- gemot/sweep/fit_pool_ctl.sh +221 -0
- gemot/sweep/fit_pool_server.sh +77 -0
- gemot/sweep/phoenix_ctl.sh +139 -0
- gemot/sweep/phoenix_server.sh +105 -0
- gemot/sweep/submit.py +568 -0
- gemot/tracing.py +974 -0
- gemot/wandb_logging.py +148 -0
- gemot-0.1.0.dist-info/METADATA +262 -0
- gemot-0.1.0.dist-info/RECORD +94 -0
- gemot-0.1.0.dist-info/WHEEL +4 -0
- gemot-0.1.0.dist-info/licenses/LICENSE +21 -0
gemot/__init__.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Shared harness for the petab-mcp model-repair examples.
|
|
2
|
+
|
|
3
|
+
Every example (enzyme kinetics, predator–prey, the repressilator, …) is the same demo
|
|
4
|
+
with a different *scenario*: a deliberately mis-specified PEtab problem, an orchestrator
|
|
5
|
+
prompt + task, a deterministic canonical repair (the no-LLM ``scripted`` self-test), and
|
|
6
|
+
an independent success check. The cleanup → stateful MCP server → deepagents analyst panel
|
|
7
|
+
(three analysts + a blinded biocurator) → judge pipeline, plus Phoenix tracing and
|
|
8
|
+
the RESULT report, live here and are identical across examples.
|
|
9
|
+
|
|
10
|
+
An example's ``run.py`` just builds a :class:`Scenario` and calls :func:`run_scenario`.
|
|
11
|
+
This is an installed package (``pip install -e .`` from the repo root), so that is a plain
|
|
12
|
+
``from gemot import Scenario, run_scenario`` — no ``sys.path`` bootstrap.
|
|
13
|
+
|
|
14
|
+
Every agent-facing prompt lives in :mod:`gemot.prompts`; the deepagents driver is
|
|
15
|
+
:mod:`gemot.agent` and the pipeline + judge + CLI is :mod:`gemot.runner`.
|
|
16
|
+
|
|
17
|
+
Importing this package is deliberately CHEAP: the names below are resolved lazily (PEP
|
|
18
|
+
562), so ``import gemot.agent.dedup`` pulls in no ``mcp``, ``petab_mcp``, phoenix
|
|
19
|
+
or langchain. Several submodules here are heavy and the unit tests bind to the light ones;
|
|
20
|
+
do NOT add an eager ``from .runner import ...`` back — ``tests/test_import_lightness.py``
|
|
21
|
+
guards this.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import importlib
|
|
27
|
+
import os
|
|
28
|
+
from typing import TYPE_CHECKING
|
|
29
|
+
|
|
30
|
+
from . import paths
|
|
31
|
+
|
|
32
|
+
# Several submodules here (tracing.py, experiments.py, metrics.py, explorer/bundle.py) import
|
|
33
|
+
# from the `phoenix` package. Merely importing it runs `phoenix/config.py`'s module-level
|
|
34
|
+
# `ensure_working_dir_if_needed()`, which creates PHOENIX_WORKING_DIR -- defaulting to
|
|
35
|
+
# ~/.phoenix -- even when tracing only exports to a remote/self-hosted collector and never
|
|
36
|
+
# touches local storage. Default it to a repo-local dir (mirroring slurm/phoenix_data for
|
|
37
|
+
# the persistent collector) before any of that can happen, so nothing lands in the home dir.
|
|
38
|
+
# Every phoenix-importing module lives inside this package, so this always runs first.
|
|
39
|
+
os.environ.setdefault("PHOENIX_WORKING_DIR", str(paths.phoenix_working_dir()))
|
|
40
|
+
|
|
41
|
+
# Public name -> the submodule that defines it. Resolved on first attribute access.
|
|
42
|
+
_LAZY = {
|
|
43
|
+
"run_scenario": ".runner",
|
|
44
|
+
"Scenario": ".scenario",
|
|
45
|
+
"build_true_model": ".scenario",
|
|
46
|
+
"topology_diagnostics": ".scenario",
|
|
47
|
+
"Diagnostics": ".scenario",
|
|
48
|
+
"Baseline": ".scenario",
|
|
49
|
+
"JudgeContext": ".scenario",
|
|
50
|
+
"reaction_rate_law": ".scenario",
|
|
51
|
+
"is_rational": ".scenario",
|
|
52
|
+
"denominator_has_symbol": ".scenario",
|
|
53
|
+
"max_power_in_denominator": ".scenario",
|
|
54
|
+
"max_power_in_numerator": ".scenario",
|
|
55
|
+
"get_fitted_values": ".scenario",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if TYPE_CHECKING: # so IDEs / type checkers still resolve the lazy names
|
|
59
|
+
from .runner import run_scenario
|
|
60
|
+
from .scenario import (
|
|
61
|
+
Baseline,
|
|
62
|
+
build_true_model,
|
|
63
|
+
Diagnostics,
|
|
64
|
+
JudgeContext,
|
|
65
|
+
Scenario,
|
|
66
|
+
denominator_has_symbol,
|
|
67
|
+
get_fitted_values,
|
|
68
|
+
is_rational,
|
|
69
|
+
max_power_in_denominator,
|
|
70
|
+
max_power_in_numerator,
|
|
71
|
+
reaction_rate_law,
|
|
72
|
+
topology_diagnostics,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def __getattr__(name: str):
|
|
77
|
+
"""Import the defining submodule on first access (PEP 562)."""
|
|
78
|
+
if name in _LAZY:
|
|
79
|
+
value = getattr(importlib.import_module(_LAZY[name], __name__), name)
|
|
80
|
+
globals()[name] = value # cache, so the import runs once per name
|
|
81
|
+
return value
|
|
82
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def __dir__() -> list[str]:
|
|
86
|
+
return sorted({*globals(), *_LAZY})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
__all__ = [
|
|
90
|
+
"run_scenario",
|
|
91
|
+
"Scenario",
|
|
92
|
+
"build_true_model",
|
|
93
|
+
"topology_diagnostics",
|
|
94
|
+
"Diagnostics",
|
|
95
|
+
"Baseline",
|
|
96
|
+
"JudgeContext",
|
|
97
|
+
"reaction_rate_law",
|
|
98
|
+
"is_rational",
|
|
99
|
+
"denominator_has_symbol",
|
|
100
|
+
"max_power_in_denominator",
|
|
101
|
+
"max_power_in_numerator",
|
|
102
|
+
"get_fitted_values",
|
|
103
|
+
]
|
gemot/ablations.py
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""THE registry of ablations: every switch that changes WHAT A RUN DOES, in one place.
|
|
2
|
+
|
|
3
|
+
An ablation changes the agent's situation — what it is told, what tools it holds, what it may look
|
|
4
|
+
up — while leaving the code identical. It is therefore the one class of run input that ``git_sha``
|
|
5
|
+
cannot capture, which is what the three rules below exist to handle.
|
|
6
|
+
|
|
7
|
+
THE MEMBERSHIP TEST, since a switch is easy to add in the wrong place: an arm changes WHAT AN ANSWER
|
|
8
|
+
IS, or whether the agent can get one at all. A switch that changes only where an answer comes from,
|
|
9
|
+
or how fast it arrives, is transport — it cannot move a result, so registering it would make
|
|
10
|
+
:func:`arm` churn on differences that no analysis can care about. Transport still needs recording,
|
|
11
|
+
but as PROVENANCE (a source, a fetch date, a row count in ``result.json``), which is a different
|
|
12
|
+
job with a different consumer.
|
|
13
|
+
|
|
14
|
+
**Discoverable.** ``python -m gemot.ablations`` prints the catalogue: every arm, its
|
|
15
|
+
default, what the non-default side does, and whether it moves ``prompt_version``. A switch parsed
|
|
16
|
+
where it is used can only be found by grepping for it, so "which arms can I run?" has no answer
|
|
17
|
+
short of reading the whole source.
|
|
18
|
+
|
|
19
|
+
**Recorded.** :func:`state` and :func:`arm` go into every ``result.json``, and ``ablation_arm``
|
|
20
|
+
into the metrics CSV. An unrecorded arm is worse than no arm: both halves of an A/B land in one
|
|
21
|
+
table with no column to separate them, and the pooled cell reads as a result. Note that an arm
|
|
22
|
+
changing no prompt text leaves ``prompt_version`` byte-identical across the halves, so nothing else
|
|
23
|
+
in the record can tell them apart.
|
|
24
|
+
|
|
25
|
+
**One mechanism.** Every arm is an environment variable. Not a CLI flag: a flag cannot be set from
|
|
26
|
+
a batch script, which is where a sweep configures itself, and an arm settable two ways gets
|
|
27
|
+
recorded from whichever one the recorder happens to read. Nor a switch parsed at each use site —
|
|
28
|
+
two copies of a predicate that must agree can disagree, and a disagreement here is a half-ablated
|
|
29
|
+
run, with a tool removed from the toolset while the prompt still instructs the agent to call it.
|
|
30
|
+
|
|
31
|
+
WHY IT LIVES IN THE HARNESS: an ablation is an experiment concept — the harness runs the arms,
|
|
32
|
+
records them and sweeps over them. It also must live here rather than in the server package,
|
|
33
|
+
because ``gemot.prompts`` has to import without ``petab_mcp`` (see
|
|
34
|
+
``tests/test_import_lightness``) and ``slurm/make_sweep.py`` imports from a bare interpreter.
|
|
35
|
+
|
|
36
|
+
RETIRED ARMS (``data_regimes``, ``diff_edits``, ``free_exponents``; why in ``docs/RATIONALE.md``)
|
|
37
|
+
are gone from this tuple and their code paths fixed at the old default, here and in the server.
|
|
38
|
+
|
|
39
|
+
ADDING ONE: append an :class:`Ablation` and read it through :func:`enabled`. Recording, the CLI and
|
|
40
|
+
the metrics column all follow from this tuple, and ``test_ablations.py`` fails if a ``PETAB_*``
|
|
41
|
+
variable gates behaviour anywhere in ``src/`` without being registered here or listed as
|
|
42
|
+
non-ablation configuration.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
from __future__ import annotations
|
|
46
|
+
|
|
47
|
+
import os
|
|
48
|
+
from dataclasses import dataclass
|
|
49
|
+
|
|
50
|
+
# Spellings that mean "off". Everything else means on. See `_switch`.
|
|
51
|
+
_OFF = frozenset({"0", "false", "no", "off"})
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _switch(env: str, *, default_on: bool) -> bool:
|
|
55
|
+
"""Read one on/off environment variable: off only for an explicit off-word, else on."""
|
|
56
|
+
return os.environ.get(env, "1" if default_on else "0").strip().lower() not in _OFF
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True)
|
|
60
|
+
class Ablation:
|
|
61
|
+
"""One arm: what it is called, how to set it, and what the non-default side does.
|
|
62
|
+
|
|
63
|
+
``changes_prompt`` is the field to read when planning a comparison. A switch that alters prompt
|
|
64
|
+
TEXT moves ``prompt_version``, so it must not share a sweep with any unrelated prompt edit: the
|
|
65
|
+
two become inseparable in the record, and no later analysis can attribute the difference.
|
|
66
|
+
|
|
67
|
+
``null_arm`` says whether the null arm (``--driver barebones``) reads the switch too. It has
|
|
68
|
+
none of the panel's design, so most switches have nothing there to change, and its record
|
|
69
|
+
lists only these (``arm(null_arm=True)``).
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
name: str
|
|
73
|
+
env: str
|
|
74
|
+
default_on: bool
|
|
75
|
+
changes_prompt: bool
|
|
76
|
+
effect: str # what the NON-DEFAULT side does, in one line
|
|
77
|
+
null_arm: bool = False
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def setting(self) -> str:
|
|
81
|
+
"""The literal assignment that flips this arm away from its default."""
|
|
82
|
+
return f"{self.env}={'0' if self.default_on else '1'}"
|
|
83
|
+
|
|
84
|
+
def enabled(self) -> bool:
|
|
85
|
+
return _switch(self.env, default_on=self.default_on)
|
|
86
|
+
|
|
87
|
+
def is_default(self) -> bool:
|
|
88
|
+
return self.enabled() is self.default_on
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
ABLATIONS: tuple[Ablation, ...] = (
|
|
92
|
+
Ablation(
|
|
93
|
+
name="bio_literature",
|
|
94
|
+
env="PETAB_BIO_LITERATURE",
|
|
95
|
+
default_on=False,
|
|
96
|
+
changes_prompt=False,
|
|
97
|
+
effect="ON additionally gives the biocurator EuropePMC + bioRxiv literature search. Off by "
|
|
98
|
+
"default because literature search over a benchmark problem's distinctive entity "
|
|
99
|
+
"panel could surface its withheld source paper; the structured knowledge "
|
|
100
|
+
"(interactions/pathways/ontologies/OmniPath) is general biology. On the panel, "
|
|
101
|
+
"biocurator=off or biology_blind=on disables both kinds of knowledge access",
|
|
102
|
+
null_arm=True,
|
|
103
|
+
),
|
|
104
|
+
Ablation(
|
|
105
|
+
name="biology_blind",
|
|
106
|
+
env="PETAB_BIOLOGY_BLIND",
|
|
107
|
+
default_on=False,
|
|
108
|
+
changes_prompt=True,
|
|
109
|
+
effect="ON anonymizes the agent's PEtab identifiers and removes descriptive metadata, "
|
|
110
|
+
"scenario biology, the biocurator and external knowledge tools. The panel receives "
|
|
111
|
+
"numerical modeling instructions; a private mapping preserves reference scoring",
|
|
112
|
+
),
|
|
113
|
+
Ablation(
|
|
114
|
+
name="biocurator",
|
|
115
|
+
env="PETAB_BIOCURATOR",
|
|
116
|
+
default_on=True,
|
|
117
|
+
changes_prompt=True,
|
|
118
|
+
effect="OFF removes the biocurator from the deepagents panel, its external knowledge "
|
|
119
|
+
"tools and the lead's curator guidance. Biological identifiers, descriptions, "
|
|
120
|
+
"scenario context and the three modeling analysts are preserved. The "
|
|
121
|
+
"biology_blind arm also removes the curator, regardless of this setting",
|
|
122
|
+
),
|
|
123
|
+
Ablation(
|
|
124
|
+
name="indra_statements",
|
|
125
|
+
env="PETAB_INDRA_STATEMENTS",
|
|
126
|
+
default_on=False,
|
|
127
|
+
changes_prompt=True,
|
|
128
|
+
effect="ON starts the server with an EMPTY entity map, which offers make_changes' INDRA "
|
|
129
|
+
"`statements` route, and has the lead build the model as statements. Nothing binds the "
|
|
130
|
+
"observables or inputs for it: the readouts and how the condition targets enter are its "
|
|
131
|
+
"own, so no reference structure reaches the agent",
|
|
132
|
+
),
|
|
133
|
+
Ablation(
|
|
134
|
+
name="causal_constraints",
|
|
135
|
+
env="PETAB_CAUSAL_CONSTRAINTS",
|
|
136
|
+
default_on=False,
|
|
137
|
+
changes_prompt=True,
|
|
138
|
+
effect="ON starts the server with the problem's curated causal constraints "
|
|
139
|
+
"(PEtabAgentBench's `indra/constraints.txt`), claims every model must make, and tells the "
|
|
140
|
+
"lead they are the user's prior knowledge; make_changes refuses a model breaking one. "
|
|
141
|
+
"Needs indra_statements on, and a problem that ships the file: either missing refuses the "
|
|
142
|
+
"run. The lead never gets `set_constraints`",
|
|
143
|
+
),
|
|
144
|
+
Ablation(
|
|
145
|
+
name="reference_handoff",
|
|
146
|
+
env="PETAB_REFERENCE_HANDOFF",
|
|
147
|
+
default_on=True,
|
|
148
|
+
changes_prompt=True,
|
|
149
|
+
effect="OFF withholds what a problem's author wrote knowing the reference model: its "
|
|
150
|
+
"known-constants note and the entity names curated for the biocurator. The agent has the "
|
|
151
|
+
"problem's tables, its constants still shipping as named fixed rows, and the biocurator "
|
|
152
|
+
"the measured entities and inputs with their identifiers, derived (`entity_ids`)",
|
|
153
|
+
null_arm=True,
|
|
154
|
+
),
|
|
155
|
+
Ablation(
|
|
156
|
+
name="fix_pointers",
|
|
157
|
+
env="PETAB_FIX_POINTERS",
|
|
158
|
+
default_on=True,
|
|
159
|
+
changes_prompt=True,
|
|
160
|
+
effect="OFF withholds the numbers that point the agent at what to change or where the fit is "
|
|
161
|
+
"off: the merge hints and a tie's payoff, the ranked candidates, the regime grades, the "
|
|
162
|
+
"per-observable residual tables and outliers, sigma heterogeneity and which observables a "
|
|
163
|
+
"verdict flags (create_server(fix_pointers=False)), and the prompt lines that read them or "
|
|
164
|
+
"ask an analyst to rebuild them from the residuals. Every score, total and verdict, the "
|
|
165
|
+
"residual columns query_data reads, and all prose, stay",
|
|
166
|
+
),
|
|
167
|
+
Ablation(
|
|
168
|
+
name="progress_signals",
|
|
169
|
+
env="PETAB_PROGRESS_SIGNALS",
|
|
170
|
+
default_on=True,
|
|
171
|
+
changes_prompt=True,
|
|
172
|
+
effect="OFF withholds the numbers that tell the agent how well it is doing: the server's "
|
|
173
|
+
"best version, new-best flags, score differences against the parent or the best, chi2 "
|
|
174
|
+
"p-value and reduced chi2 (create_server(progress_signals=False)), the time left on FIT "
|
|
175
|
+
"COST, which version the finish gate restored and the score it arms on, and the chi2 "
|
|
176
|
+
"finish refusal that quotes the p-value; and the run no longer stops on the server's streak "
|
|
177
|
+
"or plateau. Prose changes only where it names a withheld number. Each fit's own nll, "
|
|
178
|
+
"criterion, k and chi2 stay, as do the subagents' turns-left notices, and the judge scores "
|
|
179
|
+
"as before",
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
_BY_NAME = {a.name: a for a in ABLATIONS}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def enabled(name: str) -> bool:
|
|
187
|
+
"""Whether the named ablation is on. Raises on an unknown name — a typo must not read as off."""
|
|
188
|
+
try:
|
|
189
|
+
return _BY_NAME[name].enabled()
|
|
190
|
+
except KeyError:
|
|
191
|
+
raise KeyError(f"unknown ablation {name!r}; registered: {sorted(_BY_NAME)}") from None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _read_by(null_arm: bool) -> tuple[Ablation, ...]:
|
|
195
|
+
"""The switches a run reads: all of them on the panel, the ``null_arm`` ones on the null arm."""
|
|
196
|
+
return tuple(a for a in ABLATIONS if a.null_arm) if null_arm else ABLATIONS
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def state(*, null_arm: bool = False) -> dict[str, bool]:
|
|
200
|
+
"""Every ablation's resolved value, for ``result.json``; on the null arm, every one it reads.
|
|
201
|
+
|
|
202
|
+
Records ALL of them, not only the non-default ones: a run silent about ``bio_literature`` is
|
|
203
|
+
indistinguishable from one recorded before the field existed, and "absent" would then have to
|
|
204
|
+
be read as "probably the default", which is how provenance rots.
|
|
205
|
+
"""
|
|
206
|
+
return {a.name: a.enabled() for a in _read_by(null_arm)}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def arm(*, null_arm: bool = False) -> str:
|
|
210
|
+
"""A compact canonical name for this configuration — the flat column a sweep groups by.
|
|
211
|
+
|
|
212
|
+
``"baseline"`` when every switch sits at its default, otherwise the deviations joined in
|
|
213
|
+
registry order (``"biocurator=off"``). Naming only the DEVIATIONS keeps the string stable when
|
|
214
|
+
a new ablation is added at its default, so old runs stay comparable to new ones.
|
|
215
|
+
|
|
216
|
+
The null arm is ``"barebones"``, followed by the deviations among the switches it reads
|
|
217
|
+
(``"barebones,reference_handoff=off"``). Deliberately not ``"baseline"``, though no switch
|
|
218
|
+
selects it: under that name its runs pooled with the panel's in every table grouped by this
|
|
219
|
+
column, which was the only one that table had (#164).
|
|
220
|
+
"""
|
|
221
|
+
off = [
|
|
222
|
+
f"{a.name}={'on' if a.enabled() else 'off'}"
|
|
223
|
+
for a in _read_by(null_arm)
|
|
224
|
+
if not a.is_default()
|
|
225
|
+
]
|
|
226
|
+
if null_arm:
|
|
227
|
+
return ",".join(["barebones", *off])
|
|
228
|
+
return ",".join(off) if off else "baseline"
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def state_key(*, null_arm: bool = False) -> str:
|
|
232
|
+
"""EVERY switch's resolved value, in registry order — the default-INDEPENDENT column.
|
|
233
|
+
|
|
234
|
+
:func:`arm` names only the deviations, which is what you want to group by but is defined
|
|
235
|
+
RELATIVE to the current defaults. So when a default flips, the same string denotes a
|
|
236
|
+
different configuration on either side of that commit: after 2026-08-15 ``"baseline"`` means
|
|
237
|
+
``free_exponents=on`` where before it meant ``off``, and pooling a sweep that spans the
|
|
238
|
+
change silently averages opposite configurations — precisely the failure the module
|
|
239
|
+
docstring's "Recorded" rule exists to prevent, reintroduced by the default rather than by a
|
|
240
|
+
missing column. This string always says what actually ran, so a groupby on it is safe across
|
|
241
|
+
any default change (and a new arm appended at its default, or a retired one removed, DOES move
|
|
242
|
+
it, which is the trade — group by `arm` for continuity, by this for correctness).
|
|
243
|
+
"""
|
|
244
|
+
return ",".join(
|
|
245
|
+
f"{name}={'on' if on else 'off'}" for name, on in state(null_arm=null_arm).items()
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def describe(*, use_color: bool = False) -> str:
|
|
250
|
+
"""The catalogue printed by ``python -m gemot.ablations``."""
|
|
251
|
+
bold, dim, reset = ("\033[1m", "\033[2m", "\033[0m") if use_color else ("", "", "")
|
|
252
|
+
rows = []
|
|
253
|
+
for a in ABLATIONS:
|
|
254
|
+
mark = "" if a.is_default() else " <- NOT the default"
|
|
255
|
+
prompt = "moves prompt_version" if a.changes_prompt else "prompt unchanged"
|
|
256
|
+
null = "; the null arm reads it too" if a.null_arm else ""
|
|
257
|
+
# `setting` is derived per-switch rather than hard-coded to `=0`: the default sides differ,
|
|
258
|
+
# so the value that flips an arm depends on which way it points. A catalogue whose printed
|
|
259
|
+
# instructions silently no-op is worse than none, so `test_ablations.py` executes every one
|
|
260
|
+
# of these strings and asserts the arm actually moves.
|
|
261
|
+
rows.append(
|
|
262
|
+
f"{bold}{a.name}{reset} [{'on ' if a.enabled() else 'off'}]{mark}\n"
|
|
263
|
+
f" {dim}set{reset} {a.setting} "
|
|
264
|
+
f"(default {'on' if a.default_on else 'off'}; {prompt}{null})\n"
|
|
265
|
+
f" {dim}does{reset} {a.effect}\n"
|
|
266
|
+
)
|
|
267
|
+
return (
|
|
268
|
+
f"{bold}Ablations{reset} — switches that change what a run does, without changing the "
|
|
269
|
+
f"code.\nEvery arm is an environment variable; export it before the run.\n"
|
|
270
|
+
f"Current arm: {bold}{arm()}{reset}\n\n"
|
|
271
|
+
+ "\n".join(rows)
|
|
272
|
+
+ f"\n{dim}Every run records these in result.json as `ablations`, plus the flat "
|
|
273
|
+
f"`ablation_arm` column in the metrics CSV, so an A/B can always be split after the "
|
|
274
|
+
f"fact.{reset}"
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _main(argv: "list[str] | None" = None) -> int:
|
|
279
|
+
import argparse
|
|
280
|
+
import json
|
|
281
|
+
import sys
|
|
282
|
+
|
|
283
|
+
p = argparse.ArgumentParser(
|
|
284
|
+
prog="python -m gemot.ablations",
|
|
285
|
+
description="List the ablations available in this repo and their current values.",
|
|
286
|
+
)
|
|
287
|
+
p.add_argument(
|
|
288
|
+
"--json",
|
|
289
|
+
action="store_true",
|
|
290
|
+
help="emit the registry as JSON (name, env, default, current, effect)",
|
|
291
|
+
)
|
|
292
|
+
args = p.parse_args(argv)
|
|
293
|
+
if args.json:
|
|
294
|
+
print(
|
|
295
|
+
json.dumps(
|
|
296
|
+
{
|
|
297
|
+
"arm": arm(),
|
|
298
|
+
"ablations": [
|
|
299
|
+
{
|
|
300
|
+
"name": a.name,
|
|
301
|
+
"env": a.env,
|
|
302
|
+
"setting": a.setting,
|
|
303
|
+
"default_on": a.default_on,
|
|
304
|
+
"current": a.enabled(),
|
|
305
|
+
"changes_prompt": a.changes_prompt,
|
|
306
|
+
"null_arm": a.null_arm,
|
|
307
|
+
"effect": a.effect,
|
|
308
|
+
}
|
|
309
|
+
for a in ABLATIONS
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
indent=2,
|
|
313
|
+
)
|
|
314
|
+
)
|
|
315
|
+
else:
|
|
316
|
+
print(describe(use_color=sys.stdout.isatty()))
|
|
317
|
+
return 0
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
if __name__ == "__main__": # pragma: no cover - exercised via _main in tests
|
|
321
|
+
raise SystemExit(_main())
|
gemot/agent/__init__.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""deepagents driver: a panel of independent analyst subagents + a modeling lead.
|
|
2
|
+
|
|
3
|
+
The panel is **scenario-agnostic** — the same one drives every example in ``examples/``. The
|
|
4
|
+
model-analysis phase is split across analysts that each look at the problem through a different
|
|
5
|
+
lens and report to a single **orchestrator** ("modeling lead"). deepagents exposes them to the
|
|
6
|
+
lead as a ``task`` tool: the lead calls ``task(description=..., subagent_type=...)``, each
|
|
7
|
+
analyst runs its own reasoning loop over *its own curated tool subset*, and returns a written
|
|
8
|
+
report. The lead synthesizes the reports and is the only agent that edits the model.
|
|
9
|
+
|
|
10
|
+
:mod:`.tools` what each agent on the panel can see, and the description trim
|
|
11
|
+
:mod:`.subagents` the analyst specs + the lead's containment (no general-purpose, no builtins)
|
|
12
|
+
:mod:`.biocurator` the blinded bio-knowledge analyst, assembled from runtime-discovered tools
|
|
13
|
+
:mod:`.literature` provenance for what the biocurator read, and the EuropePMC trim
|
|
14
|
+
:mod:`.probe` reading the server's CURRENT state through a bare call handle
|
|
15
|
+
:mod:`.finish_gate` ``finish`` — the only legitimate way to end a run
|
|
16
|
+
:mod:`.token_usage` per-run token accounting across the lead and its subagents
|
|
17
|
+
:mod:`.circuit_breaker` cut a tool that keeps failing, or whose server has gone away
|
|
18
|
+
:mod:`.dedup` pure identity/de-dup for proposed tool calls
|
|
19
|
+
:mod:`.guards` middleware: make proposed tool calls actually FIRE, and arrive intact
|
|
20
|
+
:mod:`.driver` :func:`run_deepagents` — builds the graph and runs the loop
|
|
21
|
+
|
|
22
|
+
Every agent-facing string is in :mod:`gemot.prompts`, not here; observability is Arize
|
|
23
|
+
Phoenix tracing (:mod:`gemot.tracing`), which the runner turns on before the agent starts.
|
|
24
|
+
|
|
25
|
+
Importing this package is CHEAP by design: every module above touches only stdlib at import
|
|
26
|
+
time, and each langchain / deepagents / openai import is lazy, inside the function that needs it.
|
|
27
|
+
The unit tests bind to these helpers with none of those installed
|
|
28
|
+
(``tests/test_import_lightness.py`` guards it), so keep new module-scope imports stdlib-only.
|
|
29
|
+
|
|
30
|
+
The names re-exported below are package-internal — reachable as ``agent._foo`` because tests and
|
|
31
|
+
the driver have always addressed them that way. ``run_deepagents`` is the only public one.
|
|
32
|
+
|
|
33
|
+
Re-export ONLY what is actually read through this facade. The block used to list 58 names, 22 of
|
|
34
|
+
which nothing ever reached this way — each had an in-package importer or a test importing its
|
|
35
|
+
defining submodule directly. A name here that no one resolves off the package is not an
|
|
36
|
+
interface, just a line to keep in sync.
|
|
37
|
+
|
|
38
|
+
Careful when trimming further: several tests bind the package to a local (``mod = _agent``,
|
|
39
|
+
``tests/test_finish_gate.py``) before reaching names off it, so grepping for ``agent.NAME``
|
|
40
|
+
UNDER-counts what is live. The test suite is the only reliable check.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
from __future__ import annotations
|
|
44
|
+
|
|
45
|
+
# Bind the submodules so `agent.dedup` / `agent.literature` resolve as attributes (tests reach
|
|
46
|
+
# them that way). Each touches only stdlib at import time, so this stays import-light.
|
|
47
|
+
from . import (
|
|
48
|
+
biocurator,
|
|
49
|
+
circuit_breaker,
|
|
50
|
+
dedup,
|
|
51
|
+
driver,
|
|
52
|
+
finish_gate,
|
|
53
|
+
guards,
|
|
54
|
+
literature,
|
|
55
|
+
probe,
|
|
56
|
+
subagents,
|
|
57
|
+
token_usage,
|
|
58
|
+
tools,
|
|
59
|
+
)
|
|
60
|
+
from .biocurator import (
|
|
61
|
+
DEFAULT_BIO_TOOLS,
|
|
62
|
+
LITERATURE_BIO_TOOLS,
|
|
63
|
+
SUBAGENT_NAMES,
|
|
64
|
+
_build_biocurator_subagent,
|
|
65
|
+
)
|
|
66
|
+
from .circuit_breaker import (
|
|
67
|
+
_is_transport_error,
|
|
68
|
+
_new_breaker_state,
|
|
69
|
+
_wrap_tools_with_circuit_breaker,
|
|
70
|
+
)
|
|
71
|
+
from .dedup import (
|
|
72
|
+
_dedupe_raw_tool_calls,
|
|
73
|
+
_dedupe_tool_calls,
|
|
74
|
+
_tool_call_key,
|
|
75
|
+
)
|
|
76
|
+
from .driver import _MAX_SILENT_BOUNCES, run_deepagents
|
|
77
|
+
from .finish_gate import (
|
|
78
|
+
_MAX_ADEQUACY_FINISH_REFUSALS,
|
|
79
|
+
_MAX_NO_FIT_FINISH_ATTEMPTS,
|
|
80
|
+
_MAX_PARSIMONY_FINISH_REFUSALS,
|
|
81
|
+
_MAX_SIGMA_FINISH_REFUSALS,
|
|
82
|
+
_finish_tool,
|
|
83
|
+
)
|
|
84
|
+
from .guards import (
|
|
85
|
+
_empty_report_guard,
|
|
86
|
+
_is_blank_report,
|
|
87
|
+
_report_text,
|
|
88
|
+
_task_arg_guard,
|
|
89
|
+
_task_arg_reject_message,
|
|
90
|
+
_tool_dispatch_guard,
|
|
91
|
+
_unexpected_task_kwargs,
|
|
92
|
+
)
|
|
93
|
+
from .literature import _trim_europepmc_search, _wrap_literature_recorder
|
|
94
|
+
from .probe import _model_committed
|
|
95
|
+
from .subagents import (
|
|
96
|
+
ACTIVE_SPECS,
|
|
97
|
+
ANALYSTS,
|
|
98
|
+
_build_subagents,
|
|
99
|
+
_disable_general_purpose_subagent,
|
|
100
|
+
_general_purpose_enabled,
|
|
101
|
+
_subagent_prompt_key,
|
|
102
|
+
)
|
|
103
|
+
from .token_usage import _token_accountant
|
|
104
|
+
from .tools import (
|
|
105
|
+
ALLOWED_TOOLS,
|
|
106
|
+
MATHEMATICIAN_TOOLS,
|
|
107
|
+
ORCHESTRATOR_TOOLS,
|
|
108
|
+
SIGNAL_ENGINEER_TOOLS,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# The prompt constants tests and callers have always read off this module. They live in
|
|
112
|
+
# gemot.prompts now; re-exported so `agent.BIOCURATOR_PROMPT` still resolves.
|
|
113
|
+
from ..prompts import (
|
|
114
|
+
BIOCURATOR_PROMPT,
|
|
115
|
+
SUBAGENT_EMPTY_REPORT_MARKER,
|
|
116
|
+
SUBAGENT_EMPTY_REPORT_NUDGE,
|
|
117
|
+
_biocurator_entity_block,
|
|
118
|
+
_NO_MODEL_NUDGE,
|
|
119
|
+
_SILENT_FINISH_NUDGE,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
__all__ = ["run_deepagents"]
|