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
This commit is contained in:
parent
a6bd3e0e9b
commit
93b34bc214
@ -180,6 +180,33 @@ class CalendarTool(Tool):
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user