Skip to content

send_email_to_caller

The send_email_to_caller tool lets the todo execution agent compose and send a follow-up email to the person who called. The AI writes the email subject and body based on the task description and call transcription, but the recipient is always derived from the system — never chosen by the AI.

The tool is available during todo execution when the TodoType has SendEmailToCaller in its tools list. Organizations configure this when creating todo types.

SystemTool::SendEmailToCaller => Tool {
name: "send_email_to_caller",
description: "Sends a follow-up email to the caller. The recipient is
automatically derived from the contact associated with the call.",
input_schema: {
"type": "object",
"properties": {
"reason": { "type": "string", "description": "Why this email is being sent" }
},
"required": ["reason"]
},
}

The AI provides only a reason parameter. The recipient email address comes from the contact record linked to the call.

AI calls send_email_to_caller({ "reason": "Follow up on appointment request" })
→ Look up call → get contact_id
→ Query contact_email (ordered by is_preferred DESC) → get recipient
→ GPT-5 composes email:
System: task description + "compose a professional email"
User: call transcription
Output: { subject: String, body: String }
→ Send via bases::email::send_email

GPT-5 generates both the subject line and body using structured output:

System prompt:

You are composing a follow-up email based on a phone call.
Task: {todo_description}
Compose a professional email with a clear subject line and body text
based on the task and call context.
The body should be plain text, suitable for both text and HTML rendering.

User prompt: The raw call transcription.

Output schema:

struct ComposedEmail {
subject: String,
body: String,
}

Both plain text and HTML email bodies receive the same composed.body — no separate HTML template is used.

  1. Fetch the call’s contact_id (error if no contact linked)
  2. Query contact_email filtered by contact_id, ordered by is_preferred DESC
  3. Take the first result as the recipient (error if no email on file)
  • No contact_id on the call → error returned to the AI agent
  • No email address for the contact → error returned to the AI agent
  • Email send failure → error propagated, todo marked as failed

SendEmailToCaller is a variant of the SystemTool enum:

pub enum SystemTool {
SendEmailToCaller,
}
MethodValue
display_name()"Send Email to Caller"
as_str()"send_email_to_caller"
from_str("send_email_to_caller")Some(SendEmailToCaller)

Tool assignments are stored in the todo_type_tool join table, linking TodoType to SystemTool variants.

  • Agent Tools Overview — voice and task tool systems
  • Todos — todo extraction, approval, and execution pipeline
  • Contact — contact email records used for recipient resolution