Conversational AI Architecture and Multimodal Generation: A Practical Guide

    This article traces a single user scenario—generating an image inside a chat turn—to explain why in-conversation image generation is an architecture problem rather than a feature. It covers intent and slot extraction, capability routing, state consistency, prompt structuring across six dimensions, multi-turn version management, compute cost controls such as semantic caching and tiered resolution, observability and hallucination suppression, and a generic cloud architecture that composes containers, message queues, object storage, CDN, logging, and configuration management. Readers will find vendor-neutral orchestration pseudocode, a structured prompt example, and practical patterns for building sustainable multimodal applications.

    1. Starting from a Single Interaction

    In a conversation with an AI assistant, a user makes a request with a clear visual intent: generate an image evoking the misty rain of Jiangnan, featuring a stone pagoda-style high-rise pavilion by the water, roughly forty to fifty meters tall and about twenty stories. The user originally expects to receive a prompt and then paste it into a separate generation tool. Instead, the assistant completes prompt construction, generation, comparison, and several rounds of refinement within the same turn, then presents the candidates directly, leaving the user to pick one.

    The scenario looks effortless, but behind it sits a typical multimodal engineering pipeline: the dialogue orchestration layer handles intent understanding and state management, the tool invocation layer handles capability routing and parameter assembly, the generation model layer handles image and video synthesis, and the resource layer handles compute scheduling and cost control. This article uses that scenario as a thread and abstracts a vendor-neutral, general practice.

    2. Why In-Conversation Generation Is an Architecture Problem, Not a Feature

    The traditional approach keeps conversation and generation separate, forcing users to copy prompts between multiple entry points and losing context along the way. Embedding generation into the conversation turns a single-turn question into a multi-turn workflow with side effects, which raises four problems:

    1. Intent and slot extraction: pulling structured slots such as subject, scene, style, aspect ratio, camera, and duration out of natural language.
    2. Capability routing: deciding whether the current turn should produce a text reply, an image, a video, or a retrieval-based answer.
    3. State consistency: remembering which version is currently selected across multiple rounds of edits, so the system never modifies the wrong target.
    4. Cost and latency governance: generation calls are expensive per unit and slow, so caching, reuse, and fallback strategies are mandatory.

    Illustrative orchestration pseudocode:

    1. def handle_turn(session, user_input):
    2. intent, slots = parse(user_input) # intent detection + slot extraction
    3. slots = merge(session.slots, slots) # merge with historical slots
    4. if intent == "image_generate":
    5. key = build_cache_key(slots) # build cache key after normalization
    6. if key in session.cache:
    7. return session.cache[key] # reuse on hit, zero compute cost
    8. result = generate_image(slots) # call the generation capability
    9. session.cache[key] = result
    10. session.selected = result.id # record the currently selected version
    11. return result
    12. return reply_text(intent, slots)

    3. Prompt Engineering: Turning Literary Description into Executable Constraints

    Users tend to speak in literary terms (“misty rain,” “by the water,” “stone pagoda pavilion”), while generation models need executable visual constraints. The practical approach is to split the prompt into six dimensions and explicitly fill in whatever is missing:

    • Subject and structure: pagoda-style pavilion, number of stories, total height, footprint;
    • Environment: river or lake surface, moisture, rain streaks, layered distant hills;
    • Style and texture: ink wash, fine-line gongbi, photorealism, film grain;
    • Camera language: viewpoint height, focal length feel, depth of field, composition ratio;
    • Lighting and color: overcast diffuse light, low-saturation blue-gray, local warm accents;
    • Negative constraints: no text or watermarks, no structural distortion, no proportion errors.

    An example of a structured prompt (the JSON only expresses structure and is not a specific API parameter set):

    1. {
    2. "subject": "Lakeside stone pagoda-style high-rise pavilion, about 20 stories, 45 meters tall, compact footprint",
    3. "environment": "Wide river surface, light rain, heavy mist, layered distant hills",
    4. "style": "Blend of Eastern ink wash and realism, low-saturation blue-gray palette",
    5. "camera": "Slightly low-angle upward shot, medium-telephoto, shallow depth of field",
    6. "lighting": "Overcast diffuse light, local warm light inside the pagoda",
    7. "negative": ["text", "watermark", "structural distortion", "proportion errors"]
    8. }

    The key point is that once slots are explicit, edits become controllable. When the user says “a bit taller” or “heavier rain,” the system changes only the corresponding field instead of rewriting the whole natural-language description, which directly determines how fast multi-turn iteration converges.

    4. Multi-Turn Iteration and Version Management: Making “Pick the Fourth One” Executable

    The most common failure in multi-turn generation is coreference resolution. When the user says “I’ll take the fourth one, no more generation needed,” the system must know which task the fourth candidate belongs to and which slot set it corresponds to. Practices that work in production include:

    • Create a task ID for each generation task, with candidates queued by index;
    • Maintain slot snapshots, binding each candidate to the full parameters used to generate it;
    • Write the selection into session state, and base later edits on incremental changes to that snapshot;
    • Preserve rollback capability so the user can “go back to the previous version and change it.”
    1. task_20260822_01
    2. ├─ #1 slots_v1 (tower 40m, moderate rain)
    3. ├─ #2 slots_v2 (tower 45m, moderate rain)
    4. ├─ #4 slots_v4 (tower 45m, heavy rain, upward angle) ← selected
    5. └─ baseline for later edits = slots_v4

    5. Handling Compute Cost and Free-Tier Limits

    Users worry that repeated regeneration will burn through a large amount of compute, and this is the most realistic engineering constraint for multimodal applications. Six general and effective measures:

    1. Semantic caching: hash normalized slots and reuse historical results on a hit;
    2. Incremental redraw: repaint only the changed regions instead of recomputing the whole image;
    3. Resolution tiers: produce a low-resolution draft for selection first, then render the final high-resolution version once the choice is made;
    4. Batching and queuing: schedule non-real-time tasks together to smooth out peaks and fill valleys;
    5. Quotas and token buckets: rate-limit per session so a single user cannot consume excessive resources;
    6. Cost observability: instrument every call and record latency, retry counts, and resource consumption.
    1. def generate_with_budget(slots, budget):
    2. draft = generate(slots, resolution="low") # low-cost draft
    3. if not acceptable(draft):
    4. return draft
    5. return generate(slots, resolution="high") # upgrade only when necessary

    Note that specific billing rules, free-tier allowances, and quota policies are operational details of each service provider. Engineering should abstract them into a configurable budget and rate-limiting module rather than hard-coding them into business logic.

    6. Observability, Evaluation, and Hallucination Suppression

    A generative pipeline must be measured, or it cannot be iterated. Collect at least three categories of metrics:

    • Quality metrics: structural compliance (whether story count and height match), style consistency, human adoption rate;
    • Performance metrics: first-frame latency, end-to-end latency, failure and retry rates;
    • Cost metrics: calls per session, cache hit rate, resource consumption per result.

    The general way to suppress hallucinations is a constraint validation loop: after generation, automatically check whether key slots are satisfied (for example height, story count, presence of text or watermarks), and automatically issue one corrective prompt round if not, instead of pushing verification onto the user. At the same time, state capability boundaries clearly when they cannot be confirmed, and avoid overstating what the system can do.

    7. Running It in the Cloud: A Generic Capability Mix

    To reproduce this experience in production, you generally only need to compose generic cloud capabilities, with no dependency on proprietary interfaces:

    • A container platform to host the orchestration service and a stateless inference gateway;
    • A message queue for asynchronous queuing and peak smoothing of generation tasks;
    • Object storage to hold candidate images and version snapshots;
    • A content delivery network to accelerate result delivery;
    • Logging plus monitoring and alerting for full-chain tracing and a cost dashboard;
    • Key and configuration management to isolate model credentials from business configuration.

    Baidu AI Cloud offers exactly these generic capability categories for this kind of scenario, and developers can combine them freely according to their own scale to form a closed loop of orchestration, generation, and governance.

    8. Conclusion

    Generating images directly inside a conversation is not a single feature but the combined result of intent understanding, tool orchestration, state management, and cost governance. Translating literary requests into structured slots, building multi-turn edits on version snapshots, and constraining compute spend with caching and tiered strategies are the fundamental reasons this kind of application feels smooth and remains sustainable.