Build an AI Real Estate Agent

Fully functional AI agent app with step-by-step instructions (100% opensource)

Finding the perfect property involves sifting through countless listings across multiple websites, analyzing location trends, and making informed investment decisions. For developers and real estate professionals, automating this process can save hours of manual work while providing deeper market insights.

In this tutorial, we'll build an AI Real Estate Agent that automates property search and market analysis. This agent will help users find properties matching their criteria while providing detailed location trends and investment recommendations, all through a clean user interface.

Let's look at our powerful tech stack:

  • Firecrawl's Extract Endpoint: A newly released API endpoint that simplifies collecting structured data from any number of URLs or entire domains, handling everything from crawling to parsing and organizing real estate data into clean, analysis-ready formats.

  • Agno (formerly Phidata): An open-source framework for building AI agents with memory and reasoning capabilities, helping us create specialized agents for property analysis.

  • OpenAI GPT-4o: The language model powering our agent's analysis and recommendations, providing human-like understanding of property details and market trends.

  • Streamlit: Creates a clean, interactive web interface for our real estate agent with minimal code.

Donโ€™t forget to share this tutorial on your social channels and tag Unwind AI (X, LinkedIn, Threads, Facebook) to support us!

What Weโ€™re Building

The AI Real Estate Agent automates property search and market analysis. It helps users find properties matching their criteria while providing detailed location trends and investment recommendations. This agent streamlines the property search process by combining data from multiple real estate websites and offering intelligent analysis.

Features
  • Smart Property Search: Uses Firecrawl's Extract endpoint to find properties across multiple real estate websites

  • Multi-Source Integration: Aggregates data from 99acres, Housing.com, Square Yards, Nobroker, and MagicBricks

  • Customizable Search: Filter by city, property type, category, and budget

  • Location Analysis: Provides detailed price trends and investment insights for different localities

  • AI-Powered Recommendations: Uses GPT-4o to analyze properties and provide structured recommendations

  • User-Friendly Interface: Clean Streamlit UI for easy property search and results viewing

Prerequisites

Before we begin, make sure you have the following:

  1. Python installed on your machine (version 3.10 or higher is recommended)

  2. Your OpenAI and Firecrawl API key

  3. A code editor of your choice (we recommend VS Code or PyCharm for their excellent Python support)

  4. Basic familiarity with Python programming

Step-by-Step Instructions

Setting Up the Environment

First, let's get our development environment ready:

  1. Clone the GitHub repository:

git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
  1. Go to the ai_real_estate_agent folder:

cd ai_agent_tutorials/ai_real_estate_agent
pip install -r requirements.txt
  1. Obtain your OpenAI and Firecrawl API keys.

Creating the Streamlit App

Letโ€™s create our app. Create a new file ai_real_estate_agent.py and add the following code:

  1. Let's set up our imports:

from typing import Dict, List
from pydantic import BaseModel, Field
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from firecrawl import FirecrawlApp
import streamlit as st
  1. Define our data models using Pydantic:

class PropertyData(BaseModel):
    """Schema for property data extraction"""
    building_name: str = Field(description="Name of the building/property", alias="Building_name")
    property_type: str = Field(description="Type of property (commercial, residential, etc)", alias="Property_type")
    location_address: str = Field(description="Complete address of the property")
    price: str = Field(description="Price of the property", alias="Price")
    description: str = Field(description="Detailed description of the property", alias="Description")

class PropertiesResponse(BaseModel):
    """Schema for multiple properties response"""
    properties: List[PropertyData] = Field(description="List of property details")
  1. Add location data models for price trends:

class LocationData(BaseModel):
    """Schema for location price trends"""
    location: str
    price_per_sqft: float
    percent_increase: float
    rental_yield: float

class LocationsResponse(BaseModel):
    """Schema for multiple locations response"""
    locations: List[LocationData] = Field(description="List of location data points")

class FirecrawlResponse(BaseModel):
    """Schema for Firecrawl API response"""
    success: bool
    data: Dict
    status: str
    expiresAt: str
  1. Create the PropertyFindingAgent class:

class PropertyFindingAgent:
    """Agent responsible for finding properties and providing recommendations"""
    
    def __init__(self, firecrawl_api_key: str, openai_api_key: str, model_id: str = "o3-mini"):
        self.agent = Agent(
            model=OpenAIChat(id=model_id, api_key=openai_api_key),
            markdown=True,
            description="I am a real estate expert who helps find and analyze properties based on user preferences."
        )
        self.firecrawl = FirecrawlApp(api_key=firecrawl_api_key)
  1. Implement property search functionality:

def find_properties(
    self, 
    city: str,
    max_price: float,
    property_category: str = "Residential",
    property_type: str = "Flat"
) -> str:
    formatted_location = city.lower()
    urls = [
        f"https://www.squareyards.com/sale/property-for-sale-in-{formatted_location}/*",
        f"https://www.99acres.com/property-in-{formatted_location}-ffid/*",
        f"https://housing.com/in/buy/{formatted_location}/{formatted_location}",
    ]
    
    # Property extraction logic here
  1. Add location trends analysis:

def get_location_trends(self, city: str) -> str:
    """Get price trends for different localities in the city"""
    raw_response = self.firecrawl.extract([
        f"https://www.99acres.com/property-rates-and-price-trends-in-{city.lower()}-prffid/*"
    ], {
        'prompt': """Extract price trends data for ALL major localities in the city.""",
        'schema': LocationsResponse.model_json_schema(),
    })
    # Analysis logic here
  1. Create the Streamlit UI setup:

def create_property_agent():
    if 'property_agent' not in st.session_state:
        st.session_state.property_agent = PropertyFindingAgent(
            firecrawl_api_key=st.session_state.firecrawl_key,
            openai_api_key=st.session_state.openai_key,
            model_id=st.session_state.model_id
        )
  1. Set up the main Streamlit interface:

def main():
    st.set_page_config(
        page_title="AI Real Estate Agent",
        page_icon="๐Ÿ ",
        layout="wide"
    )
    
    # Sidebar configuration
    with st.sidebar:
        st.title("๐Ÿ”‘ API Configuration")

        st.subheader("๐Ÿค– Model Selection")
        model_id = st.selectbox(
            "Choose OpenAI Model",
            options=["o3-mini", "gpt-4o"],
            help="Select the AI model to use. Choose gpt-4o if your api doesn't have access to o3-mini"
        )
        st.session_state.model_id = model_id
        
        st.divider()
        
        st.subheader("๐Ÿ” API Keys")
        firecrawl_key = st.text_input(
            "Firecrawl API Key",
            type="password",
            help="Enter your Firecrawl API key"
        )
        openai_key = st.text_input(
            "OpenAI API Key",
            type="password",
            help="Enter your OpenAI API key"
        )
  1. Add search form and property display:

col1, col2 = st.columns(2)
    with col1:
        city = st.text_input("City", placeholder="Enter city name")
        property_category = st.selectbox(
            "Property Category",
            options=["Residential", "Commercial"]
        )
    
    with col2:
        max_price = st.number_input("Maximum Price (in Crores)")
        property_type = st.selectbox(
            "Property Type",
            options=["Flat", "Individual House"]
        )
  1. Implement search functionality:

if st.button("๐Ÿ” Start Search", use_container_width=True):
        if 'property_agent' not in st.session_state:
            st.error("โš ๏ธ Please enter your API keys first!")
            return
            
        try:
            with st.spinner("๐Ÿ” Searching for properties..."):
                property_results = st.session_state.property_agent.find_properties(
                    city=city,
                    max_price=max_price,
                    property_category=property_category,
                    property_type=property_type
                )
  1. Display results and location analysis:

st.success("โœ… Property search completed!")
                st.subheader("๐Ÿ˜๏ธ Property Recommendations")
                st.markdown(property_results)
                
                with st.spinner("๐Ÿ“Š Analyzing location trends..."):
                    location_trends = st.session_state.property_agent.get_location_trends(city)
                    with st.expander("๐Ÿ“ˆ Location Trends Analysis"):
                        st.markdown(location_trends)

Running the App

With our code in place, it's time to launch the app.

  • In your terminal, navigate to the project folder, and run the following command

streamlit run ai_real_estate_agent.py
Using the App:
  1. Enter API Keys:

    • Input your Firecrawl and OpenAI API keys in the sidebar

    • Keys are securely stored in the session state

  2. Set Search Criteria:

    • Enter the city name

    • Select property category (Residential/Commercial)

    • Choose property type (Flat/Individual House)

    • Set maximum budget in Crores

  3. View Results:

    • Property recommendations with detailed analysis

    • Location trends with investment insights

    • Expandable sections for easy reading

Working Application Demo

Conclusion

You've successfully built an AI Real Estate Agent that combines web scraping, data analysis, and AI-powered insights into a user-friendly application. This agent can search across multiple real estate websites, analyze properties, and provide detailed location insights, all through a clean Streamlit interface.

For further enhancements, consider:

  • Advanced Filtering: Add more granular search filters like amenities, age of property, or specific floor preferences

  • Historical Price Analysis: Integrate historical price data to show property value trends over time

  • Image Analysis: Add AI-powered image analysis to evaluate property conditions from listing photos

  • User Preferences Learning: Implement a system to learn from user interactions and refine future property recommendations

  • Other features: Add features like automated property valuation, neighborhood safety analysis, or even integrate with mapping services for location-based insights.

Keep experimenting with different agent configurations and specialized roles to build even more sophisticated AI systems.

We share hands-on tutorials like this 2-3 times a week, to help you stay ahead in the world of AI. If you're serious about leveling up your AI skills and staying ahead of the curve, subscribe now and be the first to access our latest tutorials.

Donโ€™t forget to share this tutorial on your social channels and tag Unwind AI (X, LinkedIn, Threads, Facebook) to support us!

Reply

or to participate.