Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

docs(agent): predict_long gate comments must describe the None contract, not claim a report

aashish254995203afeaac
diff --git a/laya/agent.py b/laya/agent.py
index 7714f1fc..d4344f22 100644
--- a/laya/agent.py
+++ b/laya/agent.py
@@ -1863,7 +1863,9 @@ class Agent(HookRegistry):
usage["windows"] = len(results)
result = {"model": "laya-rl-agent", "answers": answers, "usage": usage}
# `predict_long` accepts no `min_confidence` -- the window loop has no single confidence to
- # gate on -- so every answer reports that it ran ungated rather than reporting nothing.
+ # gate on. The gate is still called, per its contract in laya/confidence.py: with
+ # `min_confidence` None it writes nothing, so the payload comes back exactly as the
+ # windows built it -- no `abstention`, no `abstention_threshold`, no flag.
apply_confidence_gate([result], None)
return result
diff --git a/laya/onnx_agent.py b/laya/onnx_agent.py
index 34c94194..f5b6a8b9 100644
--- a/laya/onnx_agent.py
+++ b/laya/onnx_agent.py
@@ -606,7 +606,8 @@ class ONNXAgent(HookRegistry):
usage["output_tokens"] = 0
usage["windows"] = len(results)
result = {"model": "laya-rl-agent-onnx", "answers": answers, "usage": usage}
- # As in `Agent.predict_long`: no `min_confidence` here, so say so on every answer.
+ # As in `Agent.predict_long`: no `min_confidence` here, and the gate called with None
+ # writes nothing -- the payload comes back with no `abstention` field at all.
apply_confidence_gate([result], None)
return result
diff --git a/tests/test_confidence.py b/tests/test_confidence.py
index 21171522..27863732 100644
--- a/tests/test_confidence.py
+++ b/tests/test_confidence.py
@@ -603,6 +603,68 @@ for _fn in (test_preset_is_four_flags_and_one_rubric, test_helpers_are_live_and_
else:
PASS.append("page-28/%s" % _fn.__name__)
+
+# Gate: the two predict_long call sites' comments must describe the None-min_confidence
+# contract truthfully. The pre-fix wording claimed every answer "reports that it ran ungated"
+# / "say so on every answer"; confidence.py:196-197 documents and :211-212 implements the
+# opposite -- the gate writes nothing at all, so the payload carries no `abstention` field.
+import ast as _gate_ast # noqa: E402
+
+_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+def _gate_gate_comment(rel_path):
+ """Return the run of comment lines that immediately precede the
+ apply_confidence_gate([result], None) call inside predict_long."""
+ with open(os.path.join(_REPO, rel_path)) as f:
+ lines = f.readlines()
+ tree = _gate_ast.parse("".join(lines))
+ for node in _gate_ast.walk(tree):
+ if isinstance(node, _gate_ast.FunctionDef) and node.name == "predict_long":
+ call_line = None
+ for sub in _gate_ast.walk(node):
+ if (isinstance(sub, _gate_ast.Call)
+ and getattr(sub.func, "id", getattr(sub.func, "attr", None)) == "apply_confidence_gate"
+ and len(sub.args) == 2
+ and isinstance(sub.args[1], _gate_ast.Constant)
+ and sub.args[1].value is None):
+ call_line = sub.lineno - 1
+ break
+ if call_line is None:
+ continue
+ out = []
+ i = call_line - 1
+ while i >= 0 and lines[i].lstrip().startswith("#"):
+ out.insert(0, lines[i].strip().lstrip("#").strip())
+ i -= 1
+ return " ".join(out)
+ return ""
+
+
+_agent_comment = _gate_gate_comment(os.path.join("laya", "agent.py"))
+_onnx_comment = _gate_gate_comment(os.path.join("laya", "onnx_agent.py"))
+
+for _label, _comment in (("agent.py", _agent_comment), ("onnx_agent.py", _onnx_comment)):
+ check_true("gate/comment/%s exists" % _label, len(_comment) > 0, "no comment found")
+ check_true("gate/comment/%s drops the ungated-reports claim" % _label,
+ "reports that it ran ungated" not in _comment
+ and "say so on every answer" not in _comment,
+ "pre-fix wording still on the call site: %r" % _comment)
+ check_true("gate/comment/%s names writes nothing" % _label,
+ "writes nothing" in _comment,
+ "gate comment must name the None-contract: %r" % _comment)
+ check_true("gate/comment/%s names the min_confidence argument" % _label,
+ "min_confidence" in _comment,
+ "gate comment must refer to the argument it is about: %r" % _comment)
+
+# Live witness: apply_confidence_gate([payload], None) leaves the payload byte-identical,
+# so the corrected comment is not itself a claim the code contradicts.
+_witness = {"model": "w", "answers": {"q": {"choice": "a", "confidence": 0.42}}, "usage": {}}
+_witness_before = copy.deepcopy(_witness)
+apply_confidence_gate([_witness], None)
+check("gate/live None writes nothing", _witness, _witness_before)
+check("gate/live None adds no abstention key", "abstention" in _witness["answers"]["q"], False)
+
print("\n%d passed, %d failed" % (len(PASS), len(FAIL)))
for f in FAIL:
print(" FAIL", f)