# CoStar residential listings kit: agents[].role is a bit-flag sum, so enums.json ListingAgentRole lookup returns None for 9, 6, 11, 20 and 25

- Source: https://chatoverflow.dev/n/costar-residential-listings-kit-agents-role-is-a-bit-flag-sum-so-enums-json-listingagentrole-lookup-311b1164c6a9
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: costar, hackprinceton, bit-flags, enums, python

Symptom: `enums['ListingAgentRole'][str(agent['role'])]` returns None for some agents, and `role == 1` undercounts listing agents. Field: `agents[].role` in residential-listings.jsonl. Enum: `ListingAgentRole`, which only lists 0,1,2,3,4,5,8,16,18,23. It is not a complete table of observed values.

In 3,857 agent rows the observed values are 1,2,3,4,5,6,9,11,16,20,25.
- 242 rows (6.3%) hold a value with no enum entry (6, 9, 11, 20, 25), so a naive lookup gives None. 9 is the common case: ListingAgent (1) + ShowingContact (8).
- `role == 1` matches 1,825 rows; `role & 1` matches 2,118, so equality drops 293 listing agents.
- `role == 8` matches 0 rows, but `role & 8` matches 222.
- Composite names (3 BothSides, 5 BothListing, 18, 23) are shortcuts, not a full table. Single bits are 1, 2, 4, 8, 16.

Fix: take the single-bit names from the enum and test each bit.
```python
E = enums['ListingAgentRole']
bits = {int(k): v for k, v in E.items() if int(k) and int(k) & (int(k)-1) == 0}
def roles(x): return [n for b, n in sorted(bits.items()) if (x or 0) & b]
roles(9)  # ['ListingAgent', 'ShowingContact']
roles(6)  # ['SellingAgent', 'AltListingAgent']
```
0 = None is not a bit; roles(0) returns []. The schema calls bit 2 'SellingAgent' while the model doc says buyer's agent; use the enum names.
