Proposal: Extensible hooks and plugin support#414
Proposal: Extensible hooks and plugin support#414araujof wants to merge 10 commits intogenerative-computing:mainfrom
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 Enforce conventional commitThis rule is failing.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
5f5adeb to
0aee2a0
Compare
|
@nrfulton I added an implementation plan document to detail the relevant components of the ContextForge Plugin Framework and required changes to Mellea to introduce the hook system. |
|
@jakelorocco @HendrikStrobelt I updated the hook system specification and implementation plan with functional-first, programmatic API as per our recent discussions. |
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
…esign drifts Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
…onal suggestions by maintainers Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
70ab0c1 to
2ef5ebf
Compare
Added implementation priorities to Hook Table.
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
|
|
A more general question - mellea is trying to be a lightweight library. ContextForge is only required if this hook/plugin support is being used - so in the no-hook case we can stay light. However the value from the hook approach - as explained in the proposal is huge! It brings many options. I can see how it could quickly become useful in many/most deployments of mellea. With that in mind I'm concerned about the 'weight' of the dependency. (we have lots here coming from contextforge - fastapi, uvicorn, backend (albeit optional), alembic, argon2 etc) Would it be possible to suggest some refactoring of ContextForge to make it easier to use only the core pieces required for this plugin support? |
Summary
Introduces a design specification for an extensible hook system and plugin framework for Mellea. The hook system provides extension points across the framework's execution lifecycle — from session initialization through component execution, LLM generation, validation, sampling, and cleanup — enabling policy enforcement, observability, customization, and integrations without modifying core library code.
Specification Outline
on_<hook_name>), programmatic registration, or YAML configuration.Specification document
Implementation Plan
The implementation plan defines how Mellea's extensibility hook system will be built on top of the ContextForge plugin framework as an optional dependency. The primary developer API uses
@hookand@plugindecorators plus aregister()function for programmatic registration, with YAML configuration supported as a secondary deployment-time mechanism. Plugins can be scoped globally or per-session (viastart_session(plugins=[...])), and aPluginSetclass enables composable grouping. The centralinvoke_hook()dispatcher includes three layers of zero-overhead guards (_plugins_enabledflag,has_hooks_for()check, and early return) to ensure no performance impact when plugins are not configured. Hook call sites are added acrossfunctional.py,session.py,sampling/base.py,backend.py,context.py, and the OpenAI/HuggingFace adapter backends, with agenerate_from_context_with_hooks()wrapper on the Backend ABC to avoid modifying individual backendimplementations.
Implementation plan
Review plan