Extract and summarise bounds are each agent's own limits, set on its form

agents.limits holds extract_top, extract_min, summarise_top and
summarise_min; the scope query reads them per ranked row, and a row saved
before this behaves like a fresh agent. The four global config keys go.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 16:02:06 +02:00
1 parent e602eb3388
commit cebe62ddc9
20 files changed
+229 -147

No files matched your search

+16 -12
View File
@@ -14,6 +14,7 @@ from desk.models import Item
from desk.tools import agent
from app.config import Config
from app.jobs import extract
from app.models import Limits
from app.storage import Store
@@ -155,38 +156,41 @@ def test_an_unknown_uid_is_ignored_and_the_role_left_out_is_charged(
role = store.role(posting("1").uid)
assert role is not None and role.country == "" and role.extracted_at is None
assert result["rejected"] == ["not-in-the-batch"]
assert store.extract_pending(500) == 1
assert store.extract_pending() == 1
modeltask.run(extract.TASK, config, store)
modeltask.run(extract.TASK, config, store)
assert store.extract_pending(500) == 0, "given up after three unanswered replies"
assert store.extract_pending() == 0, "given up after three unanswered replies"
def test_only_the_best_of_each_agent_above_the_floor_is_read(
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""The bound that keeps extract cheap: the top `per_agent` of an enabled
agent's scores at `min_score` or more, whatever the boards produced. A
role nobody ranks is never sent; a batch dealt a uid finishes it."""
"""The bound that keeps extract cheap: the top of an enabled agent's
scores, as deep and as low as that agent's own `limits` say, whatever
the boards produced. A role nobody ranks is never sent; a batch dealt a
uid finishes it."""
for sid in ("best", "second", "low", "unscored", "gated"):
store.upsert_role(posting(sid))
one = store.save_agent("One")
one = store.save_agent("One", limits=Limits(extract_top=1, extract_min=0.5))
two = store.save_agent("Two", enabled=False)
store.replace_scores(one.id, [(posting("best").uid, 0.9, ""),
(posting("second").uid, 0.8, ""),
(posting("low").uid, 0.2, ""),
(posting("gated").uid, 0.95, "country unknown")])
store.replace_scores(two.id, [(posting("unscored").uid, 0.99, "")])
config = Config(database=str(tmp_path / "x.db"),
extract={"enabled": True, "per_agent": 1, "min_score": 0.5})
config = Config(database=str(tmp_path / "x.db"), extract={"enabled": True})
model = stub(monkeypatch, lambda roles: [answer(r["uid"]) for r in roles])
assert store.extract_pending(1, 0.5) == 1
assert store.extract_pending(5, 0.5) == 2, "the floor holds the low one back"
assert store.extract_pending(5, 0.0) == 3, "the disabled agent's pick never counts"
assert store.extract_pending() == 1
store.save_agent("One", agent_id=one.id, limits=Limits(extract_top=5, extract_min=0.5))
assert store.extract_pending() == 2, "the floor holds the low one back"
store.save_agent("One", agent_id=one.id, limits=Limits(extract_top=5, extract_min=0))
assert store.extract_pending() == 3, "the disabled agent's pick never counts"
store.save_agent("One", agent_id=one.id, limits=Limits(extract_top=1, extract_min=0.5))
modeltask.run(extract.TASK, config, store)
assert [[r["uid"] for r in batch] for batch in model.asked] == [[posting("best").uid]]
assert [r.uid for r in store.extract_waiting(10, 1, 0.5, uids=[posting("low").uid])] == \
assert [r.uid for r in store.extract_waiting(10, uids=[posting("low").uid])] == \
[posting("low").uid], "a dealt uid is read whatever its rank"