base.py


Overview

The base.py file defines foundational classes and data structures used for integrating and managing "tools" within the InfiniFlow agent framework. These tools are components that expose functionality (such as API calls or computational logic) which can be invoked programmatically and managed within a canvas-based workflow environment.

Key responsibilities of this file include:

This file plays a central role in the architecture by establishing the interface and lifecycle of tools, ensuring consistency in parameter handling, invocation, and output management, and by bridging between lower-level tool implementations and the higher-level canvas workflow system.


Classes and Functions

TypedDicts for Metadata

ToolParameter

class ToolParameter(TypedDict):
    type: str
    description: str
    displayDescription: str
    enum: List[str]
    required: bool

ToolMeta

class ToolMeta(TypedDict):
    name: str
    displayName: str
    description: str
    displayDescription: str
    parameters: dict[str, ToolParameter]

Class: LLMToolPluginCallSession

class LLMToolPluginCallSession(ToolCallSession):
tools = {
    "search": search_tool_instance,
    "translate": MCPToolCallSession(...)
}
def callback(name, args, resp, elapsed_time):
    print(f"Tool {name} called in {elapsed_time:.2f}s")
session = LLMToolPluginCallSession(tools, callback=callback)
result = session.tool_call("search", {"query": "example"})

Class: ToolParamBase

class ToolParamBase(ComponentParamBase):

Class: ToolBase

class ToolBase(ComponentBase):
class MyToolParam(ToolParamBase):
    meta = {
        "name": "my_tool",
        "description": "Example tool",
        "parameters": {
            "param1": {"type": "string", "description": "Input param", "required": True}
        }
    }

class MyTool(ToolBase):
    def _invoke(self, param1):
        # Tool logic here
        return f"Processed {param1}"

canvas = Canvas()
param = MyToolParam()
tool = MyTool(canvas, "tool1", param)
result = tool.invoke(param1="test")
print(result)  # Output: Processed test

Important Implementation Details


Interaction with Other System Components


Diagram: Class Structure and Relationships

classDiagram
    class ToolParameter {
        +type: str
        +description: str
        +displayDescription: str
        +enum: List[str]
        +required: bool
    }

    class ToolMeta {
        +name: str
        +displayName: str
        +description: str
        +displayDescription: str
        +parameters: dict[str, ToolParameter]
    }

    class LLMToolPluginCallSession {
        -tools_map: dict[str, object]
        -callback: partial
        +__init__(tools_map, callback)
        +tool_call(name: str, arguments: dict) Any
        +get_tool_obj(name) object
    }

    class ToolParamBase {
        -inputs: dict
        +__init__()
        +_init_inputs()
        +_init_attr_by_meta()
        +get_meta() dict
    }

    class ToolBase {
        -_canvas: Canvas
        -_id: str
        -_param: ComponentParamBase
        +__init__(canvas, id, param)
        +get_meta() dict
        +invoke(**kwargs) Any
        -_retrieve_chunks(res_list, get_title, get_url, get_content, get_score=None)
        +thoughts() str
    }

    ToolParamBase --|> ComponentParamBase
    ToolBase --|> ComponentBase
    LLMToolPluginCallSession --|> ToolCallSession

Summary

The base.py file provides the core abstractions and utilities for defining, parameterizing, invoking, and managing tools in the InfiniFlow agent platform. It enables consistent metadata handling, robust invocation with error and time tracking, and supports integration into the canvas-driven workflow system. The LLMToolPluginCallSession facilitates tool invocation in an LLM context, bridging between tool implementations and conversational agents.

This base layer is essential for extending the system with new tools and ensuring they adhere to expected interfaces and behaviors within the agent ecosystem.