Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Real Estate AI Agent

A sophisticated AI-powered real estate assistant built with FastAPI, LangChain, and LangGraph. This agent helps users search for properties and calculate mortgage payments using natural language conversations.

Features

  • Property Search: Search available properties by city with detailed information including neighborhood, bedrooms, bathrooms, price, and descriptions
  • Mortgage Calculator: Calculate mortgage payments for properties
  • Conversational AI: Natural language interface powered by GPT-4o-mini
  • Memory Persistence: Maintains conversation context across sessions using thread IDs
  • RESTful API: Clean FastAPI endpoints for integration

Tech Stack

  • FastAPI: Modern, fast web framework for building APIs
  • LangChain: Framework for building language model applications
  • LangGraph: Library for building stateful, multi-actor applications with LLMs
  • OpenAI GPT-4o-mini: Language model for AI reasoning
  • Pydantic: Data validation using Python type annotations
  • Uvicorn: ASGI server for running FastAPI applications

Project Structure

lang-example2/
├── app/
│   ├── api/
│   │   └── routes.py          # API endpoints
│   ├── config/
│   │   └── settings.py        # Configuration settings
│   ├── database/
│   │   └── fake_db.py         # Sample property database
│   ├── memory/
│   │   └── checkpoint.py      # Conversation memory management
│   ├── models/
│   │   ├── chat.py            # Chat request/response models
│   │   └── property.py        # Property data model
│   ├── tools/
│   │   ├── mortgage_tools.py  # Mortgage calculation tools
│   │   └── property_tools.py  # Property search tools
│   ├── graph.py               # LangGraph agent configuration
│   ├── main.py                # FastAPI application entry point
│   └── prompts.py             # System prompts for the AI agent
├── tests/                     # Test directory
├── docs/                      # Documentation directory
├── docker/                    # Docker configuration
├── requirements.txt           # Python dependencies
├── .env.example              # Environment variables template
└── README.md                 # This file

Installation

  1. Clone the repository

    git clone <repository-url>
    cd lang-example2
  2. Create a virtual environment

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables

    cp .env.example .env

    Edit .env and add your OpenAI API key:

    OPENAI_API_KEY=your_api_key_here
    OPENAI_MODEL=gpt-4o-mini
    

Usage

Running the Application

Start the FastAPI server:

uvicorn app.main:app --reload

The API will be available at http://localhost:8000

API Endpoints

Health Check

GET /

Returns application status and version information.

Chat Endpoint

POST /chat

Send questions to the AI agent.

Request Body:

{
  "question": "Show me properties in Zapopan",
  "thread_id": "user_session_123"
}

Response:

{
  "answer": "I found 2 properties in Zapopan:..."
}

Example Usage with cURL

curl -X POST "http://localhost:8000/chat" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What properties are available in Zapopan?",
    "thread_id": "session_1"
  }'

Example Usage with Python

import requests

response = requests.post(
    "http://localhost:8000/chat",
    json={
        "question": "Calculate mortgage for a 5.8M property with 20% down payment",
        "thread_id": "session_1"
    }
)

print(response.json()["answer"])

Available Tools

The AI agent has access to the following tools:

  1. search_properties: Search for properties by city

    • Input: city name (string)
    • Output: List of matching properties with details
  2. calculate_mortgage: Calculate mortgage payments

    • Input: property details and loan parameters
    • Output: Monthly payment calculations

Sample Data

The application includes sample properties in the Guadalajara metropolitan area:

  • Zapopan - Puerta de Hierro: 3BR/2BA luxury apartment - $5,800,000
  • Guadalajara - Providencia: 4BR/3BA family house - $7,200,000
  • Zapopan - Valle Real: 2BR/2BA modern condo - $4,300,000

Development

Running Tests

pytest tests/

API Documentation

Once the server is running, access the interactive API documentation:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Configuration

The application can be configured through environment variables:

  • OPENAI_API_KEY: Your OpenAI API key (required)
  • OPENAI_MODEL: The OpenAI model to use (default: gpt-4o-mini)

License

This project is provided as-is for educational and demonstration purposes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages