Agents working on text-based tasks are highly prone to rewriting the text unnecessarily, editing parts that shouldn’t be modified, and introducing errors. This creates a process where developers must manually make adjustments and continuously implement checkpoints, especially when handling text-based use cases.Within the Upsonic framework, we have a Canvas feature specifically designed to address this issue and provide a direct solution. This feature includes specialized and sensitive functions tailored for creating and editing a text canvas.
A Canvas is created with a specific name and can be assigned to a Task or class as a tool. This enables Agents or Direct operations to easily perform text edits.
Copy
from upsonic import Canvasmy_travel_guide_canvas = Canvas("Travel Guide") # Creating an canvas with an uniqe name
Once your tasks are executed by the agent, the canvas retains all modifications in a consistent state. This enables you to query or display the final version of the text after all edits have been applied. By decoupling text state from the agent logic, you gain better control over the output, making it easier to debug, review, or pass the final content into downstream systems like editors, emails, or publishing pipelines.
Copy
from upsonic import Task, Agent, Canvas# My Agent with Canvasmy_travel_guide_canvas = Canvas("Travel Guide") # Creating an canvas with an uniqe nameagent = Agent( name="My Travel Agent", canvas=my_travel_guide_canvas # Adding canvas)# My Taskstask = Task("Generate a plan to visit cities in Canad")task2 = Task("Edit the canvas first section with Hi guys")# Completing my Tasksagent.do(task)agent.do(task2)# Getting canvas final stateprint(my_travel_guide_canvas.get_current_state_of_canvas())