precedent-ai 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- precedent/__init__.py +12 -0
- precedent/calibrate.py +58 -0
- precedent/cli.py +679 -0
- precedent/config.py +122 -0
- precedent/drift.py +135 -0
- precedent/evals.py +64 -0
- precedent/export.py +151 -0
- precedent/guard.py +219 -0
- precedent/ingest/__init__.py +42 -0
- precedent/ingest/episodes.py +110 -0
- precedent/ingest/jsonl.py +54 -0
- precedent/ingest/redact.py +57 -0
- precedent/ingest/slack.py +71 -0
- precedent/ingest/whatsapp.py +94 -0
- precedent/kb.py +280 -0
- precedent/llm.py +317 -0
- precedent/loop.py +320 -0
- precedent/mcp.py +166 -0
- precedent/models.py +316 -0
- precedent/packs.py +100 -0
- precedent/py.typed +0 -0
- precedent/reasoner.py +316 -0
- precedent/retrieve.py +149 -0
- precedent/runtime.py +163 -0
- precedent/store.py +337 -0
- precedent_ai-0.2.1.dist-info/METADATA +541 -0
- precedent_ai-0.2.1.dist-info/RECORD +31 -0
- precedent_ai-0.2.1.dist-info/WHEEL +5 -0
- precedent_ai-0.2.1.dist-info/entry_points.txt +2 -0
- precedent_ai-0.2.1.dist-info/licenses/LICENSE +21 -0
- precedent_ai-0.2.1.dist-info/top_level.txt +1 -0
precedent/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Precedent: turn how your team already works into rules your agents follow, and keep them true.
|
|
2
|
+
|
|
3
|
+
Mine rules from team chat -> a person approves -> agents consult the rulebook through
|
|
4
|
+
deterministic gates -> every escalation becomes next week's rule and a regression test.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "0.2.1"
|
|
8
|
+
|
|
9
|
+
from .kb import Precedent # noqa: E402
|
|
10
|
+
from .models import ANSWER, ESCALATE, NEEDS_APPROVAL, Decision, Gap, Proposal, Rule # noqa: E402
|
|
11
|
+
|
|
12
|
+
__all__ = ["Precedent", "Rule", "Proposal", "Decision", "Gap", "ANSWER", "ESCALATE", "NEEDS_APPROVAL", "__version__"]
|
precedent/calibrate.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Set the act-or-escalate thresholds from evidence instead of guessing.
|
|
2
|
+
|
|
3
|
+
For every golden case the runtime is replayed (dry run). Each case where the runtime
|
|
4
|
+
*would* have acted gives a (confidence, was-it-right) pair. For each risk tier we then
|
|
5
|
+
pick the lowest threshold at which auto-answers are at least `target` precise, and
|
|
6
|
+
report how much work that leaves for humans.
|
|
7
|
+
|
|
8
|
+
This is the cost trade-off from the escalation literature made concrete: a wrong action
|
|
9
|
+
costs more than a human's minute, so you choose the precision you need and the data
|
|
10
|
+
tells you the threshold, not the other way round.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
|
|
17
|
+
from .models import ESCALATE
|
|
18
|
+
from .runtime import Resolver
|
|
19
|
+
from .store import Store
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class TierResult:
|
|
24
|
+
risk: str
|
|
25
|
+
cases: int
|
|
26
|
+
current: float
|
|
27
|
+
recommended: float | None
|
|
28
|
+
precision_at_recommended: float | None
|
|
29
|
+
auto_rate_at_recommended: float | None
|
|
30
|
+
points: list[tuple[float, bool]] = field(default_factory=list)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def calibrate(store: Store, resolver: Resolver, target: float = 0.95, min_cases: int = 5) -> list[TierResult]:
|
|
34
|
+
by_tier: dict[str, list[tuple[float, bool]]] = {"low": [], "medium": []}
|
|
35
|
+
for case in store.golden():
|
|
36
|
+
d = resolver.resolve(case["situation"], dry_run=True)
|
|
37
|
+
if not d.cited or d.risk not in by_tier:
|
|
38
|
+
continue # never auto-answerable (no coverage, conflict) or always needs a human (high)
|
|
39
|
+
expected_rules = set(case.get("rules") or [])
|
|
40
|
+
right = case.get("expect", "covered") != ESCALATE and expected_rules <= {c["id"] for c in d.cited}
|
|
41
|
+
by_tier[d.risk].append((d.confidence, right))
|
|
42
|
+
|
|
43
|
+
out = []
|
|
44
|
+
for risk, pts in by_tier.items():
|
|
45
|
+
current = store.config.threshold(risk)
|
|
46
|
+
res = TierResult(risk=risk, cases=len(pts), current=current, recommended=None,
|
|
47
|
+
precision_at_recommended=None, auto_rate_at_recommended=None, points=sorted(pts))
|
|
48
|
+
if len(pts) >= min_cases:
|
|
49
|
+
for t in sorted({c for c, _ in pts}):
|
|
50
|
+
auto = [ok for c, ok in pts if c >= t]
|
|
51
|
+
precision = sum(auto) / len(auto)
|
|
52
|
+
if precision >= target:
|
|
53
|
+
res.recommended = round(t, 3)
|
|
54
|
+
res.precision_at_recommended = round(precision, 3)
|
|
55
|
+
res.auto_rate_at_recommended = round(len(auto) / len(pts), 3)
|
|
56
|
+
break
|
|
57
|
+
out.append(res)
|
|
58
|
+
return out
|