From 93b34bc214f9cd08ef55051a5aa9f42dfd073e65 Mon Sep 17 00:00:00 2001 From: tanyar09 Date: Mon, 30 Mar 2026 14:15:09 -0400 Subject: [PATCH] Enhance CalendarTool action handling - Introduce logic to set default action to "list_events" when `action` is omitted and only a single key-value pair is present. - Expand handling for various input scenarios to ensure correct action assignment based on known actions and input keys. - Improve robustness of the coerced dictionary to accommodate different input formats. Made-with: Cursor --- nanobot/agent/tools/calendar.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/nanobot/agent/tools/calendar.py b/nanobot/agent/tools/calendar.py index 4943952..3f655ad 100644 --- a/nanobot/agent/tools/calendar.py +++ b/nanobot/agent/tools/calendar.py @@ -179,7 +179,34 @@ class CalendarTool(Tool): coerced["action"] = "list_events" if value == "calendar" else value coerced.pop(key, None) break - + + # Models often omit `action` and pass only a range ("this week", "1 week") under a junk key. + if not coerced.get("action"): + _known_actions = { + "list_events", + "create_event", + "delete_event", + "delete_events", + "update_event", + "check_availability", + "calendar", + } + _create_keys = {"title", "start_time", "end_time", "event_id", "event_ids", "description", "location", "attendees"} + if len(coerced) == 1: + only_k, only_v = next(iter(coerced.items())) + if only_k == "time_min" and isinstance(only_v, str): + coerced["action"] = "list_events" + elif isinstance(only_v, str) and only_k not in _create_keys: + if only_v in _known_actions: + coerced["action"] = "list_events" if only_v == "calendar" else only_v + coerced.pop(only_k, None) + else: + coerced = {"action": "list_events", "time_min": only_v} + else: + coerced["action"] = "list_events" + else: + coerced = {**coerced, "action": "list_events"} + return coerced @property