From 3a3df9d5772e2b888bd04deb6e49c8d87ad765ec Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sat, 18 Jul 2026 07:19:37 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/agent.py b/agent.py index 23ba458..b4c91f3 100644 --- a/agent.py +++ b/agent.py @@ -54,6 +54,7 @@ AMBIGUOUS_DATE_RE = re.compile( re.IGNORECASE, ) RENEWAL_RE = re.compile(r"\brenew(?:s|al|ed|ing)?\b", re.IGNORECASE) +DEADLINE_KIND_ORDER = {"renewal": 0, "notice": 1, "obligation": 2} class ContractClockStudioV1Config(BaseModel): @@ -443,13 +444,16 @@ def extract_timeline(text: str) -> ExtractedTimeline: elif RENEWAL_RE.search(text): warnings.append("No explicit notice-window duration was found for the renewal date.") - order = {"renewal": 0, "notice": 1, "obligation": 2} deduped: dict[tuple[str, str], Deadline] = {} - for deadline in sorted(deadlines, key=lambda item: (order[item.kind], item.date, item.summary)): + for deadline in sorted(deadlines, key=deadline_sort_key): deduped.setdefault((deadline.kind, deadline.date), deadline) return ExtractedTimeline(deadlines=list(deduped.values()), warnings=warnings) +def deadline_sort_key(deadline: Deadline) -> tuple[int, str, str]: + return (DEADLINE_KIND_ORDER[deadline.kind], deadline.date, deadline.summary) + + def source_excerpt(text: str, start: int, end: int, radius: int = 140) -> str: left = max(0, start - radius) right = min(len(text), end + radius)