房产搜索代理
LangGraph ReAct代理接受自然语言属性搜索请求,通过Playwright MCP子流程导航domain.com.au,并通过FastAPI SSE API和单页web UI流式返回结果。
需求
- Python 3.12
- Node.js(必需
@playwright/mcp) - 克劳德代码 (用于开发技能和钩子)
设置
# Create and activate a conda environment (or venv)
conda create -n rental-search python=3.12
conda activate rental-search
# Install Python dependencies
pip install -r requirements-dev.txt
# Install Node dependencies (Playwright MCP)
npm install
# Configure environment
cp .env.example .env
# Edit .env and fill in:
# OPENAI_API_KEY — required (LangGraph agent)
# GOOGLE_MAPS_API_KEY — optional (school-distance filtering)
跑步
uvicorn main:app --reload
# or via skill:
/dev-server
服务器启动时间 http://localhost:8000
| 端点 | 描述 |
|---|
GET / | 房产搜索聊天界面 |
GET /health | 健康检查 |
GET /tools | 列出已注册的MCP工具 |
POST /search | 开始搜索运行,返回 run_id |
GET /stream/{run_id} | SSE搜索进度和结果流 |
POST /chat | 会话聊天端点 |
测试
pytest
# or via skill:
/lint
项目结构
.
├── main.py # FastAPI app, lifespan, routes
├── config.py # Settings from .env via pydantic-settings
├── agent/
│ ├── __init__.py # LangGraph ReAct property search agent
│ ├── chat_graph.py # LangGraph chat workflow (async/sync tool routing)
│ ├── enrichment.py # School-distance filtering via Google Maps API
│ ├── models.py # PropertyListing Pydantic model
│ └── url_builder.py # domain.com.au URL builder + listing parser
├── api/
│ ├── chat.py # POST /chat endpoint
│ ├── search.py # POST /search + SSE event translation
│ └── stream.py # GET /stream/{run_id} SSE endpoint
├── mcp_subprocess/ # Playwright MCP subprocess lifecycle
├── templates/
│ └── index.html # Single-page chat UI (noir concierge design)
├── tests/ # pytest unit tests
├── requirements.txt # Runtime dependencies
├── requirements-dev.txt # Dev dependencies
└── .env.example # Environment variable reference
Claude代码技能
项目范围内的技能 .claude/commands/ --在此目录中工作时可用:
| 技能 | 描述 |
|---|
/dev-server | 通过热重新加载启动FastAPI |
/run-search | 启动搜索查询并流式传输SSE结果 |
/check-agent | 检查MCP工具和代理运行状况 |
/test-enrichment [school] | 烟雾测试学校距离过滤 |
/lint | 在代码库中运行ruff+mypy |
/preview | 使用Playwright对UI进行截图并审查设计 |
挂钩
配置于 .claude/settings.json:
| 钩子 | 触发器 | 动作 |
|---|
PostToolUse | 编辑或写入任何 .py 文件 | 运行 ruff 自动剥皮 |
插件
| 插件 | 来源 | 目的 |
|---|
frontend-design | claude-plugins-official | 独特的前端UI生成 |
CI/GitHub操作
| 工作流 | 触发器 | 它的作用 |
|---|
ci.yml | 推/PR到主 | 绒毛+皮棉测试 |
claude.yml | @claude 在公关/问题中提及 | 按需克劳德回应 |
claude-code-review.yml | PR打开/更新 | 自动Claude代码审查 |