Plugin¶
Plugin(name, *, version='0.0.0', api=API, description='')
A named, versioned set of hooks.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
| name | str | Lower-case letters, digits, _ and -: how its changes and entries are named in records. |
required |
| version | str | Its own version, recorded with every change it makes. | '0.0.0' |
| api | int | The plugin API it was written for (1). A version this FunctAI does not implement refuses plugin-api. |
API |
| Hooks | required |
Examples¶
import functai
from functai import *
guard = functai.Plugin("no-deletes", version="1.0.0")
@guard.tool_call
def refuse_deletes(tool):
if tool.name == "delete_file":
return functai.Change(block="deleting files is not allowed here")
functai.configure(plugins=[guard])
configure(plugins=(<Plugin no-deletes 1.0.0: tool_call>,))
Methods¶
| Name | Description |
|---|---|
| before_call | An AI function is about to be asked: sections, model, settings, tools. |
| context | Which earlier turns a turn is shown, and sections about them. |
| describe | Its manifest, as data: name, version, api, the hooks it uses. |
| on | Register fn for hook (as a decorator when fn is left out). |
| request | The escape hatch: rewrite the provider request (the call is then not replayable). |
| tool_call | A tool is about to run: change its input, block it, or ask a person. |
| tool_result | A tool ran: change what the model is shown. |
| turn_end | A turn ended (hears only; may keep entries in its conversation). |
| turn_start | A turn is about to be recorded: may replace its inputs. |
before_call¶
Plugin.before_call(fn)
An AI function is about to be asked: sections, model, settings, tools.
context¶
Plugin.context(fn)
Which earlier turns a turn is shown, and sections about them.
describe¶
Plugin.describe()
Its manifest, as data: name, version, api, the hooks it uses.
on¶
Plugin.on(hook, fn=None)
Register fn for hook (as a decorator when fn is left out).
request¶
Plugin.request(fn)
The escape hatch: rewrite the provider request (the call is then not replayable).
tool_call¶
Plugin.tool_call(fn)
A tool is about to run: change its input, block it, or ask a person.
tool_result¶
Plugin.tool_result(fn)
A tool ran: change what the model is shown.
turn_end¶
Plugin.turn_end(fn)
A turn ended (hears only; may keep entries in its conversation).
turn_start¶
Plugin.turn_start(fn)
A turn is about to be recorded: may replace its inputs.