Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio CanvasAssistantAgentFactory

From Leeroopedia
Knowledge Sources
Domains Agent_Systems, NLP
Last Updated 2026-10-23 12:00 GMT

Overview

Factory that builds a LangGraph ReAct agent with inspection, execution, and generation tools for autonomous canvas manipulation, using a custom tool-calling chat model.

Description

CanvasAssistantAgentFactory is a wrapper around LangGraph's create_react_agent. The factory's __call__ method builds (and caches) a compiled agent graph with:

  • Custom model selector: Returns a CanvasAssistantToolCallingChatModel bound with tools, adapting to the canvas context (document_id, user_id, api_key_id)
  • Tool set: Inspection tools (read graph state), execution tools (create/update/delete nodes and connections), generation tools (trigger text/image/video generation), and workflow tools (status, prepare script)
  • Checkpointer: InMemorySaver for session state persistence
  • Context schema: Passes document_id, user_id, api_key_id, chat_model_id, and observation snapshot as context

The build_context method loads a canvas graph snapshot for the agent to reason about.

Usage

Import when building the canvas AI assistant agent. Called by CanvasAssistantService.chat.

Code Reference

Source Location

  • Repository: ai-moive-studio
  • File: backend/src/assistant/agent_factory.py:L302-330

Signature

class CanvasAssistantAgentFactory:
    def __init__(self, db_session, inspection_tools, canvas_execution_tools,
                 generation_tools, workflow_service=None, checkpointer=None): ...

    async def __call__(self, **kwargs) -> CompiledGraph:
        """Build and cache the LangGraph ReAct agent."""

    async def build_context(self, document_id, user_id, api_key_id, chat_model_id) -> dict:
        """Load canvas graph snapshot as agent context."""

Import

from src.assistant.agent_factory import CanvasAssistantAgentFactory

I/O Contract

Inputs

Name Type Required Description
db_session AsyncSession Yes Database session
inspection_tools CanvasAssistantCanvasInspectionTools Yes Read tools
canvas_execution_tools CanvasAssistantCanvasExecutionTools Yes │ Mutation tools
generation_tools CanvasAssistantGenerationTools Yes Generation dispatch tools
workflow_service CanvasAssistantWorkflowService No Workflow status tools
checkpointer Any No Session state (default InMemorySaver)

Outputs

Name Type Description
__call__ return CompiledGraph LangGraph compiled agent

Usage Examples

Building and Invoking the Agent

from src.assistant.agent_factory import CanvasAssistantAgentFactory

factory = CanvasAssistantAgentFactory(
    db_session=session,
    inspection_tools=inspection_tools,
    canvas_execution_tools=execution_tools,
    generation_tools=generation_tools,
)
graph = await factory(
    document_id="doc-uuid",
    user_id="user-uuid",
    api_key_id="key-uuid",
    chat_model_id="model-uuid",
    session_id="session-uuid",
)
result = await graph.invoke(
    {"messages": [{"role": "user", "content": "Create a cinematic scene node"}]},
    config={"configurable": {"thread_id": "session-uuid"}},
    context=await factory.build_context("doc-uuid", "user-uuid", "key-uuid", "model-uuid"),
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment