Build a rent-analysis agent
Stop downloading rent data into spreadsheets. Build an agent that pulls Zillow's county rents and tells you where your market stands.
If you own a rental, you've probably done this: go to Zillow's research page, download the rent file, open it in a spreadsheet, filter to your state, sort, and try to figure out whether your county is doing better or worse than the one next door. Then do it again next month.
This post replaces that with an agent. You ask it a question in plain English, like "Where are Florida rents falling?", and it pulls the data, runs the comparisons and tells you what it found. We'll build it in one Python file, test it without an API key, and run it on Florida.
Why an agent and not a spreadsheet
A spreadsheet answers the question you set it up for. "Which counties are below their 2023 peak?" is one sort. "Is that a trend or a blip?" is another tab. "Is there a pattern by region?" is you squinting at county names. An agent decides which of those to run, runs them, and writes up what it sees.
- Find Zillow's rent file
- Download the CSV
- Filter to your state
- Sort and chart
- Guess at the pattern
- Ask a question
- It picks the comparisons
- Tools pull and compute
- It explains what changed
There's one catch. Language models are bad at arithmetic and happy to make up a number that sounds right. So in this agent, the model never calculates anything. Small Python functions do the math, and the model only reads their results and explains them.
The data
Zillow's Observed Rent Index (ZORI) publishes a monthly rent index for most US counties as a free CSV. One row per county, one column per month. We load it once into a pandas table indexed by state and county; TiRE republishes the same series per county on its rent index page.
The tools
Three tools, each a plain function with a docstring the model reads:
state_overview(state): how many counties are rising, falling or at a record, plus the median 12-month change.rank_counties(state, sort_by, lowest_first, limit): counties sorted by 12-month change or by distance below their all-time high.county_detail(state, county): one county's 12-month change for each of the last 24 months.
All three read one shared table, computed in pandas:
def county_table(rents: pd.DataFrame, state: str) -> pd.DataFrame:
"""Latest rent, 12-month change, and distance from the all-time high for each county in a state."""
s = rents.loc[state.upper()].dropna(subset=[rents.columns[-1]])
latest, year_ago = s.columns[-1], s.columns[-13]
return pd.DataFrame(
{
"rent": s[latest].round(0),
"yoy_pct": (100 * (s[latest] / s[year_ago] - 1)).round(2),
"vs_peak_pct": (100 * (s[latest] / s.max(axis=1) - 1)).round(2),
"peak_month": s.idxmax(axis=1).str[:7],
}
).assign(as_of=latest[:7])Every tool result carries as_of, so the model can always say which month it's talking about.
The agent
The agent is the model, the tools and a short system prompt. The model is a parameter, which is what lets us test it offline:
SYSTEM_PROMPT = """You analyze rental markets for people who own a few rental properties.
- Every number you state comes from a tool result. Never calculate, estimate or round beyond the tool's output.
- Say which month the data runs through.
- Look for a pattern across counties (geography, size, timing) and say plainly what the data can't explain.
- End with what an owner should do differently because of the answer."""
def build_agent(model, rents: pd.DataFrame | None = None):
rents = load_rents() if rents is None else rents
return create_agent(model=model, tools=make_tools(rents), system_prompt=SYSTEM_PROMPT)create_agent comes from langchain. It runs the loop: call the model, run whatever tools it asks for, hand back the results, stop when it answers.
Test it without an API key
The test swaps Zillow's file for a four-county fixture and the model for a scripted fake, then checks that the tool really ran against the data:
def test_agent_answers_from_tool_results(rents):
call = {"name": "rank_counties", "args": {"state": "FL", "sort_by": "vs_peak_pct"}, "id": "1", "type": "tool_call"}
answer = "Lee County is furthest below its peak."
model = ScriptedModel(messages=iter([AIMessage(content="", tool_calls=[call]), AIMessage(content=answer)]))
result = build_agent(model, rents).invoke({"messages": [{"role": "user", "content": "Where is rent weakest?"}]})
tool_msg = next(m for m in result["messages"] if isinstance(m, ToolMessage))
assert "Lee County" in tool_msg.content
assert result["messages"][-1].content == answerTwo more tests check the pandas math against hand-computed values. All three pass in a clean environment with no keys set.
Run it on Florida
With claude-sonnet-5-5, the agent made three tool calls: state_overview for Florida, then rank_counties twice, once by 12-month change and once by distance below peak. The heart of its answer:
Long-term slump, southwest Gulf coast: Lee (-9.06%), Charlotte (-7.32%), Collier (-5.05%), Sarasota (-4.49%) and Manatee (-4.18%) are the five counties furthest below their peaks. Their peaks were between January 2023 and December 2023.
Recent, shallow dips: Putnam, Lake, Hillsborough, Monroe and Wakulla peaked between 2025 and mid-2026. They are only about 1% to 3% off their highs.
So Florida rent isn't falling statewide. The southwest Gulf coast is still well below where it peaked in 2023, while most of the state keeps rising. Lee County's rent has been below its year-earlier level every month since November 2023:
Its advice for owners held up: in Lee, Charlotte and Manatee, price new leases to today's market and don't assume a return to 2023 rents; where a county is barely 1% off a recent peak, check comparable listings before cutting.
Run it yourself
The full project (agent, tests, pinned requirements) is in our public repo. Install the requirements, run pytest, then set ANTHROPIC_API_KEY and ask it about your state. The model string is the only thing to change for another provider.
Before you use it
- It tracks asking rents on new listings, so use it to price your next lease, then check a few comps near your property before you change anything.
- Next: we'll turn these same tools into an MCP server, so Claude Desktop or Cursor can answer rent questions directly.