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.
- 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
- 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
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
-
Clone the repository
git clone <repository-url> cd lang-example2
-
Create a virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
cp .env.example .env
Edit
.envand add your OpenAI API key:OPENAI_API_KEY=your_api_key_here OPENAI_MODEL=gpt-4o-mini
Start the FastAPI server:
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
GET /Returns application status and version information.
POST /chatSend 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:..."
}curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"question": "What properties are available in Zapopan?",
"thread_id": "session_1"
}'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"])The AI agent has access to the following tools:
-
search_properties: Search for properties by city
- Input: city name (string)
- Output: List of matching properties with details
-
calculate_mortgage: Calculate mortgage payments
- Input: property details and loan parameters
- Output: Monthly payment calculations
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
pytest tests/Once the server is running, access the interactive API documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
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)
This project is provided as-is for educational and demonstration purposes.
Contributions are welcome! Please feel free to submit a Pull Request.