feat(07-01): DB migration 009, ORM updates, and LANGUAGE_INSTRUCTION in system prompts

- Migration 009: adds language col (VARCHAR 10, NOT NULL, default 'en') to portal_users
- Migration 009: adds translations col (JSONB, NOT NULL, default '{}') to agent_templates
- Migration 009: backfills es+pt translations for all 7 seed templates
- PortalUser ORM: language mapped column added
- AgentTemplate ORM: translations mapped column added
- system_prompt_builder.py: LANGUAGE_INSTRUCTION constant + appended before AI_TRANSPARENCY_CLAUSE
- system-prompt-builder.ts: LANGUAGE_INSTRUCTION constant + appended before AI transparency clause
- tests: TestLanguageInstruction class with 3 tests (all pass, 20 total)
This commit is contained in:
2026-03-25 16:22:53 -06:00
parent 5cd9305d27
commit 7a3a4f0fdd
6 changed files with 394 additions and 1 deletions

Submodule packages/portal updated: c4ff491b9d...04c03749a6

View File

@@ -61,6 +61,12 @@ class PortalUser(Base):
default="customer_admin",
comment="platform_admin | customer_admin | customer_operator",
)
language: Mapped[str] = mapped_column(
String(10),
nullable=False,
server_default="en",
comment="UI and email language preference: en | es | pt",
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,

View File

@@ -253,6 +253,12 @@ class AgentTemplate(Base):
default=True,
comment="Inactive templates are hidden from the gallery",
)
translations: Mapped[dict[str, Any]] = mapped_column(
JSON,
nullable=False,
default=dict,
comment="JSONB map of locale -> {name, description, persona} translations. E.g. {'es': {...}, 'pt': {...}}",
)
sort_order: Mapped[int] = mapped_column(
Integer,
nullable=False,

View File

@@ -14,6 +14,14 @@ AI_TRANSPARENCY_CLAUSE = (
"When directly asked if you are an AI, always disclose that you are an AI assistant."
)
# Language detection instruction (Phase 7 multilanguage feature).
# Instructs agents to respond in the language the user writes in.
# Supports English, Spanish, and Portuguese.
LANGUAGE_INSTRUCTION = (
"Detect the language of each user message and respond in that same language. "
"You support English, Spanish, and Portuguese."
)
def build_system_prompt(
name: str,
@@ -62,6 +70,9 @@ def build_system_prompt(
)
sections.append(f"Escalation rules:\n{rule_lines}")
# --- Language instruction (always present — Phase 7 multilanguage) ---
sections.append(LANGUAGE_INSTRUCTION)
# --- AI transparency clause (always present, non-negotiable) ---
sections.append(AI_TRANSPARENCY_CLAUSE)