Skip to main content

An open-source Python SDK for building executable learning experiences.

Project description

๐ŸŽจ Agent Canvas

The executable DSL for AI-generated learning experiences

Write a lesson once in Python. Play it back anywhere โ€” SVG, PNG, video, or your own renderer.

Python 3.12+ License: MIT Ruff Tests PyPI

๐Ÿš€ Quick Start โ€ข โœจ Why Agent Canvas โ€ข ๐Ÿงฉ Features โ€ข ๐Ÿ“ Architecture โ€ข ๐Ÿ—บ๏ธ Roadmap โ€ข ๐Ÿค Contributing


Agent Canvas demo โ€” an AI-generated lesson animating on canvas

โšก TL;DR

Static slides and videos can't adapt to a learner. LLMs can generate great explanations โ€” but there's no standard, executable format for what they generate. Agent Canvas is that format.

lesson.add(RectangleCommand(...)).add(TextCommand(...))
lesson.save("hello_lesson.json")  # portable, replayable, renderer-agnostic

One typed, validated JSON lesson โ†’ rendered as SVG today, video tomorrow, an interactive canvas next quarter โ€” without touching your generation pipeline.


๐Ÿง  Why Agent Canvas

The old way With Agent Canvas
โŒ Static slides/videos that never adapt โœ… Lessons that replay, animate, and re-render on demand
โŒ Every AI tutor invents its own ad-hoc output format โœ… One typed, Pydantic-validated schema LLMs can target reliably
โŒ Content locked to a single output (a video file, a PDF) โœ… Write once, render to SVG, PNG, or video via pluggable renderers
โŒ No safety net between "LLM output" and "on-screen" โœ… Full validation layer catches malformed lessons before render

Built for:

  • ๐ŸŽ“ Educational platforms generating interactive lessons from AI tutors
  • ๐Ÿ“š Content teams building animated tutorials programmatically
  • ๐Ÿค– AI agent builders who need a structured way to draw, not just talk
  • ๐Ÿ“Š Docs teams creating executable diagrams and flowcharts that stay in sync with code

๐Ÿงฉ Features

๐Ÿ–Š๏ธ Core DSL

  • Text, Line, Arrow, Circle, Rectangle, Scribble
  • Highlight & Underline annotations
  • Pointer and Laser tools
  • Move / Fade animations with configurable easing
  • Wait, Pause, Erase, Clear control flow

๐Ÿ”’ Type Safety

  • Full Pydantic runtime validation
  • 100% MyPy type hints
  • Immutable models โ€” no accidental mutation

๐Ÿ“ฆ Serialization

  • Clean, human-readable JSON output
  • Lossless round-trip serialization
  • Version-aware, forward/backward compatible

๐Ÿ”Œ Renderer-Agnostic

  • Pluggable renderer registry
  • SVG, PNG, HTML5 Canvas (community renderers, in progress)

๐ŸŽฌ Timeline-Based Playback

  • Frame-accurate timestamp control
  • Layer-based rendering with z-index
  • Configurable FPS & duration defaults

๐Ÿš€ Quick Start

Ship your first lesson in under 2 minutes.

1. Install

# pip
pip install agent-canvas

# uv (recommended)
uv add agent-canvas

# editable install for contributors
git clone https://github.com/agent-canvas/agent-canvas.git
cd agent-canvas && pip install -e .

Requires Python 3.12+. Core deps: pydantic, rich, typer, loguru, networkx, python-dotenv.

2. Build a lesson

from agent_canvas import (
    Lesson,
    LessonMetadata,
    TextCommand,
    RectangleCommand,
    Point,
    Size,
    Bounds,
    Style,
    Color,
)

lesson = Lesson(
    metadata=LessonMetadata(
        title="Hello, Agent Canvas!",
        description="A quick introduction to the SDK",
        author="Your Name",
    ),
    timeline=[
        # Frame 1: draw a rectangle
        {
            "timestamp": 0.0,
            "command": RectangleCommand(
                bounds=Bounds(
                    position=Point(x=100, y=100),
                    size=Size(width=400, height=200),
                ),
                style=Style(color=Color(value="#3B82F6"), stroke_width=2),
            ),
        },
        # Frame 2: add text
        {
            "timestamp": 1.0,
            "command": TextCommand(
                position=Point(x=300, y=200),
                text="Welcome to Agent Canvas!",
                font_size=24,
                style=Style(color=Color(value="#1E293B")),
            ),
        },
    ],
)

3. Serialize, save, reload โ€” anywhere

import json

json_output = lesson.model_dump_json(indent=2)

with open("hello_lesson.json", "w") as f:
    f.write(json_output)

with open("hello_lesson.json") as f:
    loaded = Lesson.model_validate_json(f.read())
    print(f"Loaded lesson: {loaded.metadata.title}")
See the resulting JSON
{
  "metadata": {
    "title": "Hello, Agent Canvas!",
    "description": "A quick introduction to the SDK",
    "author": "Your Name",
    "version": "0.1.0",
    "tags": []
  },
  "timeline": [
    {
      "timestamp": 0.0,
      "command": {
        "command": "rectangle",
        "bounds": {
          "position": { "x": 100, "y": 100 },
          "size": { "width": 400, "height": 200 }
        },
        "style": { "color": "#3B82F6", "stroke_width": 2 }
      }
    }
  ]
}

๐Ÿ“ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     Agent Canvas SDK                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚   Canvas     โ”‚     โ”‚   Playback   โ”‚     โ”‚  Renderer   โ”‚  โ”‚
โ”‚  โ”‚     DSL      โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚    Engine    โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   Registry  โ”‚  โ”‚
โ”‚  โ”‚              โ”‚     โ”‚              โ”‚     โ”‚             โ”‚  โ”‚
โ”‚  โ”‚  - Models    โ”‚     โ”‚  - Timeline  โ”‚     โ”‚  - SVG      โ”‚  โ”‚
โ”‚  โ”‚  - Commands  โ”‚     โ”‚  - Player    โ”‚     โ”‚  - PNG      โ”‚  โ”‚
โ”‚  โ”‚  - Validator โ”‚     โ”‚  - Scheduler โ”‚     โ”‚  - Custom   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚         โ”‚                                       โ”‚            โ”‚
โ”‚         โ–ผ                                       โ–ผ            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚ Serializer   โ”‚                       โ”‚   Output    โ”‚      โ”‚
โ”‚  โ”‚   (JSON)     โ”‚                       โ”‚   Files     โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ”‚                                                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Component Description
Canvas DSL Core data models and commands defining the lesson structure
Serializer Converts lessons to/from JSON with validation
Playback Engine Interprets timeline events for animation (planned)
Renderer Registry Pluggable backend for different output formats
Validators Ensures lessons conform to spec before rendering

๐Ÿ“ Repository Structure

agent-canvas/
โ”œโ”€โ”€ src/agent_canvas/
โ”‚   โ”œโ”€โ”€ __init__.py          # Public API exports
โ”‚   โ”œโ”€โ”€ canvas/               # Core DSL implementation
โ”‚   โ”‚   โ”œโ”€โ”€ models.py         # Pydantic models (Point, Lesson, etc.)
โ”‚   โ”‚   โ”œโ”€โ”€ commands/         # Command implementations
โ”‚   โ”‚   โ”œโ”€โ”€ serializer.py     # JSON serialization
โ”‚   โ”‚   โ”œโ”€โ”€ validator.py      # Lesson validation
โ”‚   โ”‚   โ””โ”€โ”€ registry.py       # Renderer registry
โ”‚   โ”œโ”€โ”€ renderer/              # Rendering backends
โ”‚   โ”œโ”€โ”€ playback/              # Timeline playback (planned)
โ”‚   โ””โ”€โ”€ runtime/                # Runtime engine (planned)
โ”œโ”€โ”€ tests/                     # Test suite (288 tests)
โ”œโ”€โ”€ examples/                  # Usage examples
โ”œโ”€โ”€ docs/                       # Documentation
โ”œโ”€โ”€ SPEC.md                     # DSL specification
โ””โ”€โ”€ pyproject.toml              # Project configuration

๐Ÿงช Examples

Example Description
hello_world.py Minimal lesson creation
draw_text.py Text rendering with various styles
draw_shapes.py Rectangles, circles, lines, arrows
annotations.py Highlights and underlines
timeline.py Multi-frame animations
serialization.py Save/load lessons from JSON
validation.py Validate lessons before rendering
svg_export.py Export lesson to SVG
png_export.py Export lesson to PNG
python examples/hello_world.py

๐Ÿ“š Documentation

Document Description
SPEC.md Complete DSL specification
docs/ARCHITECTURE.md High-level architecture
docs/CANVAS_DSL.md DSL reference guide
docs/PLAYBACK.md Playback engine documentation
docs/TIMELINE.md Timeline and animation guide
docs/RUNTIME.md Runtime engine docs
docs/ROADMAP.md Future development plans

๐Ÿ—บ๏ธ Roadmap

v0.1.0 โ€” Current โœ… Core Canvas DSL ย ยทย  โœ… Pydantic models ย ยทย  โœ… JSON serialization ย ยทย  โœ… Validation ย ยทย  โœ… Renderer registry ย ยทย  โœ… Type safety ย ยทย  โœ… 288-test suite

v0.2.0 โ€” Next

  • SVG renderer implementation
  • PNG renderer implementation
  • CLI tool for lesson preview
  • Enhanced animation support
  • Custom easing functions

v0.3.0

  • HTML5 Canvas renderer
  • Interactive playback mode
  • Lesson composition utilities
  • Performance optimizations

v1.0.0

  • Stable public API
  • Production-ready renderers
  • Comprehensive documentation
  • Integration examples

๐Ÿค Contributing

Contributions make this project better โ€” issues, PRs, and ideas are all welcome. See the Contributing Guide.

# Fork and clone
git clone https://github.com/YOUR_USERNAME/agent-canvas.git
cd agent-canvas

# Set up environment
uv sync --all-groups

# Run tests
pytest

# Lint and type check
ruff check .
mypy src

All PRs must pass CI (Ruff + MyPy + pytest) before merging.


๐Ÿ’ฌ Support

Need help? Check the Support Guide for bug reports, feature requests, questions, and commercial support.


๐Ÿ™ Acknowledgments

Agent Canvas draws inspiration from Manim, Pydantic, Rich, and Textual.


๐Ÿ“„ License

Agent Canvas is licensed under the MIT License.


If Agent Canvas is useful to you, a โญ on GitHub goes a long way.

Built with โค๏ธ for educators and developers

Report Issue โ€ข Discussions โ€ข Changelog

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_draw-0.1.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_draw-0.1.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file agent_draw-0.1.0.tar.gz.

File metadata

  • Download URL: agent_draw-0.1.0.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for agent_draw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ce375cdc8d6cf8395181540dd0ce2934e2b58cbcbba830963d8d701d6ae1a6d
MD5 ee5f7e1b09aa5f6f50c3c7e44e0477e1
BLAKE2b-256 dd457e71a50b6c9b47b4cc80647ae999aa388ccfbcd885005119ab4c2b2318b4

See more details on using hashes here.

File details

Details for the file agent_draw-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agent_draw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for agent_draw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f067f2fcabb20bc0da489a03b680d7fdb3526fa3c2bfce16142c47a49725346d
MD5 217f1575db303351dae57190143eaa86
BLAKE2b-256 9cf9a442fe954217e662d9aeebef703f0aa382cc9eb262ef02b052b6f22a286f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page