Plugin#

EvoFabric supports user-defined plugins, and the currently predefined plugin types are:

Note

Supported plugin types can also be looked up in evofabric.plugin_manager.PluginTypeDict

Plugin Integration Principle#

Plugins integrating with the EvoFabric framework require the use of Python’s entry-points mechanism: when users define entry-points in the configuration file of their plugin package, EvoFabric will automatically recognize the plugin.

Example as follows:

# ChatClientBase type plugin
[project.entry-points."ChatClientBase"]
# 'demo_tool1' is plugin name
demo_tool1 = "demo_tool1:create"

The above configuration demo_tool1:create() corresponds to the demo_tool1.create function, and EvoFabric will call this function during the plugin registration phase to obtain the plugin class.

Plugin initialization logic is visible: evofabric.plugin_manager.load_plugins()

After being loaded by the EvoFabric framework, plugins automatically inherit from the parent class corresponding to their type, and users can then use the corresponding plugins as needed.

Plugin Example#

Next, we can customize a plugin named demo_tool1 according to this guide:

  1. First, we need to create a new Python package. The directory structure is as follows:

demo_tool1
│  pyproject.toml
│  README.md
│
├─demo_tool1
│   invoke_tool.py
│   __init__.py

The pyproject.toml file contains the entry-points registration block, the specific configuration is as follows:

# pyproject.toml

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "demo_tool1"
version = "0.1.3"
authors = [
  { name="author", email="author@example.com" },
]
description = "An Agent System plugin demo."
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

dependencies = []

[project.entry-points."ChatClientBase"]
# 'demo_tool1' is plugin name.
demo_tool1 = "demo_tool1:register"
  1. Write plugin logic. The following is a streaming output example of an LLM module, located at demo_tool1/invoke_tool.py:

from pydantic import Field


class LLMRunner:
state: str = Field(description="zhuan")

async def create_on_stream(
        self, messages
):
    for token in "This is the implementation of create_on_stream.":
        yield token
  1. Add registration function, located at demo_tool1/invoke_tool.py:

def register():
    return "demo_tool1.LLMRunner"

The plugin has been completed. Simply execute pip install -e . in the current directory to install it.