- unwind ai
- Posts
- Build an AI Real Estate Agent
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.
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:
Step-by-Step Instructions
Setting Up the Environment
First, let's get our development environment ready:
Clone the GitHub repository:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
Go to the ai_real_estate_agent folder:
cd ai_agent_tutorials/ai_real_estate_agent
Install the required dependencies:
pip install -r requirements.txt
Creating the Streamlit App
Letโs create our app. Create a new file ai_real_estate_agent.py
and add the following code:
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
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")
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
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)
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
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
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
)
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"
)
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"]
)
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
)
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
Streamlit will provide a local URL (typically http://localhost:8501).
Using the App:
Enter API Keys:
Input your Firecrawl and OpenAI API keys in the sidebar
Keys are securely stored in the session state
Set Search Criteria:
Enter the city name
Select property category (Residential/Commercial)
Choose property type (Flat/Individual House)
Set maximum budget in Crores
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.
Reply