86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
"""
|
|
@core PersonaGenerator (swarm/core/persona_generator.py)
|
|
@purpose Spawns heterogeneous individual agent personas grounded in behavioral archetypes.
|
|
"""
|
|
import random
|
|
from typing import List, Dict, Any
|
|
from pydantic import BaseModel, Field
|
|
from swarm.core.archetypes import STANDARD_ARCHETYPES, Archetype
|
|
|
|
|
|
class AgentPersona(BaseModel):
|
|
agent_id: str
|
|
archetype_id: str
|
|
archetype_name: str
|
|
name: str
|
|
device_model: str
|
|
budget_inr: float
|
|
price_sensitivity: float
|
|
urgency: float
|
|
quality_priority: float
|
|
trust_threshold: float
|
|
whatsapp_irritation_threshold: float
|
|
b2b_focus: bool
|
|
context_notes: str
|
|
|
|
|
|
DEVICE_POOL = [
|
|
"iPhone 13 Screen", "iPhone 15 Display", "Samsung Galaxy S22 Battery",
|
|
"MacBook Air M1 Battery", "OnePlus 11 Charging Port", "iPad 9th Gen Glass",
|
|
"Corporate Fleet (50x Dell Latitude)", "Xiaomi Note 12 Display"
|
|
]
|
|
|
|
SAMPLE_NAMES = [
|
|
"Rahul S.", "Priya M.", "Amit K.", "Kavita R.", "Vikram D.",
|
|
"Deepak P.", "Ananya B.", "Rohan N.", "Meera T.", "Suresh V."
|
|
]
|
|
|
|
|
|
def generate_personas(count: int = 50, seed: int = 42) -> List[AgentPersona]:
|
|
"""
|
|
Generates a deterministic cohort of heterogeneous agent personas
|
|
distributed according to archetype population weights.
|
|
"""
|
|
rng = random.Random(seed)
|
|
personas: List[AgentPersona] = []
|
|
|
|
agent_counter = 1
|
|
for arch in STANDARD_ARCHETYPES:
|
|
arch_count = max(1, int(round(count * arch.population_weight)))
|
|
for _ in range(arch_count):
|
|
# Inject small bounded variance (+- 0.08) around archetype mean
|
|
ps = min(1.0, max(0.0, arch.price_sensitivity + rng.uniform(-0.08, 0.08)))
|
|
urg = min(1.0, max(0.0, arch.urgency + rng.uniform(-0.08, 0.08)))
|
|
qp = min(1.0, max(0.0, arch.quality_priority + rng.uniform(-0.08, 0.08)))
|
|
tt = min(1.0, max(0.0, arch.trust_threshold + rng.uniform(-0.08, 0.08)))
|
|
wit = min(1.0, max(0.0, arch.whatsapp_irritation_threshold + rng.uniform(-0.08, 0.08)))
|
|
|
|
# Budget ranges based on persona
|
|
if arch.b2b_focus:
|
|
budget = rng.choice([25000.0, 50000.0, 150000.0, 300000.0])
|
|
else:
|
|
budget = rng.choice([1500.0, 2800.0, 4500.0, 8500.0, 12000.0])
|
|
|
|
persona = AgentPersona(
|
|
agent_id=f"AGT-{agent_counter:03d}",
|
|
archetype_id=arch.id,
|
|
archetype_name=arch.name,
|
|
name=f"{rng.choice(SAMPLE_NAMES)} ({arch.name.split()[0]})",
|
|
device_model=rng.choice(DEVICE_POOL),
|
|
budget_inr=budget,
|
|
price_sensitivity=round(ps, 3),
|
|
urgency=round(urg, 3),
|
|
quality_priority=round(qp, 3),
|
|
trust_threshold=round(tt, 3),
|
|
whatsapp_irritation_threshold=round(wit, 3),
|
|
b2b_focus=arch.b2b_focus,
|
|
context_notes=arch.description
|
|
)
|
|
personas.append(persona)
|
|
agent_counter += 1
|
|
if len(personas) >= count:
|
|
break
|
|
if len(personas) >= count:
|
|
break
|
|
|
|
return personas
|