Skip to content

hitl — Human-in-the-Loop Events

Auto-documented module: spanforge.namespaces.hitl

The hitl.* namespace captures human oversight of AI decisions — a mandatory requirement for high-risk AI systems under EU AI Act Art. 14. Four canonical event types:

  • hitl.queued
  • hitl.reviewed
  • hitl.escalated
  • hitl.timeout

Regulatory mapping

FrameworkClauseRole of hitl.* events
GDPRArt. 22Proves human involvement in automated decisions
EU AI ActArt. 14Mandatory human oversight for high-risk AI
EU AI ActAnnex IV.5Technical documentation — oversight measures

Payload class

HITLPayload

FieldTypeRequiredDescription
decision_idstrIdentifier of the AI decision under review
agent_idstrAgent that produced the decision
risk_tierstrOne of "low", "medium", "high", "critical"
statusstrOne of "queued", "approved", "rejected", "escalated", "timeout"
reasonstrReason for the review outcome
reviewerstr | NoneIdentity of the human reviewer
sla_secondsintReview SLA in seconds. Default 3600
queued_atstr | NoneISO 8601 timestamp — when queued
resolved_atstr | NoneISO 8601 timestamp — when resolved
escalation_tierintEscalation level. Default 0
confidencefloat | NoneAgent confidence score in [0.0, 1.0]

Example

from spanforge.namespaces.hitl import HITLPayload

payload = HITLPayload(
    decision_id="dec_01HX...",
    agent_id="loan-agent@1.0.0",
    risk_tier="high",
    status="queued",
    reason="Low confidence on credit decision",
    confidence=0.42,
)

event = Event(
    event_type="hitl.queued",
    source="hitl-service@1.0.0",
    org_id="org_01HX",
    payload=payload.to_dict(),
)

Convenience functions

The spanforge.hitl module provides a HITLQueue class and module-level helpers:

from spanforge.hitl import queue_for_review, review_item, list_pending

queue_for_review(
    decision_id="dec_01HX...",
    agent_id="loan-agent@1.0.0",
    risk_tier="high",
    reason="Low confidence",
)

review_item(decision_id="dec_01HX...", reviewer="alice", approved=True)
pending = list_pending()