Skip to main content

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

Project description

๐ŸŽจ Agent Canvas

Executable visual lessons for AI-native education.

Agent Canvas is a typed Python DSL for describing visual lessons โ€” text, shapes, annotations, and timelines โ€” as structured, validated data instead of one-off scripts or static media. Write a lesson once, serialize it to JSON, and render it anywhere a renderer exists.

Python 3.12+ License: MIT Ruff Tests PyPI

Installation โ€ข Quick Example โ€ข Why Agent Canvas โ€ข Features โ€ข Architecture โ€ข Roadmap


Installation

# pip
pip install agent-draw

# uv (recommended)
uv add agent-draw

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

For contributors, an editable install:

git clone https://github.com/harshitgavita-07/agent-canvas.git
cd agent-canvas
uv sync --all-groups

The PyPI distribution is named agent-draw; the importable module remains agent_canvas:

from agent_canvas import Lesson, LessonMetadata, TextCommand, RectangleCommand

Repository: github.com/harshitgavita-07/agent-canvas


Quick Example

1. Define a lesson as typed Python objects.

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=[
        {
            "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),
            ),
        },
        {
            "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")),
            ),
        },
    ],
)

2. Serialize it to JSON. Every model is Pydantic-backed, so the output is validated and lossless.

with open("hello_lesson.json", "w") as f:
    f.write(lesson.model_dump_json(indent=2))

3. Reload and validate it later, from anywhere.

with open("hello_lesson.json") as f:
    loaded = Lesson.model_validate_json(f.read())
    print(f"Loaded lesson: {loaded.metadata.title}")
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 }
      }
    }
  ]
}

Today, that JSON is the portable artifact: it can be validated, diffed, stored, and handed to a renderer once one exists for your target format. That's the contract Agent Canvas is building around.


Why Agent Canvas

Large language models are good at explaining things, but there's no standard way for them to draw an explanation. Every AI tutor or content pipeline ends up inventing its own ad-hoc drawing format, tightly coupled to whatever renderer it started with.

Agent Canvas separates what a lesson contains from how it gets rendered:

Problem Agent Canvas's approach
Every AI tutor invents its own output format One typed, Pydantic-validated schema LLMs can target
Lesson content is locked to a single output (a video file, a PDF) Lessons serialize to plain JSON, independent of any renderer
No safety net between "LLM output" and "on-screen" Full validation layer catches malformed lessons before rendering
Static slides and videos can't be replayed, edited, or re-targeted Lessons are data โ€” diffable, versionable, re-renderable

Built for:

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

Note: Agent Canvas today is a DSL and validation layer, not a rendering engine. Rendering backends (SVG, PNG, playback) are on the roadmap โ€” see Current Capabilities below for exactly what's implemented now.


Features

Available Today

  • Typed DSL โ€” Text, Line, Arrow, Circle, Rectangle, and Scribble commands, plus Highlight/Underline annotations and Pointer/Laser tool primitives
  • Pydantic models โ€” full runtime validation, 100% MyPy type hints, immutable models with no accidental mutation
  • JSON serialization โ€” clean, human-readable, lossless round-trip serialization
  • Validation layer โ€” catches malformed lessons before they reach a renderer
  • Renderer registry โ€” a pluggable interface for registering renderer backends
  • Timeline model โ€” frame-accurate timestamps, layer-based ordering with z-index, configurable FPS and duration defaults
  • 288-test suite covering models, serialization, and validation

Coming Soon

  • SVG renderer implementation
  • PNG renderer implementation
  • CLI tool for lesson preview
  • Playback / animation engine (move, fade, easing)
  • HTML5 Canvas renderer
  • Interactive playback mode

Current Capabilities

To be precise about where the project stands:

Layer Status
Canvas DSL (models, commands) โœ… Implemented
Serialization (JSON) โœ… Implemented
Validation โœ… Implemented
Renderer registry (interface) โœ… Implemented
SVG / PNG renderers ๐Ÿšง Planned, not yet implemented
Playback / animation engine ๐Ÿšง Planned, not yet implemented
Runtime engine ๐Ÿšง Planned, not yet implemented

If your use case needs an actual rendered image or video today, Agent Canvas is not yet there โ€” it currently produces validated, structured lesson data. If you need a reliable schema to generate and store AI-authored visual lessons, that part is ready now.


Project Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Agent Canvas SDK                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚   โ”‚  Canvas DSL โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚  Serializer  โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚  Output   โ”‚ โ”‚
โ”‚   โ”‚             โ”‚      โ”‚   (JSON)     โ”‚      โ”‚  (JSON)   โ”‚ โ”‚
โ”‚   โ”‚ - Models    โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚   โ”‚ - Commands  โ”‚                                           โ”‚
โ”‚   โ”‚ - Validator โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚   โ”‚             โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚   Renderer   โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ SVG / PNG โ”‚ โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚   Registry   โ”‚      โ”‚ (planned) โ”‚ โ”‚
โ”‚                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Component Description Status
Canvas DSL Core data models and commands defining lesson structure โœ… Implemented
Serializer Converts lessons to/from JSON with validation โœ… Implemented
Validator Ensures lessons conform to spec before rendering โœ… Implemented
Renderer Registry Pluggable backend interface for output formats โœ… Implemented
Playback Engine Interprets timeline events for animation ๐Ÿšง Planned
Runtime End-to-end execution engine ๐Ÿšง Planned

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 (in progress)
โ”‚   โ”œโ”€โ”€ 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 lesson timelines
serialization.py Save/load lessons from JSON
validation.py Validate lessons before rendering
python examples/hello_world.py

Roadmap

v0.1 โ€” Completed

Core Canvas DSL ยท Pydantic models ยท JSON serialization ยท Validation ยท Renderer registry ยท Type safety ยท 288-test suite

v0.2 โ€” In Progress

SVG renderer ยท PNG renderer ยท CLI tool for lesson preview ยท Enhanced animation support ยท Custom easing functions

v0.5 โ€” Planned

HTML5 Canvas renderer ยท Interactive playback mode ยท Lesson composition utilities ยท Performance optimizations

v1.0 โ€” Production Ready

Stable public API ยท Production-ready renderers ยท Comprehensive documentation ยท Integration examples


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 (planned feature)
docs/TIMELINE.md Timeline and animation guide
docs/RUNTIME.md Runtime engine docs (planned feature)
docs/ROADMAP.md Future development plans

Contributing

Issues, PRs, and design discussion are 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 pull requests must pass CI (Ruff + MyPy + pytest) before merging.


Support

Need help? See 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.

Built for educators and developers.

Report an 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.1.tar.gz (30.4 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.1-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agent_draw-0.1.1.tar.gz
  • Upload date:
  • Size: 30.4 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.1.tar.gz
Algorithm Hash digest
SHA256 e3bc7ee8f6358df6d60f4d943604e9940bc268ce7118f4cb70778ae35bca5e84
MD5 d6dfee26298b8995a2cd3306ad6d31c9
BLAKE2b-256 9dc85a8e4e1db3cc35ec777d3d41f2b33d9af6b72c57cf09602f130bd8391fd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agent_draw-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 39.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d50da348d5b92c813c7190ba80ea038af4c4011b11fca58bcd2417143212cf50
MD5 9d73885d666af3678b887b666a2f5b84
BLAKE2b-256 dfde03177e8b4a5d5786a1f915036c16248e80d5b795832c2e3cc2a3024e45e5

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