Skip to main content

Interaction Modes

Four distinct ways users (or the system) trigger MIA.

1. Normal chat

User opens the chat panel (PivotAiAgentDashboard) and types a question.

  • Frontend route: src/routes/PivotAiAgentDashboard/
  • Backend endpoint: POST /api/chat on the Cloud Run service
  • Response: streaming SSE (text → widgets → suggestions)
  • Session persisted at AIZackboardSessions/{companyId}/{userId}/{sessionId} in RTDB

Two execution paths inside the same endpoint:

PathTriggerModels usedLatency
chatGreetings, help questions, no data neededHaiku only~200-500ms
dataAnything touching employees, schedule, attendance, payroll, etc.Sonnet tool loop + Haiku fan-out~5-30s

Intent classification happens in functions/pivotAiAgent/intent.ts using Haiku. See Normal Conversations for the full pipeline.

2. MIA Tips (manager-led setup conversation)

User navigates to /mia-tips to configure tip-distribution rules. This is a scoped conversation with a context-specific system prompt, not the open-ended chat.

  • Frontend route: src/routes/MiaTips/
  • System prompt: src/routes/MiaTips/index.tsx (bilingual FR/EN, strict tipping terminology, mandatory tools)
  • Tools: save_ai_tips_rule, update_ai_tips_rule, delete_ai_tips_rule, list_ai_tips_rules
  • Persistence: AiTipsRules/{companyId}/{ruleId} in RTDB

See MIA Tips.

3. AI Onboarding (new owner setup)

After signup, a new company owner is routed to /ai-onboarding instead of the manual wizard. Mia leads a multi-step conversation: role creation → integrations → schedule template → confirmation.

  • Frontend route: src/routes/AIOnboarding/
  • Backend orchestrator: functions/pivotAiAgent/onboarding-pipeline.ts
  • Prompts: functions/pivotAiAgent/onboarding-prompts.ts
  • Intent classifier: functions/pivotAiAgent/onboarding-intent.ts

See AI Onboarding.

4. Cron-scheduled reports

The user creates a recurring report (e.g., "every Monday at 9am, send me last week's labor breakdown"). Temporal fires on the schedule, runs the full AI pipeline server-side, and emails the result.

  • Created via: POST /ai-memory/cron-tasks?companyId= (Firebase Functions)
  • Stored in: RTDB pivotAiAgentCrons/{companyId}/{taskId} and mirrored as a Temporal Schedule
  • Schedule ID: pivot-ai-report-{sanitizedCompanyId}-{taskId}
  • On fire: scheduledReportWorkflow on the pivot-ai-agent task queue runs the tool loop, generates an email body (Haiku, 1024 tokens), and calls sendReportEmailActivity

See MIA Task Lifecycle and Temporal.