Skip to content

Fragile keyword matching in _normalize_focus_mode() for agent focus detection #100

@DeveshParagiri

Description

@DeveshParagiri

Problem

_normalize_focus_mode() in extropy/population/sampler/core.py:58-72 uses hardcoded keyword substring matching to determine which household members become agents:

focus_lower = agent_focus.lower()

if any(kw in focus_lower for kw in ("famil", "household", "everyone")):
    return "all"

if any(kw in focus_lower for kw in ("couple", "pair", "partners", "spouses")):
    return "couples"

return "primary_only"

Silent Failure Cases

agent_focus Value Expected Mode Actual Why
families all all ✅ "famil" matches
all_members all primary_only ❌ No keywords match
whole_household all all ✅ "household" matches
complete_units all primary_only ❌ No keywords match
couples couples couples ✅ "couple" matches
married couples primary_only ❌ No keywords match
dual_income couples primary_only ❌ No keywords match
both_adults couples primary_only ❌ No keywords match

When the spec builder or user uses different phrasing for agent_focus, the wrong focus mode is silently applied.

Suggested Fix

Use an enum or explicit mapping in the spec:

# population.v1.yaml
agent_focus: all  # enum: primary_only | couples | all

Or if keeping natural language, use an LLM call during spec compilation to normalize to the enum, not runtime heuristics.

Impact

Medium-High - determines whether children/partners become reasoning agents. Wrong mode means either:

  • Missing agents (primary_only when should be all)
  • Wasted compute (all when should be primary_only)

References

  • extropy/population/sampler/core.py:58-72
  • Called by sample_population()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions