Fix audience_brief and research_objective dropped in Stage 2 persona generation

Stage 2 (detailed persona generation) was ignoring the audience brief and
research objective, causing the LLM to guess research context from demographics
alone. Now passes both values through to generate_persona() in all three
endpoints (generate-personas-full, complete-and-save-persona, complete-persona)
and auto-generates prompt customization via customize_persona_prompt() when
they are provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
michael 2026-02-11 08:40:17 -06:00
parent 850cb25067
commit d4ce5d99bc
2 changed files with 31 additions and 11 deletions

View file

@ -135,16 +135,21 @@ async def complete_persona():
basic_profile = data.get('basic_profile')
if not basic_profile:
return jsonify({"error": "Missing basic profile", "message": "Basic profile is required"}), 400
temperature = data.get('temperature', 1.0)
if not (0 <= temperature <= 1.5):
temperature = 1.0
audience_brief = data.get('audience_brief')
research_objective = data.get('research_objective')
try:
# Complete the persona
complete_persona_data = await generate_persona(
basic_persona=basic_profile,
temperature=temperature
temperature=temperature,
audience_brief=audience_brief,
research_objective=research_objective
)
return jsonify({
@ -224,9 +229,11 @@ async def complete_and_save_persona():
basic_persona=basic_profile,
temperature=temperature,
customer_data_session_id=customer_data_session_id,
llm_model=llm_model
llm_model=llm_model,
audience_brief=audience_brief,
research_objective=research_objective
)
# Generate AI summary for the persona
try:
summary_data = await generate_persona_summary(
@ -1107,9 +1114,11 @@ async def generate_personas_full():
basic_persona=basic_profile,
temperature=temperature,
customer_data_session_id=customer_data_session_id,
llm_model=llm_model
llm_model=llm_model,
audience_brief=audience_brief,
research_objective=research_objective
)
# Check cancellation before summary generation
if asyncio.current_task().cancelled():
raise asyncio.CancelledError("Task was cancelled")

View file

@ -444,25 +444,36 @@ async def generate_persona(
basic_persona: Optional[Dict[str, Any]] = None,
temperature: float = 1.0,
customer_data_session_id: Optional[str] = None,
llm_model: Optional[str] = None
llm_model: Optional[str] = None,
audience_brief: Optional[str] = None,
research_objective: Optional[str] = None
) -> Dict[str, Any]:
"""
Generate a synthetic persona using the specified LLM model.
Args:
prompt_customization: Optional string to customize the generation
basic_persona: Optional dictionary containing basic persona data to start with
temperature: Controls randomness in generation (0.0 = deterministic, 1.0 = creative)
customer_data_session_id: Optional session ID for customer data context
llm_model: Optional LLM model to use for generation
audience_brief: Optional audience brief for research context
research_objective: Optional research objective for research context
Returns:
A dictionary containing the generated persona data
Raises:
PersonaGenerationError: If there's an issue with the AI generation or JSON parsing
"""
try:
# If audience_brief or research_objective provided but no prompt_customization,
# generate customization so the LLM knows the research context
if not prompt_customization and (audience_brief or research_objective):
prompt_customization = customize_persona_prompt(
audience_brief=audience_brief,
research_objective=research_objective
)
# Load customer data context if session ID provided
customer_data_context = ''
if customer_data_session_id: