workflow-twin / env /dynamics.py
NDGCodes's picture
fix repo structure for HF
1a692ce
raw
history blame contribute delete
716 Bytes
from .entities import Ticket
from .models import Action
VALID_TRANSITIONS = {
"triage": "in_progress",
"respond": "in_progress",
"resolve": "resolved",
"escalate": "in_progress",
}
def apply_action(ticket: Ticket, action: Action) -> Ticket:
updated = ticket.model_copy(deep=True)
updated.attempts_used += 1
if action.action_type in VALID_TRANSITIONS:
updated.status = VALID_TRANSITIONS[action.action_type]
if updated.attempts_used >= updated.max_attempts and updated.status != "resolved":
updated.status = "open"
return updated
def is_terminal(ticket: Ticket) -> bool:
return ticket.status == "resolved" or ticket.attempts_used >= ticket.max_attempts