agent.py

Overview

The agent.py file defines a RESTful API for managing "agents" within the InfiniFlow platform. An "agent" here corresponds to a user-specific canvas entity, optionally with a domain-specific language (DSL) describing its behavior or configuration. This file provides endpoints to list, create, update, and delete agents, ensuring operations are authenticated and scoped by tenant (user) ownership.

The core functionality in this file revolves around CRUD operations on the UserCanvasService and version tracking via UserCanvasVersionService. It includes input validation, JSON DSL handling, and permission enforcement so that only the owner of an agent can modify or delete it.


Detailed Explanation of API Endpoints

1. list_agents

@manager.route('/agents', methods=['GET'])
@token_required
def list_agents(tenant_id):

2. create_agent

@manager.route("/agents", methods=["POST"])
@token_required
def create_agent(tenant_id: str):

3. update_agent

@manager.route("/agents/<agent_id>", methods=["PUT"])
@token_required
def update_agent(tenant_id: str, agent_id: str):

4. delete_agent

@manager.route("/agents/<agent_id>", methods=["DELETE"])
@token_required
def delete_agent(tenant_id: str, agent_id: str):

Important Implementation Details


Interaction with Other System Components

This module is likely part of a larger backend API providing user-specific, version-controlled canvas/agent management within the InfiniFlow system.


Visual Diagram

classDiagram
    class AgentAPI {
        +list_agents(tenant_id)
        +create_agent(tenant_id)
        +update_agent(tenant_id, agent_id)
        +delete_agent(tenant_id, agent_id)
    }

    class UserCanvasService {
        +query(**kwargs)
        +get_list(tenant_id, page, size, orderby, desc, id, title)
        +save(**kwargs)
        +update_by_id(agent_id, data)
        +delete_by_id(agent_id)
    }

    class UserCanvasVersionService {
        +insert(user_canvas_id, title, dsl)
        +delete_all_versions(user_canvas_id)
    }

    AgentAPI ..> UserCanvasService : uses
    AgentAPI ..> UserCanvasVersionService : uses

Summary

The agent.py file implements a set of REST API endpoints managing the lifecycle of "agents" (user canvases) with support for DSL versioning, ownership enforcement, and pagination. It acts as a controller layer interfacing between HTTP requests and underlying database service layers, ensuring data integrity and secure multi-tenant access.

This module is a crucial part of the InfiniFlow backend, enabling users to create, view, update, and delete their agents while maintaining version control over the agent DSL configurations.