Coverage for app / services / quality_check.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-10-31 11:21 +0000

1""" 

2What became of an answer at svc-ai's quality check — the evaluator node every 

3agent turn ends in — and how svc-core reads it. 

4 

5svc-ai owns the verdict (``app/agents/graph.py`` ``QualityOutcome``). This is 

6svc-core's copy of its vocabulary, held equal by ``tests/test_quality_check.py``, 

7because the ``quality_check`` rule field offers it to the rule builder. 

8 

9A turn that never reached a check — a direct model prompt, or a request the 

10pipeline answers without one — has no outcome at all, and a rule condition on 

11it does not match. That is different from ``unavailable``: the check should 

12have run and did not. 

13""" 

14 

15from __future__ import annotations 

16 

17from enum import StrEnum 

18from typing import Any 

19 

20 

21class Outcome(StrEnum): 

22 #: The check ran and the draft stood. 

23 passed = "passed" 

24 #: It failed, the agent revised it, and the revision passed. 

25 revised = "revised" 

26 #: It failed, and no revision passed: the agent's latest answer went out. 

27 failed = "failed" 

28 #: No check ran: no evaluator model, or it errored. 

29 unavailable = "unavailable" 

30 #: No check ran, by choice: the agent's cost profile answers a request 

31 #: triage calls simple unchecked (svc-ai ``PipelineEffort``). Not a 

32 #: failure to check — a rule can tell the two apart. 

33 skipped = "skipped" 

34 

35 

36def from_stream_event(data: dict[str, Any]) -> dict[str, Any]: 

37 """The verdict on svc-ai's ``system_node_result`` for ``__evaluator__``. 

38 

39 svc-ai nests it under ``result``. svc-core used to read it from the top 

40 of the event, where it never was, so no evaluator verdict had ever been 

41 stored on a message. 

42 """ 

43 result = data.get("result") 

44 if not isinstance(result, dict): 

45 return {} 

46 return { 

47 key: result[key] 

48 for key in ("outcome", "score", "passed", "critique", "gaps", "set_aside") 

49 if key in result 

50 } 

51 

52 

53def audit_figures(verdict: dict[str, Any] | None) -> dict[str, Any]: 

54 """What an audit rule may ask about the check: ``quality_check`` (the 

55 outcome) and ``quality_score`` (only when a check ran and scored).""" 

56 if not verdict: 

57 return {} 

58 figures: dict[str, Any] = {} 

59 outcome = verdict.get("outcome") 

60 if outcome in Outcome.__members__: 

61 figures["quality_check"] = outcome 

62 score = verdict.get("score") 

63 if isinstance(score, (int, float)) and not isinstance(score, bool): 

64 figures["quality_score"] = score 

65 return figures