Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sage/gateway/tests/test_lean_tool_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,24 @@ def test_what_lean_leaves_out_is_one_describe_away():
def test_lean_is_materially_smaller_than_brief():
b = len(json.dumps(toolset.specs({}, {}, brief=True)))
l = len(json.dumps(toolset.specs({}, {}, lean=True)))
assert l < 0.75 * b, f"lean {l} vs brief {b}"
# 0.80, not 0.75: the #708 rule keeps prose for parameters that act on existing state (about 800
# chars). That trade is deliberate: lean is a saving, not a target, and safety lines outrank it.
assert l < 0.80 * b, f"lean {l} vs brief {b}"


def test_every_load_bearing_pair_names_a_real_parameter():
"""A typo in LEAN_KEEP would silently drop the line it meant to keep."""
for verb, param in toolset.LEAN_KEEP:
assert verb in _TOOL_SCHEMAS and param in _TOOL_SCHEMAS[verb][1], (verb, param)


def test_every_optional_parameter_is_classified():
"""SAGE #708's rule: every optional parameter is either kept under lean (it acts on existing state,
or its valid values are prose) or reviewed as safe to drop. A new optional parameter in neither set
fails here, so it gets a decision instead of silently losing its prose."""
optional = {(v, p) for v, (_d, props, req) in _TOOL_SCHEMAS.items() for p in props if p not in req}
unclassified = optional - toolset.LEAN_KEEP - toolset.LEAN_DROP_REVIEWED
assert not unclassified, f"classify these for lean (LEAN_KEEP or LEAN_DROP_REVIEWED): {sorted(unclassified)}"
assert not (toolset.LEAN_KEEP & toolset.LEAN_DROP_REVIEWED), "a parameter cannot be both kept and dropped"
for v, p in toolset.LEAN_DROP_REVIEWED:
assert v in _TOOL_SCHEMAS and p in _TOOL_SCHEMAS[v][1], ("stale LEAN_DROP_REVIEWED entry", v, p)
35 changes: 34 additions & 1 deletion sage/gateway/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,40 @@ def here(cfg: Optional[dict], backend: Optional[str] = None) -> Dict[str, tuple]
# not an enum, so lean dropped them with the rest.
LEAN_KEEP = frozenset({("run", "data"), ("request_run", "rerun"), ("memory_read", "find"),
("memory_edit", "old"), ("game", "game"), ("check", "target"),
("settle", "id"), ("settle", "reopen")})
("settle", "id"), ("settle", "reopen")}) | frozenset({
# THE RULE, applied to every optional parameter (SAGE #708; HUB on #753: apply it now, not
# near-miss by near-miss). Both lean-trial regressions came from one behaviour: without the
# prose, a small model fills EVERY listed parameter. So the prose stays when misfilling would
# act on existing state, or when the valid values are a closed set written as prose:
("memory_edit", "start_line"), ("memory_edit", "end_line"), # pick which lines get replaced
("skill", "retire"), ("skill", "distinct"), # remove a skill / write beside one
("retire_thread", "preview"), ("retire_thread", "confirmation"), # dry run vs. a real retire
("pr_amend", "body"), # overwrites the PR body
("tune", "value"), # 'default' resets the parameter
("pr_sync", "op"), ("identity_edit", "field"), # closed sets written as prose
# HUB on #759: three anchors the first pass dropped. Each picks WHAT a kept flag or write acts on.
("camera", "out_path"), # a write destination: ffmpeg overwrites whatever path it names
("tune", "name"), # picks which parameter `value` sets or resets
("skill", "name"), # the anchor for a rewrite ("writing it again replaces it") and retire
("retire_thread", "settled"), # picks which settled entries leave with the thread; 'all' takes every one named
})
# Every other optional parameter was REVIEWED and its prose may go: free text the being writes in
# its own words, or a read-only selector whose misfill costs a re-read, not a change. A parameter
# in neither set fails test_every_optional_parameter_is_classified, so a new one can't slip
# through lean unclassified. The test proves every optional parameter is CLASSIFIED, not that each
# is classified CORRECTLY: that is a review question, and HUB's review of #759 moved three entries.
LEAN_DROP_REVIEWED = frozenset({
("camera", "device"), ("game", "expect"), ("gaze", "target"),
("gaze", "words"), ("git_read", "n"), ("git_read", "path"), ("git_read", "rev"),
("git_read", "rev2"), ("git_read", "start_line"), ("identity_edit", "text"), ("identity_edit", "why"),
("memory_read", "end_line"), ("memory_read", "start_line"), ("pr_read", "repo"),
("pr_read", "last"), ("pr_sync", "message"), ("recall", "query"), ("recall", "top_k"),
("recall", "idx"), ("remember", "tags"), ("request_run", "why"), ("retire_thread", "reason"),
("search", "path"), ("search", "n"), ("settle", "question"), ("settle", "answer"),
("settle", "evidence"), ("settle", "why"), ("skill", "query"),
("skill", "description"), ("skill", "when"), ("skill", "body"), ("skill", "why"),
("tune", "why"),
})


def tool_descriptions_mode(cfg: Optional[dict]) -> str:
Expand Down
Loading