plugin

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FireHooks

func FireHooks(ctx context.Context, registry *Registry, event HookEvent, data interface{}) error

FireHooks fires all registered hooks for the given event. Hooks are called in registration order. If any hook returns an error, subsequent hooks are still called but the first error is returned.

func ResolveSlot

func ResolveSlot(def Definition, activeSlots map[string]string, config SlotConfig) error

ResolveSlot determines whether a plugin should be activated based on its Kind and the slot configuration.

Returns nil if the plugin is allowed; returns an error (with explanation) if the plugin should be skipped.

This implements OpenClaw's slot exclusion mechanism where only one plugin per Kind can be active at a time.

Types

type CLIProvider

type CLIProvider interface {
	Plugin

	// CLIRegistrars returns the CLIRegistrars provided by this plugin.
	CLIRegistrars() []CLIRegistrar
}

CLIProvider is an optional plugin interface for plugins that provide CLI commands. This corresponds to openclaw's registerCli() capability.

type CLIRegistrar

type CLIRegistrar interface {
	// RegisterCommands adds subcommands to the given parent command
	RegisterCommands(parent *cobra.Command)
}

CLIRegistrar is the interface for plugins that register CLI commands. This corresponds to openclaw's registerCli() capability.

type Code

type Code int

Code is a status code returned by plugin operations. Modeled after K8s scheduler framework's Code type.

const (
	// Success means the plugin operation completed successfully.
	Success Code = iota
	// Error means the plugin encountered a fatal error.
	Error
	// Skip means the plugin chose to skip this operation.
	Skip
	// Unschedulable means the operation cannot be completed (K8s terminology).
	Unschedulable
)

func (Code) String

func (c Code) String() string

String returns the human-readable name of the code.

type CompletedConfig

type CompletedConfig struct {
	*Config
}

CompletedConfig is the validated and completed framework configuration.

func (CompletedConfig) New

func (c CompletedConfig) New() *Framework

New creates a new Framework from the completed configuration.

type Config

type Config struct {
	// SlotConfig controls which plugins are active per slot kind.
	SlotConfig SlotConfig

	// RuntimeAPI provides plugins access to core modules.
	RuntimeAPI RuntimeAPI
}

Config holds the configuration for creating a Framework. Follows the K8s Config → Complete() → New() pattern.

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete validates and fills in defaults for the framework configuration.

type Definition

type Definition struct {
	ID          string
	Name        string
	Kind        string
	Description string
}

Definition is the static metadata for a plugin. It is used to register plugins into the framework.

type Framework

type Framework struct {
	// contains filtered or unexported fields
}

Framework is the core plugin framework that manages plugin lifecycle. It orchestrates: plugin loading → slot resolution → Init → Start → Stop.

This is modeled after K8s scheduler's frameworkImpl, which: 1. Holds the plugin registry 2. Manages plugin instantiation via factories 3. Drives the scheduling cycle (in our case, plugin lifecycle)

The Framework implements the Handle interface, so plugins can access shared runtime resources through it.

func (*Framework) Handle

func (f *Framework) Handle() Handle

Handle returns the framework Handle for external use.

func (*Framework) Init

func (f *Framework) Init() error

Init instantiates all registered factories, resolves slots, and calls Init/Register on each plugin.

This corresponds to the "plugin loading" phase in OpenClaw: 1. Iterate factories in registration order 2. Resolve slot constraints 3. Instantiate plugin via factory 4. Call InitPlugin.Init() if implemented (register Tool/CLI/Hook/Service) 5. Auto-probe for ToolProvider/HookProvider/ServiceProvider/CLIProvider interfaces

func (*Framework) PromptPipeline

func (f *Framework) PromptPipeline() *prompt.Pipeline

PromptPipeline returns the attached PromptPipeline.

func (*Framework) RegisterFactory

func (f *Framework) RegisterFactory(def Definition, factory PluginFactory, args PluginArgs) error

RegisterFactory registers a PluginFactory with its Definition and optional args. This is analogous to K8s scheduler's WithPlugin() option.

Factories are registered before Init(); the Framework instantiates plugins from them during Init().

func (*Framework) Registry

func (f *Framework) Registry() *Registry

Registry returns the underlying plugin registry. Used by the server to query registered tools, hooks, CLI commands, etc.

func (*Framework) SetPromptPipeline

func (f *Framework) SetPromptPipeline(pipeline *prompt.Pipeline)

SetPromptPipeline attaches a PromptPipeline to the framework. Plugin-contributed sections/mutators are registered into this pipeline. Must be called before init() for plugins to contribute sections

func (*Framework) Start

func (f *Framework) Start(ctx context.Context) error

Start starts all plugin services and fires the ServerStart hook.

func (*Framework) Stop

func (f *Framework) Stop(ctx context.Context) error

Stop stops all plugin services and fires the ServerStop hook.

type Handle

type Handle interface {
	// RuntimeAPI returns the framework's runtime API.
	// This is used to access services, tools, and other plugins.
	RuntimeAPI() RuntimeAPI
}

Handle is the interface that plugins use to access the framework's runtime API. It is passed to the PluginFactory during plugin instantiation.

type HookEvent

type HookEvent string

HookEvent identifies a lifecycle event that plugins can subscribe to. This corresponds to OpenClaw's typed lifecycle hooks (on()).

const (
	// HookServerStart is fired when the hivemind server starts.
	HookServerStart HookEvent = "server_start"

	// HookServerStop is fired during graceful shutdown.
	HookServerStop HookEvent = "server_stop"

	// HookBeforeAgentStart is fired before an Agent session begins.
	// Plugins can inject context (e.g., memory recall) here.
	HookBeforeAgentStart HookEvent = "before_agent_start"

	// HookAgentEnd is fired after an Agent session ends.
	// Plugins can capture/persist data (e.g., memory flush) here.
	HookAgentEnd HookEvent = "agent_end"

	// HookBeforeGenerate is fired before LLM generation.
	HookBeforeGenerate HookEvent = "before_generate"

	// HookAfterGenerate is fired after LLM generation completes.
	HookAfterGenerate HookEvent = "after_generate"

	// HookBeforeCompaction is fired before compaction is about to run.
	// Plugin can perform pre-compaction actions (e.g., LLM-driven memory flush.)
	// Data: {"agent", "session", "window_info", "chat_model"}
	HookBeforeCompaction HookEvent = "before_compaction"

	// HookAfterCompaction is fired after compaction completes successfully.
	// Plugins can perform post-compaction actions (e.g., workspace context refresh.)
	// Data: {"agent", "session", "summary", "compaction_count"}
	HookAfterCompaction HookEvent = "after_compaction"
)

type HookHandler

type HookHandler func(ctx context.Context, data interface{}) error

HookHandler is the callback function for lifecycle hooks. The data parameter is event-specific; plugins should type-assert as needed.

type HookProvider

type HookProvider interface {
	Plugin
	// Hooks returns a mapping of events to handlers.
	Hooks() map[HookEvent]HookHandler
}

HookProvider is an optional plugin interface for plugins that want to register hooks declaratively. The framework probes for this interface and auto-registers the hooks.

type InTreeRegistry

type InTreeRegistry struct {
	// contains filtered or unexported fields
}

InTreeRegistry is a pre-configured set of built-in plugin factories. This mirrors K8s scheduler's in-tree plugin registration pattern, where all default plugins are registered in a single function.

Out-of-tree plugins can be added via Framework.RegisterFactory() directly.

func NewInTreeRegistry

func NewInTreeRegistry() *InTreeRegistry

NewInTreeRegistry creates a new in-tree plugin registry.

func (*InTreeRegistry) ApplyTo

func (r *InTreeRegistry) ApplyTo(f *Framework) error

ApplyTo registers all in-tree plugin factories into the given Framework.

func (*InTreeRegistry) Len

func (r *InTreeRegistry) Len() int

Len returns the number of registered factories.

func (*InTreeRegistry) Register

func (r *InTreeRegistry) Register(def Definition, factory PluginFactory, args PluginArgs)

Register adds a plugin factory to the in-tree registry.

type InitPlugin

type InitPlugin interface {
	Plugin

	// Init is called after the plugin is instantiated, allowing it
	// to register Tool/Cli/Hook/Service capabilities via the PluginAPI.
	Init(api PluginAPI) error
}

InitPlugin is an optional interface for plugins that need initialization with access to the pluginAPI, called during framework setup

type LifecyclePlugin

type LifecyclePlugin interface {
	Plugin

	// Start is called when the framework is initializing,
	// after all plugins have been registered.
	Start(ctx context.Context) error

	// Stop is called when the framework is shutting down,
	// before plugins are unregistered.
	Stop(ctx context.Context) error
}

LifecyclePlugin is an optional interface for plugins that have start/stop lifecycle

type ModelManager

type ModelManager interface {
	// GetChatModel returns a chat model by provider ID and model ID.
	// Return nil if the model is not found.
	GetChatModel(ctx context.Context, provideID, modelID string) (model.BaseChatModel, error)

	// GetDefaultChatModel returns the default chat model for the current runtime.
	// Return nil if the default model is not set.
	GetDefaultChatModel(ctx context.Context) (model.BaseChatModel, error)
}

ModelManager is a plugin-facing subset of the LLM ModelManager interface. It exposes only the capabilities that plugins need, decoupling the plugin package from the full llm/domain/service.ModelManager.

type ParameterDef

type ParameterDef struct {
	// Name is the parameter's unique name. (e.g. "query")
	Name string
	// Type is the parameter's data type. (e.g. "string", "number", "object")
	Type string
	// Description is a brief description of the parameter's purpose.
	Description string
	// Required indicates whether the parameter is mandatory.
	Required bool
}

ParameterDef defines a single parameter for a tool.

type Plugin

type Plugin interface {
	// Name returns the unique identifier of this plugin.
	// Must be DNS-compatible (lowercase, hyphens, no spaces).
	Name() string
}

Plugin is the fundamental interface that all plugins must implement. Each Plugin has a static definition and registers its capabilities via the PluginAPI during the Register phase

type PluginAPI

type PluginAPI interface {
	// RegisterTool registers an Agent-callable tool.
	RegisterTool(tool ToolDefinition)

	// RegisterCLI registers a CLI subcommand registrar.
	RegisterCLI(registrar CLIRegistrar)

	// RegisterHook registers a lifecycle event hook.
	RegisterHook(event HookEvent, handler HookHandler)

	// RegisterService registers a background service with Start/Stop lifecycle.
	RegisterService(svc ServiceDefinition)
}

PluginAPI is the registration interface given to plugins during Init(). Through this API, plugins register their capabilities: Tool, CLI, Hook, Service.

This corresponds to OpenClaw's OpenClawPluginApi with registerTool(), registerCli(), registerHook/on(), registerService().

type PluginArgs

type PluginArgs map[string]interface{}

PluginArgs is a map of arguments passed to the PluginFactory. These arguments are typically configuration values or dependencies.

type PluginFactory

type PluginFactory func(args PluginArgs, handle Handle) (Plugin, error)

PluginFactory is a function that creates a new instance of a plugin. It is called during framework initialization, after all plugins have been registered.

type PromptMutatorProvider

type PromptMutatorProvider interface {
	Plugin

	// PromptMutators returns the PromptMutators contributed by this plugin.
	// These are registered into the shared Pipeline during framework init.
	PromptMutators() []prompt.PromptMutator
}

PromptMutatorProvider is an optional plugin interface for plugins that want to contribute PromptMutators to the system prompt pipeline.

PromptMutators returns the PromptMutators contributed by this plugin. These are registered into the shared Pipeline during framework init.

type PromptProvider

type PromptProvider interface {
	Plugin

	// PromptSections returns the PromptSections contributed by this plugin.
	// These are registered into the shared Pipeline during framework init.
	PromptSections() []prompt.PromptSection
}

PromptProvider is an optional plugin interface for plugins that want to contribute PromptSections and/or PromptMutators to the system prompt pipeline.

This is the fifth capability injection channel, alongside:

  • ToolProvider (tools for Agent to call)
  • HookProvider (lifecycle hooks)
  • ServiceProvider (background services)
  • CLIProvider (CLI commands)

The framework probes for this interface during Init() and auto-registers sections/mutators into the shared PromptPipeline.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is the central plugin registry that holds all loaded plugins and their registered capabilities (tools, CLI, hooks, services).

This follows K8s scheduler's frameworkImpl pattern: the framework maintains ordered lists of plugins per extension point.

Thread-safe: all mutations are guarded by a mutex.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty plugin registry.

func (*Registry) GetHooks

func (r *Registry) GetHooks(event HookEvent) []HookHandler

GetHooks returns all handlers registered for the given event.

func (*Registry) GetPlugin

func (r *Registry) GetPlugin(name string) (Plugin, bool)

GetPlugin returns a loaded plugin by name.

func (*Registry) GetServices

func (r *Registry) GetServices() []ServiceDefinition

GetServices returns all registered background services.

func (*Registry) GetTools

func (r *Registry) GetTools() map[string]ToolDefinition

GetTools returns all registered tools.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of loaded plugins.

func (*Registry) PluginNames

func (r *Registry) PluginNames() []string

PluginNames returns the names of all loaded plugins in registration order.

func (*Registry) RegisterCLICommands

func (r *Registry) RegisterCLICommands(parent *cobra.Command)

RegisterCLICommands registers all plugin-provided CLI subcommands into the given cobra parent command.

type RuntimeAPI

type RuntimeAPI interface {
	// ModelManager returns the LLM model manager for building/retrieving chat models.
	// Return nil if the LLM module is not available.
	ModelManager() ModelManager
}

RuntimeAPI is the bridge between plugins and core runtime modules. Plugins access core capabilities (LLM, Memory, etc.) through this interface.

func NewRuntimeAPI

func NewRuntimeAPI(modelManager ModelManager) RuntimeAPI

NewRuntimeAPI creates a RuntimeAPI with the given ModelManager. modelManager may be nil if the LLM module is not available.

type ServiceDefinition

type ServiceDefinition struct {
	// Name is the service's unique name.
	Name string

	// Start launches the service. It should be non-blocking
	Start func(ctx context.Context) error
	// Stop gracefully shuts down the service. It should be non-blocking.
	Stop func(ctx context.Context) error
}

ServiceDefinition describes a background service registered by a plugin. Service have a Start/Stop lifecycle managed by the framework.

type ServiceProvider

type ServiceProvider interface {
	Plugin
	// Services returns the list of background services provided by the plugin.
	Services() []ServiceDefinition
}

ServiceProvider is an optional plugin interface that allows plugins to register background services. The framework probes for this interface when loading plugins.

type SlotConfig

type SlotConfig map[string]string

SlotConfig maps slot kind → desired plugin name. For example: {"memory": "memory-core"} means only the "memory-core" plugin should be active for the "memory" slot.

Special values:

  • "none": disable all plugins of this kind
  • "": use the default plugin for this kind

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status indicates the result of running a plugin operation. This is modeled after K8s scheduler framework's Status type.

func NewStatus

func NewStatus(code Code, reasons ...string) *Status

NewStatus creates a new Status with the given code and reasons.

func NewStatusWithError

func NewStatusWithError(err error) *Status

NewStatusWithError creates an error Status from an error.

func (*Status) AsError

func (s *Status) AsError() error

AsError converts any non-success status to an error.

func (*Status) Code

func (s *Status) Code() Code

Code returns the status code.

func (*Status) Err

func (s *Status) Err() error

Err returns the underlying error, if any.

func (*Status) IsSuccess

func (s *Status) IsSuccess() bool

IsSuccess returns true if the status code is Success.

func (*Status) Message

func (s *Status) Message() string

Message returns a concatenated message from all reasons.

func (*Status) WithPlugin

func (s *Status) WithPlugin(name string) *Status

WithPlugin sets the plugin name on the status (for diagnostics).

type ToolDefinition

type ToolDefinition struct {
	// Name is the tool's unique name. (e.g. "memory_search")
	Name string
	// Description is a brief description of the tool's purpose.
	Description string
	// Parameters defines the input schema for the tool.
	Parameters []ParameterDef
	// Handler is the function that is called when the tool is invoked.
	Handler ToolHandler
}

ToolDefinition describes a tool registered by a plugin. Tools have a single Handler function that is called when the tool is invoked. Tools are invoked by the Agent to perform actions.

type ToolHandler

type ToolHandler func(ctx context.Context, params map[string]interface{}) (interface{}, error)

ToolHandler is the function that is called when the tool is invoked. It receives the context and a map of parameter values, and returns the result or an error.

type ToolProvider

type ToolProvider interface {
	Plugin
	// Tools returns the Tools contributed by this plugin.
	// These are registered into the shared ToolRegistry during framework init.
	Tools() []ToolDefinition
}

ToolProvider is an optional plugin interface for plugins that want to contribute Tools to the system.

Tools are invoked by the Agent to perform actions.

Tools are registered into the shared ToolRegistry during framework init.

Directories

Path Synopsis
Package builtin registers all in-tree (built-in) plugins.
Package builtin registers all in-tree (built-in) plugins.
diagnostics
Package diagnostics implements the "diagnostics" built-in plugin.
Package diagnostics implements the "diagnostics" built-in plugin.
diagnostics/trace
Package trace provides LLM-aware distributed tracing for Echoryn.
Package trace provides LLM-aware distributed tracing for Echoryn.
golem-cluster
Package golem_cluster provides the golem-cluster plugin for Hivemind.
Package golem_cluster provides the golem-cluster plugin for Hivemind.
llmtask
Package llmtask implements the "llm-task" built-in plugin.
Package llmtask implements the "llm-task" built-in plugin.
llmtask/entity
Package entity defines configuration and types for the llm-task plugin.
Package entity defines configuration and types for the llm-task plugin.
skills
Package skills provides the skills built-in plugin for Hivemind.
Package skills provides the skills built-in plugin for Hivemind.
web-search/gemini-web-search
Package gemini_websearch implements the "web-search" built-in plugin.
Package gemini_websearch implements the "web-search" built-in plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL