Skip to content

feat(prompt): optimize booking flow with tool chaining, ASAP auto-select, and structured errors#45

Merged
dhairyashiil merged 4 commits into
mainfrom
devin/1773491362-ideal-booking-flow
Mar 14, 2026
Merged

feat(prompt): optimize booking flow with tool chaining, ASAP auto-select, and structured errors#45
dhairyashiil merged 4 commits into
mainfrom
devin/1773491362-ideal-booking-flow

Conversation

@dhairyashiil
Copy link
Copy Markdown
Member

feat(prompt): optimize booking flow with tool chaining and ASAP auto-select

Summary

Rewrites the booking section of the agent system prompt in lib/agent.ts to minimize user round-trips (from 4 messages → 2 for the best case). Also adds structured error hints to tool returns so the agent can react more intelligently to failures.

Prompt changes (getSystemPrompt()):

  • Step 0: Defaults to "theirs" (Option B) when a Cal.com username is present in the message. Only asks "Yours or Theirs?" when genuinely ambiguous.
  • Tool chaining: New section instructing the agent to chain tool calls within a single turn (e.g., list_event_typescheck_availability → text) instead of stopping after each tool.
  • ASAP auto-select: Auto-selects slots[0] for ASAP requests instead of presenting 3-5 options. Uses nextAvailableSlots from the extended search when 0 slots found in 3 days.
  • Option B fallback: When username lookup fails, offers to switch to Option A (user's own calendar) with attendee name+email.
  • Username ambiguity: Guides the user to share a direct booking link when the wrong person's event types are returned.
  • Fast-path scoping: Explicitly limits skip-confirmation fast-path to Option A only. Option B always requires confirmation.

Tool return changes:

  • list_event_types_by_username: Adds fallbackSuggestion on 0 results and retryable + fallbackSuggestion on errors.
  • book_meeting / book_meeting_public: Adds retryable and suggestion fields for 409 conflicts and network errors.

Review & Testing Checklist for Human

These are prompt-engineering changes — CI passing confirms types/lint only, not behavioral correctness. Manual testing is required.

  • Test "book with X asap" (1 event type): Verify the agent chains list_event_types_by_usernamecheck_availability_public → confirmation text in a single turn (2 user messages total)
  • Test "book with X asap" (multiple event types): Verify the agent stops to ask which event type, then auto-selects earliest slot (3 messages)
  • Test username not found: Verify the fallback message offers Option A with name+email
  • Test Option B always confirms: Send "book with peer asap, just do it" — agent should still ask for confirmation (no fast-path for Option B)
  • Test Option A fast-path preserved: Send "book a 30 min with john@example.com tomorrow 2pm, just do it" — should book without confirmation
  • Verify non-booking flows unaffected: Cancel, reschedule, "am I free?", schedule management should all work as before (the prompt sections for these were not modified)
  • Review error string matching in the catch blocks — the isConflict/isNetwork heuristics rely on substring matching ("409", "conflict", "fetch", "timeout") which may not cover all real API error formats

Notes

  • All changes are in a single file: apps/chat/lib/agent.ts
  • No API changes, no handler changes, no schema changes
  • The error hint fields (retryable, suggestion, fallbackSuggestion) are additional return object properties — no schema enforcement, the agent reads them as context

Link to Devin session: https://app.devin.ai/sessions/f0604c789fbb43299f2dc7ba90c4616b
Requested by: @dhairyashiil

@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 14, 2026

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: cal-companion-chat.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@dhairyashiil dhairyashiil marked this pull request as ready for review March 14, 2026 14:24
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/chat/lib/agent.ts">

<violation number="1" location="apps/chat/lib/agent.ts:795">
P2: The fallback string `"Failed to fetch event types for this user"` contains `"fetch"`, so `isNetwork` is always `true` when `err` is not an `Error` instance. This misclassifies unknown errors as transient network failures, giving the agent a misleading retry hint.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/chat/lib/agent.ts Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/chat/lib/agent.ts">

<violation number="1" location="apps/chat/lib/agent.ts:1130">
P2: Generic fetch failures are no longer classified as retryable network errors in the booking tools.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/chat/lib/agent.ts
@dhairyashiil dhairyashiil merged commit f46b257 into main Mar 14, 2026
10 of 12 checks passed
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/chat/lib/agent.ts">

<violation number="1" location="apps/chat/lib/agent.ts:795">
P2: This narrower check stops retryable Cal.com lookup failures from being recognized, so transient 5xx errors get reported to the agent as an invalid username.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/chat/lib/agent.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants