Text-to-Animation Engine (TTA)
A production-grade multi-agent system that transforms raw academic topics into fully narrated, animated educational videos with a 99.4% success rate — deployed at Edza.ai.
Client
Edza.ai
Year
2024
PRD
Text-to-Animation (TTA) Engine
Retrospective PRD — Production System @ Edza.ai
Documenting existing production system, written retrospectively
Why I Built This
The obvious approach — asking an LLM to write Manim animation code directly — failed in production. The pure generative baseline succeeded only ~40% of the time: the model called non-existent functions, produced malformed object layouts, and generated code that didn't compile. I designed TTA's architecture specifically to fix that failure mode, by combining generative reasoning with deterministic, template-driven execution — lifting the success rate from ~40% to 99.4% in production.
1. Overview
The Text-to-Animation Engine converts a raw academic topic (e.g. "Gauss's Law") into a fully rendered, narrated educational video, with no human in the loop. It serves CBSE/JEE/NEET students, targeting Physics, Chemistry, and Mathematics (PCM) content at production scale.
2. Problem Statement
Manim is unforgiving: a single invalid construct breaks the entire render. When given full creative latitude over both the content and code structure of an animation, an LLM frequently invents APIs that don't exist, misordered object lifecycles, or produces structurally incoherent scenes — producing a ~40% baseline success rate. This made pure generative pipelines unfit for unattended, large-scale production use.
The product requirement I set was not "make the AI better at writing code." It was "constrain what the AI is allowed to decide, so that failure becomes structurally difficult."
3. Goals
- —Generate narrated educational animation videos automatically from a topic input, with no manual editing step.
- —Achieve a production-grade 99.4% success rate (vs the ~40% pure generative baseline).
- —Support PCM subjects at launch, with an architecture that allows new subjects to be added without rewriting the orchestration layer.
- —Guarantee that every submitted topic produces some usable video, even if it falls outside a supported domain.
- —Keep rendering latency within a usable range (P95 ≈ 85 seconds).
- —Keep narration and visuals synchronised tightly (<100ms audio sync).
4. Core Architectural Principle: Neuro-Symbolic Determinism
The defining design decision is a hybrid philosophy:
- —Use generative models for reasoning and content synthesis (what to explain, in what order).
- —Use deterministic templates to enforce execution structure (how the code is built, so it can't fail in unbounded ways).
- —Use routing logic to ensure the right template is selected for the right domain.
- —Isolate failure boundaries so that one component's failure doesn't cascade through the system.
This reframes the LLM's job from "write correct code" to "fill structured slots inside code that is already guaranteed to be valid."
5. Key Decisions & Tradeoffs
Templates over fine-tuning. I rejected fine-tuning because it would still leave failure modes unbounded — a fine-tuned model can still hallucinate. Templates gave a hard ceiling on what could go wrong, at the cost of upfront engineering time per subject and less creative flexibility in scene composition. For a student-facing product, reliability is worth more than expressiveness.
85% confidence threshold for routing, not 100%. Too high a threshold would push legitimate PCM topics into the generic fallback. Too low would let ambiguous topics break templates. I tuned empirically against misclassification cost, not topic coverage.
Coverage over depth in the fallback path. For exam-prep students, "video exists but is somewhat generic" beats "no video, try a different topic." A hard rejection breaks trust in the product.
Separating rendering from the request path. Generation and rendering run as separate phases so a long render can't block API responsiveness. This added orchestration complexity but was necessary at concurrent-user scale.
6. System Components
Subject Classification & Confidence-Gated Routing — Every incoming topic predicts a subject domain with a confidence score. If confidence exceeds 85%, the topic routes to a domain-specific template. Below threshold → Wikipedia-grounded fallback pipeline.
Domain-Constrained Template Architecture — Structured template modules per subject: Mathematics, Physics, Physical Chemistry, Organic Chemistry, Computer Science. Each template enforces scene sequencing, allowed Manim constructs, naming conventions, and explicit animation boundaries.
Multi-Agent Fallback Pipeline — For topics that don't confidently match a supported domain, an orchestrator retrieves a Wikipedia summary, extracts core sections, and converts them into a structurally valid (if more generic) Manim script.
Orchestration Layer — A central AgentOrchestrator decides which template to invoke, when to trigger validation, how to handle regeneration, and when to initiate rendering and storage. New subjects can be added by registering a new template — no routing rewrite needed.
Script Validation & Rendering — Code generation and code execution are distinct phases. Render failures trigger bounded retries before falling back to a simplified render. Rendering is decoupled from the API request path.
Narration & Audio Synchronisation — Narration is generated as structured blocks, passed through TTS, then aligned to scene transitions. Decoupled from animation code so the voice model can be iterated independently.
Cloud Storage & Asset Lifecycle — Rendered videos upload to Google Cloud Storage. The system returns a public asset URL on success.
7. Production Metrics
| Metric | Result |
|---|---|
| End-to-end success rate | 99.4% |
| Rendering latency (P95) | 85 seconds |
| Audio/visual sync drift | <100ms |
| Subject coverage | Physics, Chemistry, Mathematics (PCM) |
The 99.4% figure represents the gap closed between naive LLM-driven generation (~40% success) and a production-viable pipeline, achieved entirely through structural constraint rather than improving the underlying model.
8. Core Technologies
| Layer | Technology |
|---|---|
| Application runtime | Python 3.11 |
| API layer | FastAPI with async background workers |
| Animation rendering | Manim |
| LLM / reasoning | Google Vertex AI |
| Job queueing | Redis |
| Script validation | AST parsing |
| Asset storage | Google Cloud Storage |
9. Why This Architecture Matters
I treat this system as a case study in production AI reliability engineering rather than prompt engineering. The core insight driving every design decision: when a generative model's output must be executed by a strict, failure-intolerant runtime like Manim, the way to get reliability is not to make the model smarter — it's to shrink the space of mistakes the model is structurally permitted to make.

Production Metrics
Impact
99.4% animation success rate in production
P95 end-to-end latency of 85 seconds
<100ms audio-video synchronisation
Covers Physics, Chemistry, Mathematics (PCM)
Tech Stack
1. The Problem
Creating a single high-quality educational animation requires subject matter experts, structured scriptwriting, animation engineering, and voice + post-production — a largely sequential, human-intensive workflow that is impossible to scale.
2. The Insight: LLMs Lack Spatial Awareness
Early experiments asking LLMs to write Manim scripts directly failed ~60% of the time. Models called non-existent functions, placed text labels over diagrams, and produced invalid syntax. Pure generation is unreliable for structured animation code.
3. Architecture: Neuro-Symbolic Pipeline
The solution is a hybrid approach: use LLMs for high-level reasoning and content synthesis, but confine them within strict, deterministic code scaffolds.
- Subject Classifier — routes topic to domain-specific template engine (confidence > 85%)
- Template Engine — subject-specific Manim scaffolds for Maths, Physics, Chemistry, Organic Chemistry, CS
- Wikipedia Fallback Agent — grounded generation for low-confidence or unsupported topics
- Orchestration Layer — manages routing, validation, regeneration, rendering, and storage
- TTS + Sync Layer — audio narration with <100ms video synchronisation
4. Confidence-Gated Routing
def route_topic(topic: str, subject: str, confidence: float):
if confidence >= 0.85:
return use_domain_template(subject, topic)
else:
return wikipedia_fallback_pipeline(topic)
5. Results
- 99.4% success rate (up from ~40% with pure generation)
- P95 latency: 85 seconds for a fully rendered, narrated video
- Deployed across PCM subjects at Edza.ai
This project was built at NatrajX — an AI/IT engineering agency.
Full engineering write-up, system architecture, and production metrics available on the agency site.