How to avoid duplicate email sends with Hail MCP
Описание и применение
Рецепт автоматизации предотвращает дублирование отправки писем, используя ключи идемпотентности и внешнее хранение состояния, чтобы гарантировать, что письмо отправляется только один раз при сбоях соединения.
Задача
An AI agent sends an email, the service accepts it, but the connection drops before the agent receives an answer, leading to possible duplicate emails on retry.
Результат
Implementing idempotency keys and external state tracking prevents duplicate email sends when connections drop during AI agent retries.
Рабочий процесс
- Generate a unique idempotency key before the first send
- Pass the key and message details to Hail’s send_email tool
- Store campaign, lead, message, key, state, Hail email ID, and last attempt time in a database
- If a timeout occurs, mark the operation as unknown and do not requeue
- Before retrying, check Hail’s get_email or saved response for the key
- If the result is still unknown, pause for review instead of creating a new key
- Resume batch processing one message at a time, claiming operations atomically
- Test the lost-response scenario by simulating accept, drop, retry, and verify single acceptance
Доказательства
An AI agent sends an email, then the service accepts it, but the connection drops before the agent gets an answer.
Hail’s send_email tool accepts an idempotency_key. If you leave it out, the tool creates a fresh UUID for that invocation.
If the connection drops without a result, mark the operation as unknown. Do not quietly return it to the unsent list.
- Дата записи: 2026-10-20T21:56:02.469Z