MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / ensure_profile_shape

Function ensure_profile_shape

agents/coldstart-agent/main.py:151–186  ·  view source on GitHub ↗

Normalize a stored profile into the current schema.

(profile: Optional[Dict[str, Any]], user_id: str)

Source from the content-addressed store, hash-verified

149 "drift_state": build_default_drift_state(now),
150 }
151
152
153def ensure_profile_shape(profile: Optional[Dict[str, Any]], user_id: str) -> Dict[str, Any]:
154 """Normalize a stored profile into the current schema."""
155 normalized = copy.deepcopy(profile) if profile else build_empty_profile(user_id)
156 normalized["user_id"] = user_id
157 normalized.setdefault("version", "0.1")
158 normalized.setdefault("created_at", normalized.get("updated_at", datetime.now().isoformat()))
159 normalized["updated_at"] = datetime.now().isoformat()
160
161 for key in ("core_directions", "methodology_preferences", "topic_weights", "author_heat", "institution_heat", "taste_profile"):
162 value = normalized.get(key)
163 normalized[key] = value if isinstance(value, dict) else {}
164
165 must_read = normalized.get("must_read")
166 normalized["must_read"] = must_read if isinstance(must_read, dict) else {}
167 for key in ("authors", "institutions", "keywords"):
168 value = normalized["must_read"].get(key)
169 normalized["must_read"][key] = value if isinstance(value, list) else []
170
171 for key in ("interest_vector", "reading_history", "behavior_logs"):
172 value = normalized.get(key)
173 normalized[key] = value if isinstance(value, list) else []
174
175 drift_state = normalized.get("drift_state")
176 normalized["drift_state"] = drift_state if isinstance(drift_state, dict) else {}
177 for key, default_value in build_default_drift_state(normalized["updated_at"]).items():
178 normalized["drift_state"].setdefault(key, copy.deepcopy(default_value))
179
180 raw_core_directions = dict(normalized.get("core_directions") or {})
181 raw_topic_weights = dict(normalized.get("topic_weights") or {})
182 normalized["core_directions"] = _normalize_direction_weight_map(raw_core_directions)
183 normalized["topic_weights"] = _normalize_direction_weight_map(raw_topic_weights)
184
185 if normalized["core_directions"] and normalized["core_directions"] != raw_core_directions:
186 normalized["interest_vector"] = generate_interest_vector(normalized["core_directions"])
187
188 return normalized
189

Callers 3

cold_startFunction · 0.85

Calls 6

generate_interest_vectorFunction · 0.85
getMethod · 0.80
nowMethod · 0.80
build_empty_profileFunction · 0.70

Tested by

no test coverage detected