agent.py

Overview

The agent.py file defines the Agent class, a central entity in the InfiniFlow system responsible for managing conversational agents. An Agent encapsulates properties such as identity, avatar, description, and an embedded Domain-Specific Language (DSL) representation used to structure workflows or dialogue flows. The file also includes the nested Agent.Dsl class, which models the internal DSL structure, including components, graph nodes, edges, and messaging/history tracking.

Key functionalities provided by the Agent class include session management capabilities such as creating, listing, and deleting sessions associated with the agent. These sessions represent individual interaction instances with the agent.

This file interacts primarily with the Session class (imported from .session) to handle session lifecycle operations, and inherits from a base class Base (imported from .base) which likely provides foundational HTTP request methods (get, post, rm) and shared utilities.


Classes and Methods

Class: Agent

Agent represents a conversational or workflow agent in the InfiniFlow system.

Constructor: __init__(self, rag, res_dict)

Initializes an Agent instance.


Nested Class: Agent.Dsl

Represents the Domain-Specific Language (DSL) structure embedded within an Agent. This encapsulates the components, graph structure, message history, and references used to define the agent's operational logic.

Constructor: __init__(self, rag, res_dict)

Initializes the DSL structure with default or provided data.


Method: create_session(self, **kwargs) -> Session

Creates a new session for the agent.


Method: list_sessions(self, page: int = 1, page_size: int = 30, orderby: str = "create_time", desc: bool = True, id: str = None) -> list[Session]

Lists sessions associated with the agent, supporting pagination and sorting.


Method: delete_sessions(self, ids: list[str] | None = None)

Deletes one or more sessions by their IDs.


Important Implementation Details


Interaction with Other System Components

The Agent class acts as a gateway to managing conversational workflows and their sessions, serving as an interface between user-facing components and backend session management systems.


Visual Diagram

classDiagram
    class Agent {
        -id: str
        -avatar: str
        -canvas_type: str
        -description: str
        -dsl: Agent.Dsl
        +__init__(rag, res_dict)
        +create_session(**kwargs) Session
        +list_sessions(page:int, page_size:int, orderby:str, desc:bool, id:str) list~Session~
        +delete_sessions(ids: list~str~| None)
    }

    class Agent.Dsl {
        -answer: list
        -components: dict
        -graph: dict
        -history: list
        -messages: list
        -path: list
        -reference: list
        +__init__(rag, res_dict)
    }

    class Base {
        <<abstract>>
        +get()
        +post()
        +rm()
    }

    class Session {
        +__init__(rag, data)
    }

    Agent ..|> Base
    Agent.Dsl ..|> Base
    Agent --> Session : uses

Summary

The agent.py file provides a well-structured Agent class that models agents within the InfiniFlow platform, focusing on managing agent identity, embedded DSL workflows, and session lifecycle. It uses RESTful API calls inherited from a base class to manage sessions, encapsulating the complexity behind simple method calls. The nested Dsl class models the agent's internal workflow structure, designed for extensibility and interaction modeling.

This file is a critical component connecting the agent's representation with backend session management and workflow execution, enabling higher-level conversational or workflow orchestration in the InfiniFlow system.