AI engineering case study
Sales Enquiry Agent
Turns incoming enquiries into editable lead proposals and follow-up drafts, with approval before any CRM write.
Python · FastAPI · SQLite · OpenAI tool calling
4 passed
Integration tests
1 lead
From two concurrent approvals for the same email
0 writes
Before reviewer approval
The problem
Sales messages arrive as unstructured text. A reviewer needs the contact details, a suggested follow-up, and a duplicate check before adding the lead to the CRM.
How it works
Extract the proposed lead
A sample enquiry supplies a name, email, and interest. The workflow normalizes the email and prepares a follow-up for review.
Review before committing
The reviewer can edit the proposed lead fields. The extraction tool only proposes data, and the approval endpoint is the only route that writes a lead.
Handle duplicates and retries
Approval rechecks the normalized email inside the write transaction. Concurrent approvals resolve to one lead. Identical retries return the original result.
Engineering decisions
The CRM makes the final duplicate decision inside the transaction, even if two drafts initially appear unique. This keeps the approval flow consistent when several reviewers act at once.
What was tested
Four integration tests covered extraction, ambiguous contacts, concurrent approval, and untrusted model output. The CRM is a local sandbox. The optional OpenAI path was tested using a mocked response.
Inspect the integration tests ↗