Skip to main content

Overview

Canvas provides a persistent text document system that allows you to create, edit, and manage text content with AI assistance. Without Canvas, text editing requires manual file management and lacks intelligent content organization. With Canvas, you can:
  • Create persistent documents - Build and maintain text documents that persist across sessions
  • Intelligent editing - Use AI to intelligently update and modify document sections
  • Automatic organization - Let AI handle content placement and document structure
  • Clean formatting - Automatically remove code blocks and maintain clean text
  • Flexible content management - Add, update, or replace sections as needed

Quick Start

Your First Canvas

import asyncio
from upsonic import Canvas, Task, Agent


async def main():
    # Create a canvas with a name
    canvas = Canvas("My Project Notes")

    # Get current state (starts empty)
    current_content = canvas.get_current_state_of_canvas()
    print(current_content)  # "Empty Canvas"

    # Add initial content
    result_canvas = await canvas.change_in_canvas(
        new_text_of_part="# Project Overview\nThis is my project documentation",
        part_definition="overview"
    )
    print(result_canvas)

if __name__ == "__main__":
    asyncio.run(main())

Using Canvas with Agent and Task

import asyncio
from upsonic import Canvas, Task, Agent

# Create canvas and agent
canvas = Canvas("Meeting Notes")
agent = Agent("openai/gpt-4o")

# Task to create meeting notes
task = Task("""
Create comprehensive meeting notes for our weekly team standup including:
- Attendees and their roles
- Key discussion points
- Action items with owners
- Next meeting agenda
""")

# Execute task and update canvas
result = agent.do(task)
asyncio.run(canvas.change_in_canvas(
    new_text_of_part=result,
    part_definition="weekly standup"
))

Document Updates with AI

import asyncio
from upsonic import Canvas, Task, Agent

async def main():
    canvas = Canvas("Project Documentation")
    agent = Agent("openai/gpt-4o")

    # Update existing document
    task = Task("""
    Review and update the project documentation with:
    - Latest technical specifications
    - Updated API endpoints
    - New deployment procedures
    - Security best practices
    """)

    result = agent.do(task)
    result_canvas = await canvas.change_in_canvas(
        new_text_of_part=result,
        part_definition="technical updates"
    )
    print(result_canvas)

if __name__ == "__main__":
    asyncio.run(main())

Configuration Guide

Basic Canvas Setup

import asyncio
from upsonic import Canvas, Task, Agent

async def main():
    # Simple canvas with default model
    canvas = Canvas("My Document")
    
    # Canvas with custom model
    canvas = Canvas("Technical Notes", model="openai/gpt-4o")
    
    # Using canvas with agent
    agent = Agent("openai/gpt-4o")
    task = Task("Create a project summary document")
    result = agent.do(task)
    canvas_result = await canvas.change_in_canvas(str(result), "project summary")
    print(canvas_result)

if __name__ == "__main__":
    asyncio.run(main())

Real-World Examples

Meeting Notes with Agent

import asyncio
from upsonic import Canvas, Task, Agent

async def main():
    canvas = Canvas("Weekly Standup")
    agent = Agent("openai/gpt-4o")

    task = Task("""
            Create meeting notes for our weekly standup including:
            - Team updates and blockers
            - Action items with owners
            - Next week priorities
            """)

    result = await agent.do_async(task)
    canvas_result = await canvas.change_in_canvas(result, "weekly standup")
    print(canvas_result)

if __name__ == "__main__":
    asyncio.run(main())

Technical Documentation

import asyncio
from upsonic import Canvas, Task, Agent

async def main():
    canvas = Canvas("API Documentation")
    agent = Agent("openai/gpt-4o")
    
    task = Task("""
    Create comprehensive API documentation for our user management endpoints:
    - Authentication methods
    - Request/response examples
    - Error handling
    - Rate limiting
    """)
    
    result = agent.do(task)
    canvas_result = await canvas.change_in_canvas(result, "API docs")
    print(canvas_result)

if __name__ == "__main__":
    asyncio.run(main())

Tips and Best Practices

  • Use descriptive canvas names - “Project Documentation” vs “Doc1”
  • Structure content logically - Use clear section headers
  • Update incrementally - Build documents progressively
  • Use appropriate models - Choose models that fit your content complexity