buildocc 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. buildocc-1.0.0.dist-info/METADATA +727 -0
  2. buildocc-1.0.0.dist-info/RECORD +50 -0
  3. buildocc-1.0.0.dist-info/WHEEL +5 -0
  4. buildocc-1.0.0.dist-info/entry_points.txt +8 -0
  5. buildocc-1.0.0.dist-info/licenses/LICENSE +187 -0
  6. buildocc-1.0.0.dist-info/top_level.txt +1 -0
  7. occupant_agent/__init__.py +190 -0
  8. occupant_agent/agent/__init__.py +0 -0
  9. occupant_agent/agent/memory.py +282 -0
  10. occupant_agent/agent/occupant.py +761 -0
  11. occupant_agent/agent/persona.py +508 -0
  12. occupant_agent/analysis/__init__.py +28 -0
  13. occupant_agent/analysis/metrics.py +210 -0
  14. occupant_agent/analysis/simulation_log.py +176 -0
  15. occupant_agent/api/__init__.py +0 -0
  16. occupant_agent/api/app.py +248 -0
  17. occupant_agent/cli.py +298 -0
  18. occupant_agent/core/__init__.py +49 -0
  19. occupant_agent/core/base_memory.py +127 -0
  20. occupant_agent/core/base_persona.py +185 -0
  21. occupant_agent/core/base_scheduler.py +78 -0
  22. occupant_agent/core/registry.py +188 -0
  23. occupant_agent/data/README.txt +20 -0
  24. occupant_agent/data/activity_frequency_O1.csv +51 -0
  25. occupant_agent/data/activity_frequency_O2.csv +51 -0
  26. occupant_agent/data/activity_frequency_O3.csv +51 -0
  27. occupant_agent/data/activity_frequency_O4.csv +51 -0
  28. occupant_agent/data/mapping_coverage.csv +4 -0
  29. occupant_agent/data/schedule_peak_hours.csv +65 -0
  30. occupant_agent/data/tewhere_validation.csv +8 -0
  31. occupant_agent/data/time_at_activity.csv +1537 -0
  32. occupant_agent/data/time_of_day_distributions.csv +673 -0
  33. occupant_agent/environment/__init__.py +0 -0
  34. occupant_agent/environment/simulation.py +645 -0
  35. occupant_agent/environment/state.py +86 -0
  36. occupant_agent/grounding/__init__.py +0 -0
  37. occupant_agent/grounding/activity_code_map.py +747 -0
  38. occupant_agent/grounding/fixed_schedule.py +124 -0
  39. occupant_agent/grounding/scheduler.py +285 -0
  40. occupant_agent/llm/__init__.py +1 -0
  41. occupant_agent/llm/client.py +226 -0
  42. occupant_agent/mcp_server/__init__.py +0 -0
  43. occupant_agent/mcp_server/server.py +303 -0
  44. occupant_agent/persistence/__init__.py +0 -0
  45. occupant_agent/persistence/store.py +409 -0
  46. occupant_agent/py.typed +0 -0
  47. occupant_agent/testing/__init__.py +48 -0
  48. occupant_agent/testing/conformance.py +228 -0
  49. occupant_agent/testing/fixtures.py +170 -0
  50. occupant_agent/testing/mock_llm.py +141 -0
@@ -0,0 +1,727 @@
1
+ Metadata-Version: 2.4
2
+ Name: buildocc
3
+ Version: 1.0.0
4
+ Summary: ATUS-grounded LLM occupant agents for building energy simulation
5
+ Author-email: Wooyoung Jung <j2prosperous@gmail.com>
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship made available under
41
+ the License, as indicated by a copyright notice that is included in
42
+ or attached to the work (an example is provided in the Appendix below).
43
+
44
+ "Derivative Works" shall mean any work, whether in Source or Object
45
+ form, that is based on (or derived from) the Work and for which the
46
+ editorial revisions, annotations, elaborations, or other modifications
47
+ represent, as a whole, an original work of authorship. For the purposes
48
+ of this License, Derivative Works shall not include works that remain
49
+ separable from, or merely link (or bind by name) to the interfaces of,
50
+ the Work and Derivative Works thereof.
51
+
52
+ "Contribution" shall mean, as defined by Sections 2 through 9 of this
53
+ document, any work of authorship, including the original version of
54
+ the Work and any modifications or additions to that Work or Derivative
55
+ Works of the Work, that is intentionally submitted to the Licensor for
56
+ inclusion in the Work by the copyright owner or by an individual or
57
+ Legal Entity authorized to submit on behalf of the copyright owner.
58
+ For the purposes of this definition, "submitted" means any form of
59
+ electronic, verbal, or written communication sent to the Licensor or
60
+ its representatives, including but not limited to communication on
61
+ electronic mailing lists, source code control systems, and issue
62
+ tracking systems that are managed by, or on behalf of, the Licensor
63
+ for the purpose of discussing and improving the Work, but excluding
64
+ communication that is conspicuously marked or designated in writing
65
+ by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
68
+ whom a Contribution has been received by the Licensor and included
69
+ within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contributions
86
+ with the Work to which such Contributions were submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or Derivative
100
+ Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, You must include a readable copy of the
113
+ attribution notices contained within such NOTICE file, in
114
+ at least one of the following places: within a NOTICE text
115
+ file distributed as part of the Derivative Works; within
116
+ the Source form or documentation, if provided along with the
117
+ Derivative Works; or, within a display generated by the
118
+ Derivative Works, if and wherever such third-party notices
119
+ normally appear. The contents of the NOTICE file are for
120
+ informational purposes only and do not modify the License.
121
+ You may add Your own attribution notices within Derivative
122
+ Works that You distribute, alongside or in addition to the
123
+ NOTICE text from the Work, provided that such additional
124
+ attribution notices cannot be construed as modifying the License.
125
+
126
+ You may add Your own license statement for Your modifications and
127
+ may provide additional grant of rights to use, copy, modify, merge,
128
+ publish, distribute, sublicense, and/or sell copies of the
129
+ Contribution, and to permit persons to whom the Contribution is
130
+ furnished to do so.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or reproducing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or exemplary damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or all other
164
+ commercial damages or losses), even if such Contributor has been
165
+ advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may offer such
172
+ obligations only on Your own behalf and on Your sole responsibility,
173
+ not on behalf of any other Contributor, and only if You agree to
174
+ indemnify, defend, and hold each Contributor harmless for any
175
+ liability incurred by, or claims asserted against, such Contributor
176
+ by reason of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ Copyright 2026 Wooyoung Jung
181
+
182
+ Licensed under the Apache License, Version 2.0 (the "License");
183
+ you may not use this file except in compliance with the License.
184
+ You may obtain a copy of the License at
185
+
186
+ http://www.apache.org/licenses/LICENSE-2.0
187
+
188
+ Unless required by applicable law or agreed to in writing, software
189
+ distributed under the License is distributed on an "AS IS" BASIS,
190
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
191
+ See the License for the specific language governing permissions and
192
+ limitations under the License.
193
+
194
+ Project-URL: Repository, https://github.com/humanbuildingsynergy/BuildOcc
195
+ Project-URL: Issues, https://github.com/humanbuildingsynergy/BuildOcc/issues
196
+ Keywords: building energy,occupant behavior,LLM agents,ATUS,MCP,demand response,generative agents
197
+ Classifier: Development Status :: 4 - Beta
198
+ Classifier: Intended Audience :: Science/Research
199
+ Classifier: License :: OSI Approved :: Apache Software License
200
+ Classifier: Topic :: Scientific/Engineering
201
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
202
+ Classifier: Programming Language :: Python :: 3.11
203
+ Classifier: Programming Language :: Python :: 3.12
204
+ Classifier: Typing :: Typed
205
+ Requires-Python: >=3.11
206
+ Description-Content-Type: text/markdown
207
+ License-File: LICENSE
208
+ Requires-Dist: pydantic>=2.0
209
+ Requires-Dist: anthropic>=0.30
210
+ Requires-Dist: openai>=1.30
211
+ Requires-Dist: fastapi>=0.111
212
+ Requires-Dist: uvicorn[standard]>=0.30
213
+ Requires-Dist: httpx>=0.27
214
+ Requires-Dist: sqlalchemy>=2.0
215
+ Requires-Dist: mcp>=1.0
216
+ Requires-Dist: pandas>=2.1
217
+ Requires-Dist: numpy>=1.26
218
+ Requires-Dist: python-dotenv>=1.0
219
+ Requires-Dist: pyyaml>=6.0
220
+ Provides-Extra: dev
221
+ Requires-Dist: pytest>=8.0; extra == "dev"
222
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
223
+ Requires-Dist: ruff>=0.4; extra == "dev"
224
+ Requires-Dist: mypy>=1.10; extra == "dev"
225
+ Provides-Extra: google
226
+ Requires-Dist: google-generativeai>=0.8; extra == "google"
227
+ Provides-Extra: analysis
228
+ Requires-Dist: scipy>=1.12; extra == "analysis"
229
+ Requires-Dist: ipykernel>=6.0; extra == "analysis"
230
+ Requires-Dist: jupyterlab>=4.0; extra == "analysis"
231
+ Dynamic: license-file
232
+
233
+ # BuildOcc
234
+
235
+ ATUS-grounded LLM occupant agents for building energy simulation.
236
+
237
+ Agents are initialized from American Time Use Survey (ATUS) population microdata, reason over environment state using an LLM at each 15-minute timestep, and accumulate a memory stream that enables persistent behavior change. The library is exposed through a three-layer platform interface — Python library, REST API, and MCP server — so any building energy tool can integrate an occupant behavioral layer without bespoke coupling code.
238
+
239
+ ## Architecture
240
+
241
+ ```
242
+ ┌─────────────────────────────────────────┐
243
+ │ Layer 3 — MCP Server │ ← Claude / LLM orchestrators,
244
+ │ (tool-calling interface for LLM apps) │ Home Assistant (native MCP client)
245
+ └────────────────┬────────────────────────┘
246
+ │ wraps
247
+ ┌────────────────▼────────────────────────┐
248
+ │ Layer 2 — REST API (FastAPI) │ ← EnergyPlus Python callbacks,
249
+ │ (standard HTTP, platform-agnostic) │ VOLTTRON, OpenStudio, any script
250
+ └────────────────┬────────────────────────┘
251
+ │ calls
252
+ ┌────────────────▼────────────────────────┐
253
+ │ Layer 1 — Python Agent Library │ ← Direct import, unit tests,
254
+ │ (core logic, no network dependency) │ research scripts
255
+ └─────────────────────────────────────────┘
256
+ ```
257
+
258
+ ## Requirements
259
+
260
+ - Python ≥ 3.11
261
+ - An LLM API key — set one of:
262
+ - `ANTHROPIC_API_KEY` (default provider, `claude-haiku-4-5`)
263
+ - `OPENAI_API_KEY` (provider `openai`, `gpt-4o-mini`)
264
+ - `GOOGLE_API_KEY` (provider `google`, `gemini-2.0-flash`) — install: `pip install "buildocc[google]"`
265
+ - Ollama running locally (provider `ollama`, `llama3.2`) — no extra package needed
266
+
267
+ ## Installation
268
+
269
+ ```bash
270
+ git clone https://github.com/humanbuildingsynergy/BuildOcc
271
+ cd BuildOcc
272
+ pip install -e ".[dev]"
273
+
274
+ # Set your API key — the library loads .env automatically via python-dotenv
275
+ cp .env.example .env
276
+ # Then edit .env and replace the placeholder with your real key
277
+ ```
278
+
279
+ ## Quick Start
280
+
281
+ ### Layer 1 — Python library (direct import)
282
+
283
+ ```python
284
+ from datetime import datetime
285
+ from occupant_agent import OccupantAgent, DeviceState, EnvironmentState, RoomState, ActivityScheduler
286
+
287
+ # Create an ATUS-grounded agent for an employed single adult (25–44)
288
+ agent = OccupantAgent.from_stratum("O1", seed=42, llm_provider="anthropic")
289
+
290
+ # Sample the agent's current activity from empirical ATUS distributions
291
+ scheduler = ActivityScheduler(stratum="O1", seed=42)
292
+ timestep = datetime(2024, 7, 15, 19, 0)
293
+ atus_code = scheduler.sample(timestep) # e.g. "120303" — computer leisure
294
+
295
+ # Build an environment state
296
+ env = EnvironmentState(
297
+ timestep=timestep,
298
+ zone_temp_c=25.0,
299
+ outdoor_temp_c=34.0,
300
+ tou_rate=0.22, # peak rate $/kWh
301
+ devices=[
302
+ DeviceState(device_id="hvac", state=True, power_w=3500),
303
+ DeviceState(device_id="washer", state=False, power_w=500),
304
+ ],
305
+ rooms=[RoomState(room_id="living_room", occupied=True)],
306
+ )
307
+
308
+ # Step: agent reasons over persona + memory + environment → action
309
+ action = agent.step(env, atus_code=atus_code)
310
+ print(action.action_type, action.target_id, action.reasoning)
311
+ # e.g. "toggle_device" "hvac" "Peak rate is $0.22/kWh and I'm comfortable..."
312
+
313
+ # Send a demand-response signal (Type B — educational)
314
+ response = agent.receive_signal(
315
+ signal_type="B",
316
+ content="Your HVAC costs 3× more before 9pm. Raising the setpoint by 2°C saves ~$0.35 today.",
317
+ env=env,
318
+ )
319
+ print(response.response, response.reasoning)
320
+ # e.g. "accepted" "Makes economic sense and I'm not uncomfortable at 26°C..."
321
+ ```
322
+
323
+ **Signal types:**
324
+ | Type | Label | Description |
325
+ |------|-------|-------------|
326
+ | A | Direct command | "Turn off the dishwasher until 9pm" |
327
+ | B | Competence-building (boost) | Price/cost explanation for why a change helps |
328
+ | C | Social norm (nudge) | Comparison to similar households |
329
+
330
+ **Demographic strata:**
331
+ | ID | ATUS Stratum |
332
+ |----|-------------|
333
+ | O1 | Employed adult, single, 25–44 |
334
+ | O2 | Retired couple, 65+ |
335
+ | O3 | Employed parent with children, 35–54 |
336
+ | O4 | Unemployed adult, 25–44 |
337
+
338
+ ### Full simulation loop
339
+
340
+ The library reads `ANTHROPIC_API_KEY` (or whichever provider key) directly from `.env` — no shell export needed.
341
+
342
+ ```bash
343
+ # Runs 8 timesteps of a O1 evening with ATUS-sampled activities + a Type B signal
344
+ python3 examples/simulation_loop.py --stratum O1 --seed 42 --steps 8
345
+
346
+ # Other providers
347
+ python3 examples/simulation_loop.py --stratum O2 --provider openai --steps 16 --start-hour 6
348
+ python3 examples/simulation_loop.py --provider google --stratum O3 # Google Gemini
349
+ python3 examples/simulation_loop.py --provider ollama --stratum O1 # local Ollama
350
+
351
+ # Offline / no API key (deterministic mock responses — useful for CI and testing)
352
+ python3 examples/simulation_loop.py --mock --stratum O1 --steps 4
353
+
354
+ # Other flags
355
+ python3 examples/simulation_loop.py --zone-temp 78.5 # override zone temp (°C)
356
+ python3 examples/simulation_loop.py --hardcode # fixed ATUS codes (ablation baseline)
357
+ ```
358
+
359
+ ### Demand response signal demo
360
+
361
+ Shows all three signal types (A/B/C), cross-stratum comparison, and the `extra_context` kwarg:
362
+
363
+ ```bash
364
+ python3 examples/signal_demo.py # all three parts, Anthropic
365
+ python3 examples/signal_demo.py --part 2 # stratum comparison only
366
+ python3 examples/signal_demo.py --provider openai --warmup 4
367
+ python3 examples/signal_demo.py --mock # offline mock mode
368
+ ```
369
+
370
+ ### Layer 2 — REST API
371
+
372
+ ```bash
373
+ # Start the server
374
+ ANTHROPIC_API_KEY=... buildocc-api
375
+ # or: uvicorn occupant_agent.api.app:app --reload --port 8000
376
+ ```
377
+
378
+ ```bash
379
+ # Initialize an agent
380
+ curl -s -X POST http://localhost:8000/agents/initialize \
381
+ -H "Content-Type: application/json" \
382
+ -d '{"stratum": "O1", "seed": 42}' | python3 -m json.tool
383
+ # → {"agent_id": "...", "stratum": "O1", "seed": 42}
384
+
385
+ # Step (replace AGENT_ID)
386
+ curl -s -X POST http://localhost:8000/agents/AGENT_ID/step \
387
+ -H "Content-Type: application/json" \
388
+ -d '{
389
+ "environment": {
390
+ "timestep": "2024-07-15T19:00:00",
391
+ "zone_temp_c": 25.0, "outdoor_temp_c": 34.0, "tou_rate": 0.22,
392
+ "devices": [{"device_id": "hvac", "state": true, "power_w": 3500}],
393
+ "rooms": [{"room_id": "living_room", "occupied": true}]
394
+ },
395
+ "atus_code": "120303"
396
+ }' | python3 -m json.tool
397
+
398
+ # Send a demand-response signal
399
+ curl -s -X POST http://localhost:8000/agents/AGENT_ID/signal \
400
+ -H "Content-Type: application/json" \
401
+ -d '{
402
+ "signal_type": "B",
403
+ "content": "Your HVAC costs 3x more before 9pm. Raising the setpoint 2°C saves ~$0.35 today.",
404
+ "environment": {
405
+ "timestep": "2024-07-15T17:00:00",
406
+ "zone_temp_c": 25.0,
407
+ "outdoor_temp_c": 34.0,
408
+ "tou_rate": 0.22,
409
+ "devices": [{"device_id": "hvac", "state": true, "power_w": 3500}],
410
+ "rooms": [{"room_id": "living_room", "occupied": true}]
411
+ }
412
+ }' | python3 -m json.tool
413
+
414
+ # Check agent state (memory count, last action, reflection history)
415
+ curl -s http://localhost:8000/agents/AGENT_ID/state | python3 -m json.tool
416
+ ```
417
+
418
+ **REST endpoints:**
419
+ | Method | Endpoint | Description |
420
+ |--------|----------|-------------|
421
+ | POST | `/agents/initialize` | Create agent; returns `agent_id` |
422
+ | POST | `/agents/{id}/step` | Advance one 15-min timestep; returns `AgentAction` |
423
+ | POST | `/agents/{id}/signal` | Deliver A/B/C signal; returns `SignalResponse` |
424
+ | GET | `/agents/{id}/state` | Memory count, last action, reflection history |
425
+ | GET | `/agents/` | List all agents |
426
+ | DELETE | `/agents/{id}` | Delete agent and all records |
427
+ | GET | `/health` | `{status: "ok", version: "1.0.0"}` |
428
+
429
+ ### Layer 3 — MCP server
430
+
431
+ ```bash
432
+ # Requires the REST API to be running first
433
+ BUILDOCC_API_URL=http://localhost:8000 buildocc-mcp
434
+ # or: python3 -m occupant_agent.mcp_server.server
435
+ ```
436
+
437
+ MCP tools: `initialize_agent`, `step`, `send_signal`, `get_state`, `reset_agent`.
438
+
439
+ **Configure in Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
440
+
441
+ ```json
442
+ {
443
+ "mcpServers": {
444
+ "buildocc": {
445
+ "command": "buildocc-mcp",
446
+ "env": {
447
+ "BUILDOCC_API_URL": "http://localhost:8000"
448
+ }
449
+ }
450
+ }
451
+ }
452
+ ```
453
+
454
+ Start the REST API first (`buildocc-api`), then restart Claude Desktop. The `initialize_agent`, `step`, and `send_signal` tools will appear in Claude's tool list.
455
+
456
+ ## Testing
457
+
458
+ ```bash
459
+ # Unit tests (no API key needed — uses MockLLMAgent)
460
+ pytest tests/unit/
461
+
462
+ # Integration tests (no API key needed — uses MockLLMAgent end-to-end)
463
+ pytest tests/integration/
464
+
465
+ # Offline smoke-test of the simulation loop (--mock bypasses the LLM entirely)
466
+ python3 examples/simulation_loop.py --mock --stratum O1 --steps 4
467
+ python3 examples/signal_demo.py --mock --part 1
468
+ ```
469
+
470
+ ## How it works
471
+
472
+ ### ATUS grounding
473
+ Agents are initialized from ATUS 2022+2023 microdata (16,684 respondents; 299,513 activity episodes) matched by demographic stratum. Activity scheduling uses *time-at-activity* distributions — the population-weighted fraction of respondents in each activity at each clock hour, computed via episode-overlap rather than start-time sampling. This avoids the start-time bias that over-represents long-duration activities (e.g., sleeping). Eight categories are modeled: sleeping, work, food prep, laundry, TV, eating, exercise, and other. Weekday and weekend distributions are computed separately (`TUDIARYDAY`) and the scheduler selects the appropriate distribution from `timestep.weekday()`.
474
+
475
+ ### LLM reasoning at each timestep
476
+ `step()` synthesizes six inputs: the agent's persona (core memory), top-5 retrieved memories by recency + importance score, current environment state (temperatures, TOU rate, device states), current ATUS activity, time of day, and a per-day WFH flag (sampled from `persona.sample_wfh_today()` and resampled on date rollover). The LLM returns a structured action and a self-rated importance score (1–10) for the observation. Valid `target_id` values (device IDs and room IDs) are injected into the prompt schema so the LLM cannot hallucinate invalid targets.
477
+
478
+ ### Persona diversity
479
+ Each `create_persona()` call samples a demographically grounded agent: income bracket drives `comfort_band_c` (°C deviation from setpoint before acting — wider for lower income, per RECS 2020), appliance ownership (scaled ±30% around RECS base priors by income position within stratum), and signal preference framing in the LLM prompt (dollar-savings vs. social-comparison language). Four LLM providers are supported for cost/privacy trade-offs: Anthropic, OpenAI, Google Gemini, and local Ollama.
480
+
481
+ ### Memory stream and reflection
482
+ Follows Park et al. (2023). Retrieval score = `0.5 × recency + 0.5 × (importance/10)` with exponential recency decay (24-hour half-life). When the cumulative importance accumulator exceeds a threshold (default 100), reflection fires: the LLM synthesizes the last 30 memories into 3 high-level insights, stored as permanent memory entries. A more capable model is used for reflection; a cheaper model handles routine `step()` calls.
483
+
484
+ ### Persistence
485
+ All agent state (persona, memory stream, action log, signal log) is persisted to SQLite via SQLAlchemy. Each API request loads fresh from the database and writes back — stateless HTTP with durable state. Multiple agents can run concurrently via `agent_id` (UUID4).
486
+
487
+ ## How to extend
488
+
489
+ BuildOcc is designed as a community platform. You can add new demographic profiles, activity schedulers, and memory architectures without forking the repository.
490
+
491
+ ### Define a new demographic profile (stratum)
492
+
493
+ Subclass `BasePersona` and register it under a key. Your class will be discoverable via `OccupantAgent.from_stratum()` and `list_strata()`.
494
+
495
+ ```python
496
+ import random
497
+ from occupant_agent import OccupantAgent
498
+ from occupant_agent.core import BasePersona, register_stratum, list_strata
499
+
500
+ @register_stratum("P5")
501
+ class LowIncomeElderlyAlone(BasePersona):
502
+ """Single elderly adult, low income — for low-income housing DR research."""
503
+
504
+ def __init__(self, seed=None, **kwargs):
505
+ self._age = random.Random(seed).randint(65, 80)
506
+
507
+ @property
508
+ def stratum(self): return "P5"
509
+ @property
510
+ def age(self): return self._age
511
+ @property
512
+ def sex(self): return "female"
513
+ @property
514
+ def income_bracket(self): return 3 # low income (HEFAMINC 1–16)
515
+ @property
516
+ def work_from_home(self): return False
517
+ @property
518
+ def home_gym(self): return False
519
+ @property
520
+ def wfh_probability(self): return 0.0
521
+ @property
522
+ def comfort_band_c(self): return 2.2 # cost-sensitive → wide tolerance
523
+ @property
524
+ def appliances(self): return {"hvac", "thermostat", "tv", "refrigerator"}
525
+ @property
526
+ def schedule_priors(self): return {}
527
+ @property
528
+ def core_memory_text(self):
529
+ return (f"I am a {self._age}-year-old woman living alone on a fixed income. "
530
+ "I keep my thermostat low to save money.")
531
+ def sample_wfh_today(self, rng): return False
532
+
533
+ # Now usable everywhere:
534
+ agent = OccupantAgent.from_stratum("P5", seed=42)
535
+ print(list_strata()) # ["O1", "O2", "O3", "O4", "P5"]
536
+ ```
537
+
538
+ ### Define a new activity scheduler
539
+
540
+ Subclass `BaseScheduler` to ground the agent in a different data source (Homer, MTUS, synthetic, etc.).
541
+
542
+ ```python
543
+ from datetime import datetime
544
+ from occupant_agent.core import BaseScheduler, register_scheduler
545
+
546
+ @register_scheduler("homer")
547
+ class HomerScheduler(BaseScheduler):
548
+ """Activity grounding from Homer dataset (21-participant HAR corpus)."""
549
+
550
+ def __init__(self, stratum=None, seed=None, **kwargs):
551
+ ... # load Homer diary records
552
+
553
+ def sample(self, timestep: datetime) -> str:
554
+ ... # return 6-digit ATUS code
555
+
556
+ def category_weights(self, hour: int, timestep=None) -> dict[str, float]:
557
+ ... # return {category: probability}
558
+
559
+ # Inject at agent creation:
560
+ agent = OccupantAgent.from_stratum("O1", seed=42, scheduler="homer")
561
+ ```
562
+
563
+ ### Define a new memory architecture
564
+
565
+ Subclass `BaseMemoryStream` to replace the retrieval algorithm (e.g., sentence-embedding similarity, graph-structured memory).
566
+
567
+ ```python
568
+ from datetime import datetime
569
+ from collections.abc import Callable
570
+ from occupant_agent.core import BaseMemoryStream
571
+
572
+ class EmbeddingMemory(BaseMemoryStream):
573
+ """Retrieval weighted by semantic similarity (sentence-transformers)."""
574
+
575
+ def retrieve(self, query_time: datetime, k: int = 5):
576
+ ... # rank by cosine similarity to current context
577
+
578
+ # Inject at agent construction:
579
+ mem = EmbeddingMemory()
580
+ agent = OccupantAgent(persona=persona, memory=mem)
581
+ ```
582
+
583
+ ### Platform-specific extensions via EnvironmentState
584
+
585
+ Use `extensions: dict` to pass platform-specific data alongside the core schema without modifying it:
586
+
587
+ ```python
588
+ env = EnvironmentState(
589
+ timestep=ts, zone_temp_c=23.0, outdoor_temp_c=29.0, tou_rate=0.18,
590
+ devices=[...], rooms=[...],
591
+ extensions={
592
+ "home_assistant": {
593
+ "sensor.living_room_co2": 650,
594
+ "binary_sensor.front_door": "off",
595
+ },
596
+ "energyplus": {"zone_air_humidity_ratio": 0.009},
597
+ }
598
+ )
599
+ ```
600
+
601
+ The core agent ignores `extensions`; platform-specific plugins can read it.
602
+
603
+ ### Package your extension for distribution
604
+
605
+ ```python
606
+ # your_package/__init__.py
607
+ from occupant_agent.core import register_stratum
608
+ from .personas import LowIncomeElderlyAlone, PublicHousingResident
609
+
610
+ register_stratum("P5")(LowIncomeElderlyAlone)
611
+ register_stratum("P6")(PublicHousingResident)
612
+ ```
613
+
614
+ After `pip install your-package`, any script that imports it gains the new strata.
615
+
616
+ ### Built-in extension point summary
617
+
618
+ | Base class | Register with | Discovered by |
619
+ |---|---|---|
620
+ | `BasePersona` | `@register_stratum("P5")` | `OccupantAgent.from_stratum("P5")`, `list_strata()` |
621
+ | `BaseScheduler` | `@register_scheduler("homer")` | `OccupantAgent.from_stratum(..., scheduler="homer")`, `list_schedulers()` |
622
+ | `BaseMemoryStream` | Inject directly into `OccupantAgent(memory=...)` | — |
623
+
624
+ ---
625
+
626
+ ## Regenerating ATUS outputs
627
+
628
+ Pre-generated ATUS outputs are bundled in `occupant_agent/data/`. Raw ATUS microdata is not committed to the repository — download it and place in `data/atus/{year}/extracted/` before running these scripts. To regenerate outputs after a data update:
629
+
630
+ ```bash
631
+ python3 scripts/atus/analyze.py
632
+ # Produces scripts/atus/outputs/time_at_activity.csv (hour, category, weighted_pct, stratum, day_type)
633
+ # scripts/atus/outputs/activity_frequency_{O1,O2,O3,O4}.csv
634
+ # scripts/atus/outputs/schedule_peak_hours.csv (weekday/weekend peak hours per stratum)
635
+ # Then sync:
636
+ cp scripts/atus/outputs/time_at_activity.csv occupant_agent/data/
637
+ cp scripts/atus/outputs/schedule_peak_hours.csv occupant_agent/data/
638
+ ```
639
+
640
+ Download ATUS microdata from [BLS ATUS](https://www.bls.gov/tus/data.htm) (`.dat` files, uppercase column headers) or [IPUMS Time Use](https://www.ipums.org/timeuse) (`.csv` files, lowercase column headers — both formats are supported automatically).
641
+
642
+ ## Data
643
+
644
+ Raw datasets go in `data/`. See [docs/datasets_and_resources.md](docs/datasets_and_resources.md) for access and coverage details.
645
+
646
+ | Directory | Dataset | Purpose |
647
+ |-----------|---------|---------|
648
+ | `data/atus/` | ATUS 2022–23 (BLS) | Agent grounding and scheduling |
649
+ | `data/casas/` | CASAS Aruba/Milan (Zenodo) | Behavioral validation (Phase 2) |
650
+ | `data/ecobee/` | DOE ecobee 2017 (OSTI) | Thermostat validation (Phase 2) |
651
+ | `data/pecan_street/` | Pecan Street Dataport | Energy validation (Phase 2) |
652
+ | `data/recs/` | EIA RECS | Appliance ownership priors |
653
+
654
+ ## Project structure
655
+
656
+ ```
657
+ occupant_agent/
658
+ core/
659
+ base_persona.py — BasePersona ABC (extension contract for new strata)
660
+ base_memory.py — BaseMemoryStream ABC (extension contract for memory backends)
661
+ base_scheduler.py — BaseScheduler ABC (extension contract for activity sources)
662
+ registry.py — Plugin registry: @register_stratum, @register_scheduler
663
+ agent/
664
+ occupant.py — OccupantAgent: step(), receive_signal(), from_stratum()
665
+ memory.py — MemoryStream(BaseMemoryStream): retrieval, reflection
666
+ persona.py — Persona dataclass, create_persona(), ROOM_DEFAULTS
667
+ grounding/
668
+ scheduler.py — ActivityScheduler(BaseScheduler): ATUS-grounded sampling
669
+ fixed_schedule.py — FixedScheduleScheduler: rule-based ablation baseline
670
+ activity_code_map.py — ATUS tier-3 code → occupancy + device state mapping
671
+ llm/
672
+ client.py — call_llm(): Anthropic / OpenAI / Google Gemini / Ollama
673
+ environment/
674
+ state.py — Pydantic models: EnvironmentState (+ extensions), AgentAction
675
+ simulation.py — SimulationEnvironment: device/room/setpoint state
676
+ persistence/
677
+ store.py — AgentStore: SQLite via SQLAlchemy
678
+ analysis/
679
+ simulation_log.py — SimulationLog: per-step records, CSV/JSON export
680
+ metrics.py — compute_kl, compute_ks, compute_cvrmse, compute_mbe
681
+ testing/
682
+ mock_llm.py — MockLLMAgent: deterministic test double (no API key needed)
683
+ fixtures.py — make_env(), make_room() — factory helpers for unit tests
684
+ conformance.py — assert_persona_contract(), assert_scheduler_contract()
685
+ cli.py — Entry point for buildocc CLI command
686
+ data/ — Bundled ATUS outputs (time_at_activity.csv, ...)
687
+ api/
688
+ app.py — FastAPI REST API (Layer 2)
689
+ mcp_server/
690
+ server.py — MCP server (Layer 3, wraps REST API)
691
+ scripts/
692
+ evaluate.py — Config-driven evaluation harness (KL, KS, action distribution)
693
+ validate_strata.py — Validate each demographic stratum across a batch of seeds
694
+ validate_signals.py — Validate Type A/B/C signal response rates per stratum
695
+ extract_zone_temps.py — Extract zone temperatures from EnergyPlus output CSV
696
+ atus/
697
+ parse.py — ATUS microdata → per-respondent episode records
698
+ analyze.py — Episode records → time_at_activity.csv + frequency CSVs
699
+ data/atus/ — Raw ATUS 2022+2023 microdata (not committed to Git)
700
+ examples/
701
+ simulation_loop.py — ATUS-grounded evening simulation with Type B signal
702
+ signal_demo.py — Demand response signal reference: all three types + stratum comparison
703
+ energyplus_callback.py — EnergyPlus Python API integration pattern
704
+ docs/
705
+ datasets_and_resources.md — Dataset access, coverage, and caveats
706
+ methodology_decisions.md — Design decision log (D1–D13)
707
+ ```
708
+
709
+ ## Development plan
710
+
711
+ v1 is complete. Phase 2 (validation against CASAS and Pecan Street behavioral data) is next.
712
+
713
+ ## Citation
714
+
715
+ ```bibtex
716
+ @article{jung2026occupantagent,
717
+ title = {BuildOcc: A Large Language Model Occupant Agent Platform for Building Energy Research},
718
+ author = {Jung, Wooyoung},
719
+ journal = {SoftwareX},
720
+ year = {2026},
721
+ note = {Under review}
722
+ }
723
+ ```
724
+
725
+ ## License
726
+
727
+ [Apache License 2.0](LICENSE)