Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 2.88 KB

PLUGINS.md

File metadata and controls

59 lines (44 loc) · 2.88 KB

Plugins

PersonaKit has three extension points. Two replace a scoring function; the third may narrow a read to fewer memories. None can do anything else.

Hook Signature Built-in Used by
relevance (question: str, memories: Sequence[Memory]) -> Sequence[float] word overlap (text, category and the owner's hints) personakit serve (which memories answer a question, and in what order; when the assistant states a context it is called a second time with that text, and each memory keeps its higher score)
similarity (a: str, b: str) -> float between 0 and 1 shared words, with number, negation and order guards personakit tidy (which memories are twins)
select (question: str, context: str, memories: Sequence[Memory], client: str) -> Sequence[Memory] | None none (off) personakit serve, once per read, after the read policy: it sees only the relevant memories that may be served, best first, and the name the assistant connected with ("" when unknown). It returns the ones to serve, or None to leave the read as it is

What a plugin cannot do

Policy stays in the core, whatever a plugin returns:

  • Restricted and archived memories are never served. A relevance score only orders what the read policy already allows, and select never sees them.
  • select can only narrow. A memory it returns that it was not offered is ignored, the order of what is served stays the core's, and the limit still applies.
  • Only unconfirmed memories with the same category and scope, none resting on an assistant's proposal, can be proposed as twins, and only when they mention the same numbers and agree on negation. Merging still needs personakit tidy --apply and is reversible.
  • No hook can approve, restrict, archive, restore or forget.

A plugin is still Python code running as you, with access to your store file. Enable only plugins you trust and have read.

Enabling one

Nothing is loaded just because it is installed. Name the plugins you want:

pip install some-personakit-plugin
export PERSONAKIT_PLUGINS=some-name        # comma separated for several, applied in order
personakit tidy

A name that is not installed is an error, not a silent fallback.

Writing one

Register a function in the personakit.plugins entry-point group. It receives a Hooks object and replaces what it provides:

# pyproject.toml of the plugin
[project.entry-points."personakit.plugins"]
some-name = "some_package:register"
# some_package/__init__.py
def register(hooks):
    hooks.similarity = my_similarity      # leave hooks.relevance alone to keep the built-in

For anything beyond scoring, use PersonaKit as a library: personakit.store.Store is the one place that reads and writes the database, and Store.merge, Store.undo_merge, Store.set_state and Store.restore are the same reversible operations the CLI uses.