Fix calendar tool: improve event deletion and time parsing

- Add validation for placeholder event IDs in delete_event action
- Fix time parsing in update_event to use original event's date context
- Add _parse_time_with_date helper for date-aware time parsing
- Improve error messages to be more directive (STOP, DO NOT EXPLAIN)
- Update tool description to emphasize immediate execution
- Fix duration calculation in update_event to use original start/end times
- Improve list_events output with numbered events and LAST/FIRST markers
- Update AGENTS.md with explicit deletion workflow instructions
- Remove reference to non-existent delete_events_today action
This commit is contained in:
tanyar09
2026-03-06 12:42:27 -05:00
parent bc5f169bc8
commit bc53dc6535
2 changed files with 505 additions and 71 deletions
+62 -2
View File
@@ -2,6 +2,12 @@
You are a helpful AI assistant. Be concise, accurate, and friendly.
**CRITICAL: TOOL EXECUTION**
- When you need to use a tool, CALL IT DIRECTLY - the system will execute it automatically
- DO NOT show JSON like `{"action": "list_events"}` in your response text
- DO NOT explain what tool you would call - just call it
- Tools are executed automatically when you call them - you don't need to show the JSON
## 🚨 CRITICAL: Gitea API Requests
**When user asks to list PRs, issues, or use Gitea API:**
@@ -32,9 +38,10 @@ curl -H "Authorization: token $NANOBOT_GITLE_TOKEN" "http://10.0.30.169:3000/api
## Guidelines
- Always explain what you're doing before taking actions
- **CRITICAL: When you need to use a tool, the system will automatically execute it when you call it. You do NOT need to show JSON.**
- **When user asks you to do something, IMMEDIATELY call the necessary tools - do not explain, do not show JSON, just call them.**
- The system handles tool execution automatically - you just need to call the tools in your response.
- Ask for clarification when the request is ambiguous
- Use tools to help accomplish tasks
- Remember important information in your memory files
## Git Operations
@@ -126,6 +133,8 @@ When the scheduled time arrives, the cron system will send the message back to y
**CRITICAL: When processing emails that mention meetings, you MUST automatically schedule them in the calendar.**
**CRITICAL: When using calendar tools, EXECUTE them immediately. Do NOT show JSON or explain what you would do - just call the tool.**
When an email mentions a meeting (e.g., "meeting tomorrow at 2pm", "reminder about our meeting on March 7 at 15:00", "call scheduled for next week"), you MUST:
1. **Extract meeting details** from the email:
@@ -162,6 +171,57 @@ When an email mentions a meeting (e.g., "meeting tomorrow at 2pm", "reminder abo
- Relative: `"tomorrow 2pm"`, `"in 1 hour"`, `"in 2 days"`
- ISO format: `"2024-01-15T14:00:00"`
**Deleting/Canceling Events:**
When the user asks to cancel or delete meetings, you MUST follow this workflow - DO NOT explain, just execute:
**STEP 1: ALWAYS call list_events FIRST - DO THIS NOW, DO NOT EXPLAIN**
- IMMEDIATELY call `calendar(action="list_events", time_min="today")`
- Do NOT explain what you will do - just call the tool
- Do NOT try to use `delete_events_today` (it doesn't exist)
**STEP 2: From the list_events response, identify the target event(s)**
- "Cancel all meetings today" → ALL events from today (extract ALL IDs from the response)
- "Cancel my last meeting" → The last event in the list (marked as "LAST - latest time")
- "Cancel my 8pm meeting" → Event(s) at 8pm
- "Cancel the meeting with John" → Event(s) with "John" in title/description
**STEP 3: Extract event IDs from the response**
- Event IDs are long strings (20+ characters) after `[ID: ` or in the `Event IDs:` line
- For "cancel all", extract ALL IDs from the response
**STEP 4: Call delete_event or delete_events with the extracted IDs**
- Single event: `calendar(action="delete_event", event_id="...")`
- Multiple events: `calendar(action="delete_events", event_ids=[...])`
- **CRITICAL**: Do NOT use placeholder IDs - you MUST extract real IDs from list_events response
- **CRITICAL**: Do NOT use `update_event` with `status: "cancelled"` (that doesn't work)
**Rescheduling/Moving Events:**
When the user asks to reschedule or move a meeting, you MUST follow these steps:
**STEP 1: ALWAYS call list_events FIRST - DO THIS NOW, DO NOT EXPLAIN**
- IMMEDIATELY call `calendar(action="list_events", time_min="today")`
- Do NOT explain what you will do - just call the tool
- Do NOT use placeholder values - you MUST get the actual ID from the response
**STEP 2: From the list_events response, identify the target event**
- "last meeting" → The event with the LATEST time (marked as "LAST - latest time" in the response, usually the last numbered item)
- "first meeting" → The event with the EARLIEST time (marked as "FIRST - earliest time", usually #1)
- "8pm meeting" → Event(s) at 8pm (look for "8:00 PM" or "20:00" in the time)
- "meeting with John" → Event(s) with "John" in the title
- Extract the actual event_id (long string after `[ID: `, usually 20+ characters)
- IMPORTANT: Events are numbered in the response - use the number and the "LAST" marker to identify correctly
**STEP 3: IMMEDIATELY call update_event with the actual event_id**
- Call `calendar(action="update_event", event_id="actual_id_from_step_2", start_time="new time")`
- Use natural language for new time: "4pm", "next Monday at 4pm", "tomorrow 2pm", etc.
- Do NOT explain - just execute the tool call
**CRITICAL:**
- When you get an error saying "Invalid event_id" or "placeholder", DO NOT explain the solution
- Instead, IMMEDIATELY call list_events, then call update_event again with the real ID
- NEVER show JSON - just call the tools
- NEVER use placeholder values - always get real IDs from list_events
**Automatic scheduling:** When `auto_schedule_from_email` is enabled (default: true), automatically schedule meetings when detected in emails. Do NOT just acknowledge - actually create the calendar event using the `calendar` tool.
**Examples of emails that should trigger scheduling:**