All jobs

Turn Buyer Inquiries in Each Real Estate Agent's Gmail Into CRM Leads

A real estate CRM makes one read-only agent per user that finds new buyer inquiries in their Gmail and returns each as a structured lead with a draft reply.

Run this on RushOpens the console with this prompt ready to send. Connect Gmail there first.

What the agent does

This is for a company that makes a CRM for residential real estate agents and small brokerages. Its users get buyer inquiries in Gmail from everywhere: notification emails from listing websites, replies to their own listing emails, a neighbor's forwarded introduction. Most of those never reach the CRM because copying them in takes a minute each. The company saves one template that reads mail and nothing else, POST /o/{org}/agents {"name": "Inquiry capture", "harness": "claude", "instructions": "…", "connections": [{"name": "gmail", "access": "read"}]}, and makes one agent per user from it with {"template": "<template id>", "name": "leads-<your user id>"}.

Because the template names Gmail at the read level, each user's consent page asks Google for gmail.readonly alone, and every run asks for that scope alone when it refreshes the token. The backend starts the sign-in with POST /o/{org}/agents/{agent}/connections {"type": "app", "name": "gmail"} and opens the authorize_url in a popup for the signed-in user. The CRM company registers no Google OAuth client, and does not go through Google's verification for a restricted mail scope on its own app.

Each run calls the Gmail API's users.messages.list with a q such as after:<last check, as seconds since the epoch> -from:me in:inbox and reads each message with users.messages.get. It decides which messages are a person asking about a home: a listing site's lead notification, a reply asking to see a property, an introduction from a past client. Newsletters, closing paperwork from a title company and messages from other agents about their own listings are skipped and counted, not returned.

For each inquiry it pulls what the CRM needs into fields: the buyer's name, email and phone as the message gives them, the property address or listing the message is about, where it came from, and what the buyer said about timing, financing or price, quoted rather than inferred. It writes a short reply the user can send, in the user's own voice from the prompt, and returns the Gmail message id and thread id so the CRM can link back and drop duplicates. It sends, labels and archives nothing: the token it asks for carries no scope for that.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "<agent id>",
  "input": "Find new buyer inquiries in my Gmail since 2026-11-12 18:00 America/Denver. Call users.messages.list with q 'after:1794531600 -from:me in:inbox' and read each with users.messages.get. An inquiry is a person (or a listing site's lead notification) asking about buying or seeing a home. Skip newsletters, transaction paperwork, and messages from other agents about their own listings; count what you skip by kind. For each inquiry return: gmail_message_id, thread_id, received_at, source (listing site name from the sender, direct email, or referral), buyer_name, buyer_email, buyer_phone, property (address or listing id as written), quotes (the buyer's own words about timing, financing or price), and reply_draft (at most 90 words, friendly, offering two showing times this week without naming exact times, signed 'Jordan'). Return only JSON: inquiries, skipped (counts by kind). Do not guess a phone number or an address that is not in the message."
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The answer is that JSON, in the session's result and in the run.completed webhook's data.result. The CRM matches the webhook's execution_id to the user it started the run for, drops any inquiry whose gmail_message_id it already has, and creates a lead for the rest with a link to the Gmail thread. The reply_draft sits on the lead with a Send button that goes through the CRM's own mail flow or opens the thread in Gmail, so the user decides what goes out.

What the user checks: that the lead is a real buyer and not a vendor pitch the agent misread, and that the contact details match the message. The agent copies only what the message says, so a listing site's notification that hides the buyer's email behind a relay address comes through as that relay address. skipped tells the user what the agent left out, which is how they notice a category it gets wrong and ask the CRM to adjust the template.

Run it on every every hour, per user

The CRM's scheduler sends one POST /o/{org}/sessions per user each hour during the day, naming that user's agent, with the time of the last check in input and a request_id that is a UUID v5 of the user's id and the hour. Runs past the key's concurrent limit are created queued and start as slots free, so a thousand users need no batching logic of their own.

A user who never finished connecting is refused 422 CONNECTION_NOT_READY before a sandbox starts; one who removed Rush in their Google account shows needs_reauth on GET /o/{org}/agents/{agent}/connections. The CRM shows a reconnect banner in both cases.

The use case this job follows, with its automation and trigger: Run an agent per customer task.

Why run it on Rush?

Lead capture from email has been tried with parsers per listing site, and each breaks when a site changes its template. An agent reads the message the way the user would and handles the long tail, such as a past client's forwarded introduction, that no parser covers. The difficult part for a CRM company is the mail access itself: Google's restricted-scope review, storing tokens for every user, and making sure no user's mail is ever read for another. On Rush each user's Gmail belongs to their own agent at the read level, and the company stores only agent ids.

Each run has its own computer and a record of every Gmail call and its cost. A session that used a Gmail connection is readable only by the person who started it and the org's owners and admins, and GET /o/{org}/sessions?account=<email> lists every run that touched a given mailbox, which answers a user who asks what was read and when. When a user leaves, DELETE /o/{org}/agents/{agent} disconnects their Gmail, revoking Rush's grant at Google unless another of the key creator's live agents, or the creator's own connection, holds the same Google account.

Frequently asked questions

Can the agent send the reply itself?

No. The template names Gmail at read, so the user's consent page and every token refresh ask Google for gmail.readonly alone, and the template's instructions forbid sending. The CRM sends the reply after the user presses Send.

Will it read personal mail?

It reads inbox messages since the last check to decide which are inquiries, which means it sees personal mail too. It returns only inquiries and counts the rest by kind. Users who keep a separate work account can connect that one instead.

What if a buyer writes twice about the same house?

Both messages come back with the same thread_id, and the CRM attaches the second to the existing lead rather than creating another. A buyer who writes from a new thread about the same address is matched by the CRM on email and property.

Does it work for a team that shares one inbox?

One agent holds one Gmail account. A team inbox gets its own agent, connected by whoever owns that account, and the CRM assigns its leads by its own routing rules.

More Gmail jobs

More jobs like this: Run an agent per customer task

Keep reading