Use cases¶
Six small scripts that run as-is with make example NAME=usecases/<name>. Each takes a
decider, so the pattern ports to any surface.
Route a ticket¶
"""Route a support ticket to the team that owns it.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/route_ticket`.
"""
from mimir import ChoiceResult, Decider, Mimir, Status
TEAMS = {
"billing": "Billing: payments, refunds and invoices",
"security": "Security: account access, passwords and fraud",
"shipping": "Shipping: deliveries, tracking and returns",
}
def route(decider: Decider, ticket: str) -> ChoiceResult:
"""Route one ticket; a deferred ticket goes to a person, never to a guessed team."""
return decider.choose(ticket, "Which team should handle this ticket?", options=TEAMS, risk=0.01)
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
result = route(model, "I was charged twice for order 4412.")
if result.status is not Status.DECIDED:
print("deferred: a person reviews the ticket")
else:
print(result.answer, round(result.confidence or 0.0, 3))
if __name__ == "__main__":
main()
Verify a claim¶
"""Check a claim against evidence passages.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/verify_claim`.
"""
from mimir import Context, Decider, Mimir, Passage, VerifyResult
def check(decider: Decider, claim: str, evidence: list[str]) -> VerifyResult:
"""Judge one claim against its evidence passages."""
context = Context(passages=tuple(Passage(text=text) for text in evidence))
return decider.verify(context, claim, risk=0.01)
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
result = check(
model,
"The export failed every night this week.",
["The export has failed every night this week.", "No failures were seen in March."],
)
print(result.status, result.answer)
if __name__ == "__main__":
main()
Rank candidates¶
"""Rank vendors against a requirement, best first.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/rank_vendors`.
"""
from mimir import Decider, Mimir, RankResult
VENDORS = {
"acme": "Acme: SOC 2, EU data residency, 99.99% SLA",
"globex": "Globex: no certifications, US-only hosting, 99.9% SLA",
"initech": "Initech: SOC 2, EU data residency, 99.95% SLA",
}
def rank(decider: Decider) -> RankResult:
"""Rank the vendors for a compliant EU deployment."""
return decider.rank(
"EU data residency with SOC 2 and the strongest SLA.",
"Which vendor fits best?",
candidates=VENDORS,
risk=0.01,
)
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
result = rank(model)
print(result.status, list(result.answer))
if __name__ == "__main__":
main()
Rate severity¶
"""Rate the severity of an incident on an ordered scale.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/rate_severity`.
"""
from mimir import Decider, Mimir, RateResult
LEVELS = ["low", "medium", "high", "critical"]
def rate(decider: Decider, report: str) -> RateResult:
"""Rate one incident report; levels run lowest first."""
return decider.rate(report, "How severe is this incident?", levels=LEVELS, risk=0.01)
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
result = rate(model, "Checkout has been down for all EU customers since 09:14.")
print(result.status, result.answer)
if __name__ == "__main__":
main()
Estimate a cost¶
"""Estimate a repair cost inside a range, with an interval.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/estimate_cost`.
"""
from mimir import Decider, EstimateResult, Mimir
def estimate(decider: Decider, description: str) -> EstimateResult:
"""Estimate one repair in dollars; the interval covers the honest range."""
return decider.estimate(
description, "What will the repair cost?", 0.0, 5000.0, unit="USD", risk=0.01
)
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
result = estimate(model, "Replace a cracked phone screen, parts and labour.")
print(result.status, round(result.answer, 2), result.interval)
if __name__ == "__main__":
main()
Gate a tool call¶
"""Gate a refund tool call against a written rule.
Install `mimir-decisions[local]`, then run `make example NAME=usecases/gate_tool_call`.
"""
from mimir import CheckOutcome, Decider, Mimir, Permission
RULES = ["Refunds above 500 dollars need a manager's approval."]
def gate(decider: Decider, amount: float) -> CheckOutcome:
"""Decide whether a refund call may run: allow, deny, or escalate to a person."""
check = decider.tool_call_check(RULES, tools=["issue_refund"])
return check("issue_refund", {"order": "4412", "amount": amount})
def main() -> None:
model = Mimir.from_pretrained("Mythologic/MIMIR-1")
for amount in (120.0, 900.0):
outcome = gate(model, amount)
if outcome.permission is Permission.ESCALATE:
print(amount, "escalate:", outcome.reason)
else:
print(amount, outcome.permission.value)
if __name__ == "__main__":
main()