Download source/proxy_eval/tasks/office.py from rca-umb/five-desks: direct link, hf CLI and curl.
- Browser
- Download file 6.96 kB
-
https://huggingface.co/datasets/rca-umb/five-desks/resolve/main/source/proxy_eval/tasks/office.py
- Command line
-
hf download hf://datasets/rca-umb/five-desks/source/proxy_eval/tasks/office.py
-
curl -L -o office.py https://huggingface.co/datasets/rca-umb/five-desks/resolve/main/source/proxy_eval/tasks/office.py
6.96 kB
| """Office: schedule a meeting from an email request, calendars and a late change of plans.""" | |
| from typing import Any, Literal | |
| from pydantic import Field | |
| from ..core import Action, ProxyTask, Step | |
| PEOPLE = ["Ana Duarte", "Raj Mehta", "Lena Fischer", "Tom Okafor", "Mei Chen", "Sam Rivera"] | |
| DAYS = ["2026-10-13", "2026-10-14", "2026-10-15"] | |
| DAY_NAMES = {"2026-10-13": "Tuesday", "2026-10-14": "Wednesday", "2026-10-15": "Thursday"} | |
| def hm(minutes): | |
| return f"{minutes // 60:02d}:{minutes % 60:02d}" | |
| def parse_hm(text): | |
| h, m = str(text).strip().split(":")[:2] | |
| return int(h) * 60 + int(m) | |
| class OfficeAction(Action): | |
| op: Literal["list_emails", "read_email", "get_calendar", "create_event"] = Field( | |
| description="list_emails, read_email (email_id), get_calendar (person, date), or create_event " | |
| "(event) which sends the invitation and ends the episode.") | |
| email_id: str = Field(default="", description="Email id for read_email.") | |
| person: str = Field(default="", description="Full name for get_calendar.") | |
| date: str = Field(default="", description="YYYY-MM-DD for get_calendar.") | |
| event: dict[str, Any] = Field(default_factory=dict, description=( | |
| "For create_event: {title, date (YYYY-MM-DD), start (HH:MM), end (HH:MM), attendees (list of full names)}")) | |
| class Scheduling(ProxyTask): | |
| family = "office-scheduling" | |
| domain = "office-white-collar" | |
| Action = OfficeAction | |
| max_steps = 14 | |
| finish_action = {"op": "create_event", "event": {}} | |
| def setup(self): | |
| r = self.rng | |
| self.boss, a, b, other = r.sample(PEOPLE, 4) | |
| self.attendees = sorted([self.boss, a, b]) | |
| self.duration = r.choice([30, 45, 60]) | |
| self.days = DAYS[:2] if r.random() < 0.5 else DAYS[1:] | |
| self.title = r.choice(["Q4 budget review", "Vendor contract kickoff", "Hiring plan sync"]) | |
| self.cal = {} | |
| for person in PEOPLE: | |
| for day in DAYS: | |
| busy, t = [], 9 * 60 | |
| while t < 17 * 60: | |
| if r.random() < 0.45: | |
| length = r.choice([30, 60, 90]) | |
| busy.append((t, min(t + length, 17 * 60))) | |
| t += length | |
| t += 30 | |
| self.cal[(person, day)] = busy | |
| # a late email: one attendee is out for part of a day that is not on their calendar | |
| # and it always covers the slot that would be chosen without reading it | |
| self.late_person, self.late_day, self.late_block = r.choice([a, b]), None, (0, 0) | |
| naive = self._earliest() | |
| assert naive is not None | |
| self.late_day = naive[0] | |
| top = naive[1] - naive[1] % 60 | |
| self.late_block = (top, min(top + r.choice([120, 180]), 17 * 60)) | |
| self.slot = self._earliest() | |
| assert self.slot is not None and self.slot != naive | |
| self.emails = { | |
| "m1": {"from": self.boss, "subject": f"Set up: {self.title}", | |
| "body": f"Hi, please set up a {self.duration}-minute '{self.title}' with {a} and {b} (and me) " | |
| f"on {DAY_NAMES[self.days[0]]} {self.days[0]} or {DAY_NAMES[self.days[1]]} " | |
| f"{self.days[1]}. Working hours are 09:00-17:00 and nobody meets over lunch " | |
| f"(12:00-13:00). Start times on the quarter hour. Take the earliest slot that works " | |
| f"for all three of us. Thanks!"}, | |
| "m2": {"from": "it-news@corp.example", "subject": "Password rotation reminder", | |
| "body": "Reminder: rotate your password before Friday."}, | |
| "m3": {"from": self.late_person, "subject": "Re: availability", | |
| "body": f"Heads up: I'll be at the client site on {self.late_day} from {hm(self.late_block[0])} " | |
| f"to {hm(self.late_block[1])}. It's not on my calendar yet."}, | |
| "m4": {"from": other, "subject": "Lunch Thursday?", "body": "Want to grab lunch Thursday at 12:30?"}, | |
| } | |
| def _busy(self, person, day): | |
| blocks = list(self.cal[(person, day)]) + [(12 * 60, 13 * 60)] | |
| if person == self.late_person and day == self.late_day: | |
| blocks.append(self.late_block) | |
| return blocks | |
| def _free(self, day, start, end): | |
| if start < 9 * 60 or end > 17 * 60: | |
| return False | |
| return all(end <= s or start >= e for p in self.attendees for s, e in self._busy(p, day)) | |
| def _earliest(self): | |
| for day in self.days: | |
| for start in range(9 * 60, 17 * 60, 15): | |
| if self._free(day, start, start + self.duration): | |
| return day, start | |
| return None | |
| def reset(self): | |
| return {"text": "You are an executive assistant. Handle the scheduling request in the inbox: work out the " | |
| "right slot and send the invitation with create_event.", "remaining_actions": self.max_steps} | |
| def act(self, a): | |
| left = self.max_steps - self.steps | |
| if a.op == "list_emails": | |
| return Step({"text": "\n".join(f"{k}: from {v['from']} - {v['subject']}" for k, v in self.emails.items()), | |
| "remaining_actions": left}) | |
| if a.op == "read_email": | |
| mail = self.emails.get(a.email_id.strip()) | |
| return Step({"text": mail["body"] if mail else "No such email.", "remaining_actions": left}) | |
| if a.op == "get_calendar": | |
| if a.person not in PEOPLE or a.date not in DAYS: | |
| return Step({"text": "Unknown person or date (use full names and YYYY-MM-DD).", | |
| "remaining_actions": left}) | |
| busy = self.cal[(a.person, a.date)] | |
| text = "Busy: " + (", ".join(f"{hm(s)}-{hm(e)}" for s, e in busy) or "nothing") | |
| return Step({"text": f"{a.person} on {a.date}. {text}", "remaining_actions": left}) | |
| ev = {str(k).lower(): v for k, v in a.event.items()} | |
| try: | |
| start, end = parse_hm(ev.get("start")), parse_hm(ev.get("end")) | |
| people = sorted(str(p).strip() for p in ev.get("attendees", [])) | |
| ok = (ev.get("date") == self.slot[0] and start == self.slot[1] and end - start == self.duration | |
| and people == self.attendees) | |
| except (ValueError, TypeError, AttributeError): | |
| ok = False | |
| return Step({"text": "Invitation sent.", "remaining_actions": 0}, True, 1.0 if ok else 0.0) | |
| def oracle(self): | |
| acts = [{"op": "list_emails"}] + [{"op": "read_email", "email_id": k} for k in ("m1", "m3")] | |
| acts += [{"op": "get_calendar", "person": p, "date": d} for p in self.attendees for d in self.days] | |
| day, start = self.slot | |
| return acts[:9] + [{"op": "create_event", "event": { | |
| "title": self.title, "date": day, "start": hm(start), "end": hm(start + self.duration), | |
| "attendees": self.attendees}}] | |