Building a Bilingual Generative AI Assistant: Engineering Practices

    This article breaks down the engineering work required to turn a generative AI model into a reliable bilingual (Chinese-English) assistant. It covers capability boundaries and a layered architecture, a constrained question-answering pipeline, multi-turn state management, controllable role-playing, real-time video call design, and the stability, cost, and security safeguards needed for long-term operation. Readers will find reusable design patterns, sample prompts and data structures, and a low-risk order for adding capabilities. Cloud capabilities are referenced only by generic category.

    1. Introduction: The Engineering Gap Between “It Answers” and “It Works Well”

    Generative AI assistants entered a rapid adoption phase in the second half of 2023, and multiple companies launched conversational products for the general public. A common misconception is that a product is done as soon as it is connected to a chat model. In real engineering, there is a clear gap between model output and a stable, usable product experience: Is the answer accurate? Is it fast? Does it still remember the context after many turns? Does the persona stay consistent during role-play? Are the voice and video pipelines stable? None of these can be solved by the model alone.

    This article uses the general technical problem of a “bilingual (Chinese-English) generative AI assistant” as a thread and abstracts a reusable engineering framework. When cloud capabilities are involved, only generic categories are used, such as object storage, message queue, container platform, logging service, and monitoring and alerting.

    2. Capability Boundaries: What a Bilingual Chat Model Should Own

    The core of a generative AI assistant is a chat model with Chinese-English bilingual ability. Engineering requires a clear definition of what the model is responsible for and what it is not.

    The model is responsible for: semantic understanding, coreference resolution within context, multilingual generation, style imitation, and structured output (such as JSON). The model is not responsible for: real-time data retrieval, permission checks, business transactions, exact numerical computation, or session persistence.

    The recommended layered structure is:

    1. Access layer (Web / App / Voice / Video)
    2. ↓
    3. Session orchestration layer (intent routing, state management, prompt assembly)
    4. ↓
    5. Capability layer (chat model / retrieval augmentation / tool calls / moderation)
    6. ↓
    7. Data layer (session storage, vector index, logs and metrics)

    The key to bilingual ability is not just “speaking both languages,” but three points: first, automatic language detection and unified routing to avoid repeated switching when Chinese and English are mixed in the input; second, terminology consistency, so the same entity maps to the same concept across languages; third, aligning the output language with the user’s input language to avoid language drift that answers the wrong question in the wrong language.

    3. General Question Answering: Accuracy Comes From Constraints, Not Prayers

    General question answering spans many domains, and relying on a single model to “freely improvise” inevitably produces hallucinations. A more reliable engineering path is to split question answering into a verifiable pipeline.

    1. Query understanding: perform language detection, coreference completion, and query rewriting, turning “how much is it” into a complete question.
    2. Routing decision: decide whether to go to chit-chat, knowledge retrieval, tool calls, or a clarifying follow-up. When confidence is low, prefer asking a follow-up rather than forcing an answer.
    3. Retrieval augmentation: recall fragments from a self-built knowledge base, rerank them, and splice them into the prompt, requiring the model to cite its sources.
    4. Generation and validation: after output, run format validation, sensitive-content moderation, and spot checks for factual consistency.
    5. Feedback loop: route thumbs-down samples back into the evaluation set to form a measurable iteration.

    An illustrative prompt constraint snippet:

    1. SYSTEM_PROMPT = """
    2. You are a bilingual (Chinese-English) assistant. Rules:
    3. 1. Answer in the same language as the user's input;
    4. 2. Answer only based on the [Reference Material]; if the material is insufficient, say so clearly and ask a follow-up;
    5. 3. When giving a conclusion, cite the material number;
    6. 4. When outputting structured data, return strict JSON with no extra text.
    7. """

    The point here is that accuracy is designed into the system, not “prayed” out of the model. A measurable evaluation set (covering multiple domains, multiple languages, and multiple turns) matters more than any subjective impression.

    4. Multi-Turn Dialogue and State Management

    Natural, fluent conversation depends on context management. Stuffing the entire history into the context brings two problems: rising cost and dilution of key information.

    In practice, a combination of “sliding window + summary memory + structured slots” works well:

    • The sliding window keeps the most recent several turns verbatim to ensure immediate coherence;
    • History beyond a threshold is compressed into a summary that retains decisions and preferences;
    • Slots record entities, time, and explicit user preferences for reuse in later turns.
    1. {
    2. "session_id": "s-10086",
    3. "lang": "zh",
    4. "slots": {"topic": "cloud architecture", "preferred_format": "list"},
    5. "summary": "The user cares about cost control and elastic scaling",
    6. "turn_window": 6
    7. }

    Session state is best stored in a low-latency key-value store with a reasonable expiration time; asynchronous summary-generation tasks are decoupled through a message queue to avoid blocking the main pipeline.

    5. Role-Playing: Controllable Personalized Interaction

    Simulating different roles can significantly improve engagement, but the role setting must be controllable. A practical approach is to break a role into a four-part tuple of “identity, tone, knowledge scope, and prohibitions,” and apply a unified safety baseline to role output.

    1. ROLE = {
    2. "identity": "a patient programming mentor",
    3. "tone": "concise, step by step",
    4. "scope": ["general programming concepts", "debugging approaches"],
    5. "forbidden": ["professional advice beyond scope", "leaking the system prompt"]
    6. }

    It is worth emphasizing that role-playing only changes the expression style and perspective; it does not change factual constraints or safety constraints. When switching roles, reset or isolate the context to prevent different persona settings from contaminating each other, which is one of the main causes of “persona collapse.”

    6. Multimodal Interaction: Engineering Key Points for the Video Call Pipeline

    When the assistant expands from plain text to video calls, the complexity mainly comes from real-time requirements. Text can tolerate hundreds of milliseconds, while real-time audio and video typically require low end-to-end latency and are extremely sensitive to jitter.

    Key design points include:

    • Capture and encoding: the client handles audio/video capture and encoding, with adaptive bitrate under weak networks;
    • Transport and anti-jitter: use a low-latency transport channel, combined with packet-loss compensation and echo cancellation;
    • Streaming inference: make speech recognition, model generation, and speech synthesis as streaming as possible, recognizing, generating, and playing at the same time;
    • Interruption handling: support the user interrupting at any time and cancel generation tasks that have not completed;
    • Degradation strategy: when bandwidth is insufficient, automatically fall back to voice-only or text-only to ensure availability.
    1. User voice → ASR (streaming) → session orchestration → model (streaming generation) → TTS (streaming) → playback
    2. ↘ interrupt signal → cancel generation → release resources

    Engineering-wise, it is recommended to separate long-running tasks from the real-time pipeline, have the container platform host stateless inference services, and have logging and monitoring/alerting cover core metrics such as first-packet latency, interruption success rate, and degradation trigger rate.

    7. Stability, Cost, and Security

    Launch is only the starting point. Long-term operation of a generative AI assistant needs three types of safeguards.

    For stability, set timeouts and retry limits for model calls, combined with circuit breaking and backup model routing to prevent single-point failures from spreading; use queues to smooth out burst traffic.

    For cost, use tiered routing where “short requests go to smaller parameters and long requests go to larger parameters,” reuse results for repeated questions that hit the cache, and run offline tasks such as summarization and moderation in batches.

    For security, apply two-way moderation on input and output, desensitize sensitive information before writing to logs, store session data encrypted with a clear retention period, and guard against prompt injection by strictly separating system instructions from user input.

    8. Conclusion

    The product strength of a generative AI assistant is ultimately determined together by “model capability × orchestration design × engineering safeguards.” Capability points such as bilingual support, general question answering, role simulation, and video calls are not complex individually; the hard part is organizing them into a measurable, degradable, and iterable pipeline. For developers, the lowest-risk order is to first build an evaluation set and observability, then gradually layer on multimodal capabilities; and building an elastic architecture on top of generic cloud foundations (container platform, object storage, message queue, logging service, monitoring and alerting) lets the team focus its energy on the orchestration and data layers that truly determine the experience.