Skip to Content

AI Agent Integration — How it works

The window.postMessage contract between the portal and an embedded AI. Overview: AI Agent Integration.

Where it lives

The bridge is the SupportAgent component (components/pages/search/components/SupportAgent/), mounted in the search experience when the aiAgent flag is on. It reads live search state via useSearch and talks to the agent iframe over postMessage. Every message carries a generated sessionId.

The message protocol

Portal → Agent (the portal pushes context):

MessagePayloadWhen
InitSessionuserAgent, userNameAfter the agent signals AgentReady.
Listingscount, listings, statisticsOn results change, or on RequestListings.
ListingDetailslistingWhen a listing is opened/cached.
FiltersfiltersReply to ExtractFilters (NLP result).
WindowVisible / WindowHidden—Chat panel open/close.
CloseListing—When the listing dialog closes.

Agent → Portal (the agent drives the portal):

MessagePayloadEffect
AgentReady—Portal sends InitSession + current Listings.
RequestListings—Portal replies with Listings.
ExtractFiltersqueryPortal runs NLP (APIChat.fetchReply) → replies Filters.
ApplyFiltersfiltersPortal applies them (setFilters).
ResetFilters—Portal clears filters.
OpenListingmlsNumber, boardIdPortal opens that listing.
CloseListing—Portal clears the cached listing.
ResetAgent—Portal resets the NLP token.

Note the natural-language path: the agent sends ExtractFilters{query}, the portal turns it into MLS filters via the backend NLP endpoint, returns Filters, and the agent (or the user) can then ApplyFilters. The AI never touches the MLS API — it goes through the portal.

Modes

  • Embedded — SupportAgent renders a chat button + panel with the agent iframe (config.iframeUrl from NEXT_PUBLIC_AI_AGENT_IFRAME_URL, with sessionId appended).
  • Headless — when headlessIframeId is set, SupportAgent renders nothing; it locates an external iframe already in the DOM (by id, via a MutationObserver) and posts to that. This is how a host system plugs its own AI in without portal UI.

Configuration

Config / env / flagRole
@configs/features aiAgentEnables the bridge.
NEXT_PUBLIC_AI_AGENT_IFRAME_URLThe embedded agent’s iframe URL.
@configs/ai-agent headlessIframeIdDOM id of an external iframe for headless mode (empty = embedded).

Gotchas & hints

  • The protocol is the integration surface. Any assistant that speaks these messages can be connected — the AI is swappable; the portal side is fixed.
  • Session-scoped. The portal stamps sessionId on every outbound message and several inbound handlers ignore messages without it.
  • Headless renders no UI — if you enable headlessIframeId but no matching iframe appears, nothing happens (the observer just keeps waiting).
  • NLP runs server-side through APIChat.fetchReply; the returned token is reused across queries and reset by ResetAgent.

Verified protocol boundary

Source review: e30dd9b47, 2026-11-02, including SupportAgent.tsx and packages/ai-agent-client/src/App.tsx. Outbound messages use '*'; receivers do not check origin/source or enforce session-id equality. Presence checks on some messages are not session authentication. The reference client emits AgentReset, while the portal handler is named ResetAgent, so that reset action does not match. No origin hardening or protocol change was made in this docs task.

F03 traces extraction/apply separately and documents the null-filter failure path. This contract review does not claim an executed end-to-end assistant session.

Last updated on