Context-Aware Video Generation Agent: Engineering Practices for Stateful Video Creation

    This article explains why video generation inside conversational agents often breaks down in production, then presents a stateful video creation agent design. It covers a four-dimension capability model, session-level context, asset reuse, versioned scripts, parameter templates, asynchronous task orchestration, tool-based integration, reproducible evaluation, and practical engineering pitfalls.

    1. Problem Background: Why Video Generation in Conversations Feels Fragmented

    Over the past two years, mainstream general-purpose conversational agents have increasingly included multimodal generation capabilities. A user can enter a natural-language prompt and receive a short video. However, few teams have truly moved video generation into production workflows. The bottleneck is often not model quality, but interaction design: generation behaves like a temporary inference endpoint attached to a chat. The user sends one message, receives one clip, and the context ends there.

    This leads to four common blocked scenarios:

    • A user wants to upload a reference image to constrain the subject’s appearance or color tone, but the chat entry point has no corresponding condition slot.
    • A user wants to view the previous generation result and modify it, but historical outputs cannot be referenced again.
    • A user wants to reuse previously uploaded assets in a new task, but there is no binding relationship between assets and tasks.
    • A user wants to fix parameters such as camera movement, duration, aspect ratio, and audio strategy into a template, but has to describe them again every time.

    The common root cause of these gaps is that the system is stateless: the conversation carries text only, not assets, versions, or execution records. Video production, however, is naturally a multi-turn, multi-asset, and highly iterative process. This mismatch breaks the user experience.

    2. Abstracting the Capability Gap: Four Dimensions

    Abstracting the phenomena above yields a four-dimension capability model for evaluating any video generation solution:

    1. Condition controllability: Does it support multimodal condition inputs such as reference images, reference videos, and style anchors, rather than text prompts only?
    2. Asset reusability: Are assets persisted with stable identifiers so they can be referenced by multiple tasks?
    3. Iteration continuity: Does each generation round form a version chain that supports “continue editing from version N”?
    4. Workflow composability: Can the capability be invoked by external agents as a tool and embedded into existing workflows?

    A solution that satisfies only the first dimension can “generate.” A solution with all four dimensions can “create.”

    3. Target Form: A Stateful Video Creation Agent

    The design goal can be summarized in one sentence: a context-aware creation agent that can work independently in conversation and can also be wrapped as a video workflow by any common agent. Within the same session, uploaded assets, revised scripts, and executed tasks are all remembered.

    3.1 Session-Level Context Model

    Context should not be just an array of messages. It should be a serializable, snapshot-capable state object:

    1. {
    2. "session_id": "s_8f21",
    3. "assets": [
    4. {"id": "a_01", "type": "image", "uri": "store://assets/a_01", "tags": ["reference image", "color tone"]}
    5. ],
    6. "script": {
    7. "current": "v3",
    8. "versions": [
    9. {"v": "v1", "prompt": "A southern Chinese fishing port on a summer evening...", "note": "initial version"},
    10. {"v": "v3", "prompt": "...one continuous shot, ambient sound only", "parent": "v2"}
    11. ]
    12. },
    13. "constraints": {"duration": "10s", "ratio": "16:9", "resolution": "720P", "audio": "ambient_only"},
    14. "tasks": [{"id": "t_11", "script": "v3", "asset_refs": ["a_01"], "status": "succeeded"}]
    15. }

    The key fields are asset_refs and parent. The former enables asset reuse across tasks; the latter makes revisions traceable and rollback-friendly.

    3.2 Asset Registry and Reference Mechanism

    Upload means registration, and registration means persistence. Assets are stored in object storage, while metadata such as type, duration, resolution, tags, and source session is stored in structured storage. Externally, only a stable ID is exposed. Prompts and parameters reference the ID instead of repeatedly transmitting binary content. This saves bandwidth and makes tasks replayable.

    3.3 Versioned Scripts and Parameter Templates

    Combine “prompt + constraints” into an immutable version. Any modification creates a new version that points to its parent version. Common combinations, such as “10 seconds / 16:9 / 720P / one continuous shot / ambient sound only,” can be fixed as named templates. Later, a task only needs to call use_template("horizontal_short").

    3.4 Asynchronous Task Orchestration

    Video generation is a long-running task and must be asynchronous. Tasks enter a message queue, the execution side scales horizontally on a container platform, and status plus outputs are written back to the registry. Queueing time, failure rate, and output qualification rate can be observed through logging services and monitoring alerts.

    4. Wrapping the Creation Agent into Any General Agent

    Expose only a small number of semantically clear tools. A general agent can orchestrate them through function calls:

    1. {
    2. "name": "video_create",
    3. "description": "Generate or iterate a video based on session context, automatically reusing registered assets and historical versions",
    4. "parameters": {
    5. "type": "object",
    6. "properties": {
    7. "prompt": {"type": "string"},
    8. "asset_refs": {"type": "array", "items": {"type": "string"}},
    9. "base_version": {"type": "string", "description": "The version to continue editing from; defaults to the current version"},
    10. "template": {"type": "string"}
    11. }
    12. }
    13. }

    With two read-only tools, video_status and video_list_versions, a general agent can complete the loop of “generate — inspect — revise — generate again.” The key design point is stateless tools with a stateful session: state is maintained by the creation agent, and callers do not need to be aware of it.

    5. Baseline Comparison: Reproducible Evaluation with the Same Prompt

    To compare solutions, control variables first. Fix the prompt:

    A southern Chinese fishing port on a summer evening. A woman in an off-white shirt walks out of an old wooden door, takes a few steps, turns to look at the sea. About 10 seconds, 16:9, 720P, one continuous shot, ambient sound only.

    Run the same prompt on three implementations: the native video capability of a general conversational agent, the built-in generation of another conversational agent, and an orchestrated solution connected to a stateful creation agent. All three can deliver an approximately 10-second horizontal original clip. The differences mainly appear in controllability and iterability, not single-frame image quality.

    Recommended evaluation checklist:

    Dimension Checkpoint
    Specification compliance Whether duration, aspect ratio, resolution, and frame rate match the constraints
    Semantic fidelity Whether the scene, character actions, and camera movement match the prompt
    Subject consistency Whether the character’s appearance, clothing, and color tone drift across multiple generations
    Audio strategy Whether only ambient sound is retained, without extra background music or human voice
    Iteration cost How much information must be restated and how long it takes to revise one version
    Regressability Whether historical versions can be reproduced and compared

    The first four items measure single-generation quality. The last two measure engineering maturity, which is the real dividing line for production readiness.

    6. Common Pitfalls and Best Practices

    • Do not treat long context as memory: The context window will overflow. State must be externalized to a registry and referenced by ID.
    • Structure constraints: Write duration, aspect ratio, and similar constraints as fields rather than burying them in natural language. This makes validation and reuse easier.
    • Always validate specifications: Before an output is stored, automatically check resolution and duration. If it fails, roll back and retry.
    • Keep versions immutable: Any modification creates a new version. Never overwrite in place, otherwise regression is impossible.
    • Make observability a prerequisite: Queueing, failures, retries, and output qualification rates all need metrics and alerts.

    7. Summary

    Conversational agents with built-in video generation are not inherently unusable. What they lack is the “state” layer. By adding asset registration, script versioning, constraint templates, and asynchronous task orchestration, video generation evolves from a one-time API call into a creation workflow that can be accumulated, composed, and regression-tested. For implementation, storage, queues, containers, and observability can be provided by general cloud services, such as Baidu AI Cloud object storage, message queue, container platform, log service, and monitoring/alerting. Teams can then focus on the two things that truly determine quality: the context model and the evaluation system.