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

Function parse_profile_update_request

agents/master-coordinator/main.py:1385–1481  ·  view source on GitHub ↗

Safe profile-update parser that prioritizes exact commands and reliable patterns.

(text: str, profile: Optional[Dict[str, Any]] = None)

Source from the content-addressed store, hash-verified

1383
1384
1385def parse_profile_update_request(text: str, profile: Optional[Dict[str, Any]] = None) -> Optional[Dict[str, Any]]:
1386 """Safe profile-update parser that prioritizes exact commands and reliable patterns."""
1387 cleaned = first_meaningful_line(text)
1388 if not cleaned:
1389 return None
1390
1391 if looks_like_bot_authored_message(cleaned):
1392 return None
1393
1394 if detect_explicit_command_intent(cleaned):
1395 return None
1396
1397 if looks_like_must_read_command(cleaned):
1398 return None
1399
1400 if looks_like_cold_start_description(cleaned, profile=profile):
1401 return None
1402
1403 for pattern in (PROFILE_WEIGHT_TARGET_RE, PROFILE_WEIGHT_TARGET_PREFIX_RE):
1404 weight_target_match = pattern.search(cleaned)
1405 if not weight_target_match:
1406 continue
1407 verb = weight_target_match.group("verb")
1408 target_weight = parse_weight_target(weight_target_match.group("weight"))
1409 if target_weight is None:
1410 continue
1411 return build_profile_update_result(
1412 "adjust_weight",
1413 "decrease" if verb in {"降低", "减少", "调低", "下调", "弱化", "降到"} else "increase",
1414 weight_target_match.group("topic"),
1415 weight_target=target_weight,
1416 )
1417
1418 weight_match = PROFILE_WEIGHT_COMMAND_RE.search(cleaned)
1419 if weight_match:
1420 verb = weight_match.group("verb")
1421 return build_profile_update_result(
1422 "adjust_weight",
1423 "decrease" if verb in {"降低", "减少", "调低", "下调", "弱化"} else "increase",
1424 weight_match.group("topic"),
1425 )
1426
1427 negative_interest_match = PROFILE_NEGATIVE_INTEREST_RE.search(cleaned)
1428 if negative_interest_match:
1429 return build_profile_update_result(
1430 "adjust_interest",
1431 "decrease",
1432 negative_interest_match.group("topic"),
1433 )
1434
1435 soft_negative_interest_match = PROFILE_SOFT_NEGATIVE_INTEREST_RE.search(cleaned)
1436 if soft_negative_interest_match:
1437 return build_profile_update_result(
1438 "adjust_interest",
1439 "decrease",
1440 soft_negative_interest_match.group("topic"),
1441 )
1442

Callers 2

detect_intentMethod · 0.85
handle_profile_updateMethod · 0.85

Tested by

no test coverage detected