Support SLA Agent
No one types a time expression here. The phrase in 2 business days comes
from a policy rule, and the anchor is the ticket creation timestamp. This shows
Biruni in an automated pipeline — no chat, no LLM extraction. Business-day
arithmetic uses the default us_federal calendar, so weekends and
observed US Federal holidays are skipped automatically.
Trigger
build_expression()Your policy engine
→
resolve_time()Biruni API
→
set_deadline()Your ticket system
→
check_breach()Your alerting
The agent
sla_agent.py
import httpx, os
from datetime import datetime, timezone
BIRUNI_URL = "https://biruni.dev/v1/resolve"
# ── Stubs: replace with your integrations ────────────────────
def build_expression(policy: dict) -> str:
"""
Turn a policy rule into a Biruni expression.
e.g. {"response_time": "2 business days"} → "in 2 business days"
"""
return f"in {policy['response_time']}"
async def set_deadline(ticket_id: str, deadline: str):
"""Write the SLA deadline to your ticket system. (Zendesk, Jira ...)"""
...
async def escalate(ticket_id: str, reason: str):
"""Page on-call or notify a manager. (PagerDuty, Slack, email ...)"""
...
# ── Biruni integration ──────────────────────────────────────
async def resolve_time(phrase: str, tz: str, ref: str) -> dict:
async with httpx.AsyncClient() as client:
r = await client.post(
BIRUNI_URL,
headers={"Authorization": f"Bearer {os.environ['BIRUNI_API_KEY']}"},
json={
"expression": phrase,
"reference_date": ref,
"timezone": tz,
"options": {"business_calendar": "us_federal"},
},
)
r.raise_for_status()
return r.json()
# ── Agent entry point ────────────────────────────────────────
async def handle(ticket_id: str, created_at: str, policy: dict, tz: str):
expression = build_expression(policy)
result = await resolve_time(expression, tz, ref=created_at[:10])
if result["status"] != "resolved":
await escalate(ticket_id, "Could not compute SLA deadline.")
return
deadline = datetime.fromisoformat(result["resolved"])
await set_deadline(ticket_id, result["resolved"])
if datetime.now(timezone.utc) > deadline:
await escalate(ticket_id, "SLA already breached at ticket creation.")