Skip to contents

A named, versioned set of hooks: functions FunctAI calls at fixed points of a call or a conversation's turn. Each is given an event and returns an ai_change() (or NULL: no opinion), and every change is recorded in the call's record, so a rated call is asked again as it was.

Usage

ai_plugin(name, version = "0.0.0", ..., description = "", api = 1L)

on_hook(plugin, hook, handler)

Arguments

name

Lower-case letters, digits, _ and -, starting with a letter: its changes and entries are named by it.

version

Its own version, recorded with each change.

...

Handlers by hook: before_call = function(call) ....

description

What it does.

api

The plugin API it was written for (1).

plugin

A plugin.

hook

A hook's name.

handler

A function of one event.

Value

A plugin.

Details

hookwhenit may change
turn_starta conversation's turn is sent, before it is recordedinputs
contextthe turn's earlier turns are chosenkeep, without, sections
before_callan AI function is about to be asked (a program's steps too)instruction, sections, lm, settings, tools
requesta provider request is about to be sentreturns another lm15 request
tool_calla tool is about to runinputs, block; or ai_ask() a person
tool_resulta tool ranoutput
turn_enda turn ended (hears only; may keep_entry() entries)

Plugins are set as settings: an AI function's or a program's own (.plugins), a conversation's, a block's (with_ai_config(plugins = )), or the session's (ai_config(plugins = )). The program's own run first, then each layer out to the session's, so the host's handlers see what the program's did and have the last word. A host's program_plugins = FALSE drops the program's own. A handler runs in the call's own R session, with all its power: a plugin is code you trust.

Examples

careful <- ai_plugin("careful", version = "1.0.0",
  before_call = function(call) ai_change(sections = "Only point out problems."),
  tool_call = function(t) if (t$name == "delete_file") ai_change(block = "not here"))
careful
#> <ai plugin> careful 1.0.0: before_call, tool_call