Special Plugins
Special Plugins are defined to deal with information pipelines and task coordinating in a Copilot. Generally, they will not be called as common Plugins by the Copilot, but by the predefined working flow instead just like traditionally coding.
All special plugins extends the Plugin interface and contains all the plugin methods.
This doc list their special methods only.
Cerebrum
Source code: cerebrum.py
Config file example: config.yaml
Implement example: OpenAICerebrum
Special methods
-
def __init__(self, config: Dict)Configure the Cerebrum without initialization.
Make sure thetypein the config file is set to "cerebrum". -
def setup_plugins(self, plugin_manager: PluginManager)This method will be called by the Interactor to expose the plugin_manager (and all plugins in it) to the cerebrum.
Special work can be done here with the plugins, such as config OpenAI function calls from plugins, if necessary. -
def model(self) -> LLMReturn the backed LLM.
Retrieve the LLM from the plugin's resource list for convenient use. -
def interact(self, param: InteractParameter, **kwargs) -> InteractResponseThis method will be called by the Interactor to interact copilot materials (
InteractParameter) with the backed LLM.
A standardInteractResponseobject will be constructed and returned to the Interactor by reading the LLM response, so that the Interactor and other parts of the copilot need not know any detail of the LLM. -
the
rolepropertyThe getter and setter of the Cerebrum role.
The AbstractCerebrum
from concopilot.framework.cerebrum import AbstractCerebrum
This class implemented the cerebrum role which will be initialized from the config.role field of the "config.yaml".
Interactor
Source code: interactor.py
Config file example: config.yaml
Implement example: ChatWithToolInteractor
Special methods
-
def __init__(self, config: Dict)Configure the Interactor without initialization.
Make sure thetypein the config file is set to "interactor". -
def setup_prompts(self)Setup the interaction prompts if necessary.
Setup all subcomponents' prompts here, if necessary. -
def setup_plugins(self)Setup plugins under its own scope if necessary.
Setup all subcomponents' plugins here, if necessary. -
def interact_loop(self)The main interaction loop.
All main procedures of the interactor/copilot tasks should be defined here.
The BasicInteractor
from concopilot.framework.interactor import BasicInteractor
This class implemented the __init__ with passing the resource_manager, cerebrum, plugin_manager, and message_manager.
The setup_prompts and the setup_plugins methods are also defined to call the plugin_manager.generate_prompt and cerebrum.setup_plugins, respectively.
User Interface
Source code: interface.py
Config file example: config.yaml
Implement example: CmdUserInterface
Special methods
-
def __init__(self, config: Dict)Configure the UserInterface without initialization.
Make sure thetypein the config file is set to "user_interface". -
def send_msg_user(self, msg: Message)Send a message to the user.
-
def on_msg_user(self, msg: Message) -> Optional[Message]Send a message to the user and wait the user response.
This method must return the exact response to the input
msg. Implementations may need to take special mechanism to guarantee this. -
def has_user_msg(self) -> boolCheck if user has sent any message.
-
def get_user_msg(self) -> Optional[Message]Retrieve a new user message if any.
Use this withhas_user_msgfor async user interaction pipelines. -
def wait_user_msg(self) -> Optional[Message]Wait a new user message if until there is one.
Use this for async user interaction pipelines.
Message Manager
Source code: manager.py
Config file example: config.yaml
Implement example: BasicJsonMessageManager
Special methods
-
def __init__(self, config: Dict)Configure the MessageManager without initialization.
Make sure thetypein the config file is set to "message_manager". -
def parse(self, response: InteractResponse) -> List[Message]Parse the input
InteractResponseobject into aMessageobject list.
Usually called by an interactor after receiving a cerebrum response.
Plugin Manager
Source code: manager.py
Config file example: config.yaml
Implement example: BasicPluginManager
Special methods
-
def __init__(self, config: Dict)Configure the PluginManager without initialization.
Make sure thetypein the config file is set to "plugin_manager". -
def generate_prompt(self)Generate prompt for itself and managed plugins if necessary.
-
def get_combined_prompt(self) -> strReturn the combined prompt of itself and all plugins managed.
-
plugin_prompt_generatorpropertyGetter and setter of the plugin_prompt_generator object for plugin prompt generation.
-
pluginspropertyGet the full list of managed plugins.
-
plugin_id_mappropertyGet the map (
Dict[Union[uuid.UUID, str, int], Plugin]) of managed plugins arranged by the plugin id. -
plugin_name_mappropertyGet the map (
Dict[str, Plugin]) of managed plugins arranged by the plugin name. -
def add_plugin(self, plugin: Plugin)Add a new plugin to the plugin pool.
-
def get_plugin(self, *, id: Union[uuid.UUID, str, int] = None, name: str = None) -> Optional[Plugin]Retrieve a plugin with its id and name.
This class already implemented the get_plugin method,
as well as the config_resources and config_context method of the Plugin interface to configure resources and context for each plugin, respectively.
The BasicPluginManager
from concopilot.framework.plugin import BasicPluginManager
This class implemented all method in PluginManager and can be directly used.
Plugin Prompt Generator
Source code: promptgenerator.py
Config file example: config.yaml
Implement example: YamlPluginPromptGenerator
Special methods
-
def __init__(self, config: Dict)Configure the PluginPromptGenerator without initialization.
Make sure thetypein the config file is set to "plugin_prompt_generator". -
def generate_prompt(self, plugin: Plugin) -> strGenerate a prompt for the passed plugin.
Resource Manager
Source code: manager.py
Config file example: config.yaml
Implement example: BasicResourceManager
Special methods
-
def __init__(self, config: Dict)Configure the ResourceManager without initialization.
Make sure thetypein the config file is set to "resource_manager". -
def add_resource(self, resource: Resource)Add a new resource to the resource pool.
-
def initialize(self)Initialize all resources.
-
def finalize(self)Finalize all resources.
The BasicResourceManager
from concopilot.framework.resource import BasicResourceManager
This class implemented all method in ResourceManager and can be directly used.
Storage
Source code: storage.py
Config file example: config.yaml
Implement example: DiskStorage
Special methods
-
def __init__(self, config: Dict)Configure the Storage without initialization.
Make sure thetypein the config file is set to "storage". -
def get(self, key: str) -> AnyGet the stored object by the give
key. -
def get_or_default(self, key: str, default: Any) -> AnyGet the stored object by the give
key, or thedefaultif not found. -
def put(self, key: str, value: Any)Put the
valueto the storage, relate it with the givenkey. -
def remove(self, key: str) -> AnyRemove the stored object related to the given
key. -
def get_sub_storage(self, key: str) -> 'Storage'Return a sub-storage space of this storage.
A sub-storage is a dedicated area in this storage for special use.
Developers must make sure that:- a sub-storage must be a subset of this parent storage,
- a sub-storage cannot access data in other part of the parent storage,
- it is recommended that the parent storage should not access data in even its own sub-storage.
-
def remove_sub_storage(self, key: str) -> boolRemove a sub-storage relating to the specified
key. ReturnTrueif success, andFalseif failed.