Coverage for app / util / cost_profiles.py: 91%
22 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
1"""Cost profiles — how much pipeline work an agent's turn does
2(cost-control plan, B2).
4An agent answers through a pipeline: triage, the answer, a quality check that
5can send it back for revision, memory, the conversation it replays. Not every
6question needs all of it at full depth. A cost profile names one setting of
7that depth, chosen per agent: ``thorough`` is the pipeline as it has always
8run, ``balanced`` does less of it where that should cost little in quality,
9and ``economy`` is balanced with a lighter model doing the lighter work
10(``docs/guides/agent-graph-review.md#cost-levers-october-2026``).
12This vocabulary is carried by both services, byte for byte
13(``tools/test_shared_modules.py``): svc-core stores an agent's profile and
14sends it on every request; svc-ai decides what each one does
15(``app/agents/effort.py``). Neither holds a copy of the other's half.
16"""
18from __future__ import annotations
20from enum import StrEnum
23class CostProfile(StrEnum):
24 """One setting of how much pipeline work a turn does."""
26 #: The whole pipeline, at full depth — every agent's behaviour before
27 #: profiles existed, and every existing agent's still.
28 thorough = "thorough"
29 #: Less of it: a shorter replayed conversation, fewer revisions, a
30 #: smaller memory, and no quality check on a request triage calls simple.
31 balanced = "balanced"
32 #: Balanced, with a lighter model doing the lighter work: the agent's
33 #: maker's lightest model in the same region runs the steps nobody reads
34 #: and answers a request triage calls simple.
35 economy = "economy"
38#: An agent that names none.
39DEFAULT = CostProfile.thorough
41#: How each is named where a person chooses one.
42LABELS: dict[str, str] = {
43 CostProfile.thorough: "Thorough",
44 CostProfile.balanced: "Balanced",
45 CostProfile.economy: "Economy",
46}
48#: What each does, in a sentence.
49DESCRIPTIONS: dict[str, str] = {
50 CostProfile.thorough: (
51 "The full pipeline: the agent's answer is checked, and revised when "
52 "the check finds gaps, with the conversation's last ten turns replayed."
53 ),
54 CostProfile.balanced: (
55 "Less work on each turn: a simple request is answered without a "
56 "quality check, a failed check gets one revision rather than two, and "
57 "fewer earlier turns and memories are sent with each request."
58 ),
59 CostProfile.economy: (
60 "Balanced, with a lighter model doing the lighter work: the lightest "
61 "model of the same maker, in the same region, runs triage, planning "
62 "and the quality check, and answers a request triage calls simple. "
63 "An agent already on its maker's lightest model saves nothing more."
64 ),
65}
67#: Whether the platform has measured a profile on its gold datasets and found
68#: it answers as well as ``thorough`` — the reference, measured by
69#: definition. A profile that has not been is offered as such, never as a
70#: default.
71MEASURED: dict[str, bool] = {
72 CostProfile.thorough: True,
73 CostProfile.balanced: False,
74 CostProfile.economy: False,
75}
77#: Whether a profile has a lighter model do some of the work. svc-core
78#: chooses the model (the agent's maker's lightest in the same region, under
79#: the workspace's rules) and sends it; svc-ai decides which work it does
80#: (``app/agents/effort.py``, which checks it agrees with this).
81LIGHTER_MODEL: dict[str, bool] = {
82 CostProfile.thorough: False,
83 CostProfile.balanced: False,
84 CostProfile.economy: True,
85}
87if not (
88 set(LABELS)
89 == set(CostProfile)
90 == set(DESCRIPTIONS)
91 == set(MEASURED)
92 == set(LIGHTER_MODEL)
93):
94 raise RuntimeError(
95 "Every cost profile needs a label, a description, a measure and a "
96 "lighter-model setting"
97 )
100def keys() -> tuple[str, ...]:
101 return tuple(profile.value for profile in CostProfile)
104def parse(value: object) -> CostProfile | None:
105 """``value`` as a profile, or None when it names none."""
106 try:
107 return CostProfile(str(value))
108 except ValueError:
109 return None
112def catalogue() -> list[dict[str, object]]:
113 """Every profile, as a picker shows it."""
114 return [
115 {
116 "key": profile.value,
117 "label": LABELS[profile],
118 "description": DESCRIPTIONS[profile],
119 "measured": MEASURED[profile],
120 "lighter_model": LIGHTER_MODEL[profile],
121 }
122 for profile in CostProfile
123 ]