extensions/

Add commands, schedules and pieces of the web page to the chat and the served agent, as one file or a folder, with settings.

On this page

extensions/

An extension adds to BxAgents without changing it: chat commands (/deploy, /roll 2d6), listeners for the events of the chat and of bx-ai, schedules that run when the agent is served, and pieces of the web page. It is a class that looks and behaves like a ColdBox ModuleConfig: it has a configure(), an onLoad() and an onUnload(), its settings come from Agent.yml, and things are handed to it with $inject.

One file is a whole extension:

extensions/
  hello.bx             /hello
  roll.bx              /roll, /coin
  standup/             a folder is an extension too
    Extension.bx
    commands/Standup.bx
    schedulers/Reminder.bx

A working project with all of these is examples/extensions-agent.

The smallest extension

extensions/hello.bx. The file name is the extension's name.

class {

	function configure() {
		variables.settings = { greeting : "Hello" }
	}

	@Command( "hello" )
	@Hint( "say hello: /hello <name>" )
	function greet( agentContext, commandArguments ) {
		return agentContext.reply().ok( "#settings.greeting#, #commandArguments#!" )
	}

}

Run bxAgents chat and type /hello Ada. /extensions lists what is loaded.

A command method is called with the agentContext (the conversation and nothing else; the same object the built-in commands get) and the text after the command name. It returns a Reply or just a string. If it throws, the person sees a warning that names the extension and the chat carries on.

The Reply API

Build a reply by chaining methods on agentContext.reply(). Every method returns the reply, so they chain. The terminal, the web page and the gateways each draw the blocks their own way.

Single-style blocks β€” the whole block is one color:

MethodWhat it draws
.text( s )Muted gray text (the default)
.text( s, "accent" )Teal accent text
.ok( s )Green text (success)
.warn( s )Amber text (warning)
.header( s )Accent header for a section
.line( s )A printed line; .line() with no argument is a blank line
.blank()A blank line (alias for .line())

Mixed-style lines β€” different colors within one line. Start with .styled(), chain segment methods, then .print() to commit the line:

agentContext.reply()
    .styled()
        .accentBold( "/deploy" )
        .text( "  " )
        .muted( "ship it to production" )
        .print()

Segment methods: .text( s ) (plain), .muted( s ) (gray), .accent( s ) (teal), .accentBold( s ) (bold teal), .ok( s ) (green), .warn( s ) (amber), .error( s ) (red), .bold( s ) (bold). For a style chosen at runtime: .segment( s, styleName ).

Dynamic compound styles work too, like CommandBox's print helper β€” combine foreground, background and modifiers in the method name:

.styled().boldRedOnBlue( "CRITICAL" ).text( "  " ).muted( "disk full" ).print()

Recognized tokens: foreground (accent, ok, muted, warn, error, plain, black, red, green, yellow, blue, magenta, cyan, white, gray), background (onBlack through onWhite), modifiers (bold, dim, italic, underlined, blink, reversed, hidden, crossedout).

Convenience methods β€” shortcuts for common patterns, each produces a mixed-style line:

MethodWhat it draws
.commandLine( name, hint )Bold teal name + gray hint (for /help-style lists)
.labelValue( label, value )Gray label + teal value (for /info-style facts)
.statusLine( label, boolean )Gray label + green "on" or red "off"
.indent( text )Indented gray text (like CommandBox's indentedLine)
.bullet( text )Teal dot + gray text
.divider()A horizontal rule

Structured blocks:

MethodWhat it draws
.keyValues( rows )Label-value pairs; rows is [ [ label, value ], ... ]
.grid( columns, rows )A table; columns is [ { width, align }, ... ]
.choose( title, options )Buttons to pick from; options is [ { label, hint, line }, ... ]
.transcript( messages )Conversation messages; messages is [ { role, text }, ... ]
.file( name, mime, text )A file for the client to save or download
.screen( name )Opens a terminal-only screen (e.g. "notes", "vault")

Effects β€” things the caller does to its own state:

MethodWhat it does
.reset()Clears the conversation from the screen
.conversation( id, title )Switches to another conversation
.quit()Leaves the chat

All methods return the reply, so they chain:

return agentContext.reply()
    .header( "Deploy status" )
    .statusLine( "Connected", true )
    .labelValue( "Target", "production" )
    .styled().ok( "3 services" ).muted( " running" ).print()
    .blank()
    .indent( "Type /deploy run to start." )

Annotations

Annotations are normal BoxLang annotations on a method. Each one can be written four ways, and every BxAgents annotation takes all four:

WrittenMeansExample
baredefaults; the name comes from the method@Command on function roll() is /roll
simplethe main value@Command( "deploy" )
arrayseveral@Alias( [ "dice", "d" ] )
structevery option@Command( { name : "deploy", hint : "plan it", admin : true, aliases : [ "ship" ], transports : [ "tui", "web" ] } )

Shorthand annotations say one option each: @Hint( "..." ), @Admin, @Alias( ... ), @Transports( [ "tui", "web" ] ). A struct option wins over a shorthand, and the clash is shown in /extensions. Annotation names ignore case.

transports are where the command runs: tui (the terminal chat), web (the web page and the HTTP command route) and gateway (chat platforms). The default is all three. A chat platform only answers the commands its gateway allows (gatewaySession.commands.allow), and a command with @Admin only runs for the people listed as admins there.

Settings

The extension says its defaults in configure(), as a module does:

function configure() {
	variables.settings = { target : "staging", environments : [ "staging", "production" ] }
}

The people who use it change them under the extension's name in Agent.yml:

extensions:
  deploy:
    target: production

A person can set their own values in ~/.bxagents/Agent.yml (same extensions: block); their values win over the project's, because the person who runs the agent has the last word (see layered settings). Nested structs merge key by key, arrays and simple values replace. In the extension, settings is the merged struct.

Lifecycle

MethodWhen
configure()once, first. Sets variables.settings. No work here
onLoad()after the settings are merged and everything is injected. Open connections, start timers
onUnload()when the chat or the server ends. Release them

this.title, this.author, this.webURL, this.description, this.version and this.enabled are read as in a module config, and this.dependencies = [ "other-extension" ] loads that extension first. An extension that throws while it loads is shown as failed in /extensions with the reason; the others still load.

Injection

Every class of an extension has $inject( name, object )`. It puts the object in both the `this` and the `variables` scopes. For private only: `$inject( name, object, "variables" ). $read( name ) reads a variables entry from outside.

BxAgents injects two things before onLoad(): settings and log (log.info( "..." ), .warn(), .error(); what an extension logs is also in /extensions). To share an object between the files of an extension, create it in onLoad() and $inject it where it is needed. The same call is how a test hands an extension a fake.

A folder extension

A folder has the same shape as an agent project:

extensions/standup/
  Extension.bx        required: it is what makes the folder an extension (the module config: properties, configure(), onLoad(), onUnload())
  commands/           one class per command, like the built-in ones
  schedulers/         BoxLang scheduler classes, started when the agent is served
  web/                styles, scripts and other files for the web page (see below)

A class in commands/ extends models.chat.commands.BaseCommand@bxagents and says its name(), hint(), transports() and run( context, args ). settings and log are injected into it.

Schedulers

A class in schedulers/ is a BoxLang scheduler: a class with a configure() that defines tasks through the scheduler property BoxLang gives it, like any other BoxLang scheduler. When the agent is served (bxAgents serve, a .bxa, a deployed server) it starts in the runtime's scheduler service. Like every class of an extension it is given settings (the defaults with the values from Agent.yml) and log before configure() runs:

class {

	function configure() {
		scheduler.task( "standup-reminder" )
			.call( () => log.info( "Standup time for #settings.channel#" ) )
			.everyDayAt( settings.at )
			.withNoOverlaps()
	}

}

The BoxLang scheduler lifecycle methods (onStartup(), onShutdown(), onAnyTaskError() and the rest) work as usual. Each scheduler is registered as extension-<extension>-<scheduler>, and a scheduler that fails to start is reported on its extension in /extensions while the others still run. The terminal chat does not start schedulers: they belong to the served agent.

Listening to events

An extension is also an interceptor. A method named after an event listens to it, exactly like a BoxLang or ColdBox interceptor:

class {

	function onChatInput( data ) {
		if ( data.text contains "password" ) {
			data.cancel( "That looks like a password, so it was not sent." )
		}
	}

	function onAIError( data ) {
		log.warn( "the model failed" )
	}

}

Two things can be listened to:

  • bx-ai events (beforeAIAgentRun, afterAIModelInvoke, onAIError, beforeAIToolExecute and the rest). They fire wherever the agent runs.
  • Chat events, announced by BxAgents:
EventWhendata hasA listener can
onChatSessionStart / onChatSessionEndthe terminal chat opens or closesagent, transport
onChatInputbefore a message is senttext, transportcancel( reason ), or replace( newText )
onChatTurnStart / onChatTurnEndaround one turn of the agenttext, transport (reply, status at the end)
onChatConversationChange/new, /resume, /clear, /fork or /compact changed the conversationline, transport
onChatCommandBeforebefore any command, on every transportline, name, arguments, transportcancel( reason )
onChatCommandAfterafter any command, on every transportline, name, reply, transportreplace( newReply )

The session, input, turn and conversation events are the terminal chat's; the two command events fire in the terminal, the web page and on chat platforms alike. A listener that throws is caught: it can never stop a turn, the listeners after it still run, and the error is shown in /extensions.

@On binds a method with another name, or many events at once, and takes the four forms an annotation takes:

@On( [ "beforeAIToolExecute", "afterAIToolExecute" ] )
function toolCalled( data ) { log.info( "a tool ran" ) }

@On naming an event the runtime does not know is reported in /extensions, not ignored.

interceptors and customInterceptionPoints

As in a module config, configure() can name classes from the extension's folder to register, each with its own properties, and points of its own to announce:

function configure() {
	variables.interceptors = [ { class : "interceptors.Audit", properties : { level : "info" } } ]
	variables.customInterceptionPoints = [ "onAuditRecorded" ]
}

interceptors/Audit.bx listens with methods named after events and has settings, log and properties injected. Any extension can then listen to onAuditRecorded, and the one that owns it announces it with BoxAnnounce( "onAuditRecorded", { ... } ). extensions.disable takes extension:method to turn one listener off.

ColdBox events (preProcess, postProcess and the rest) are not part of the terminal chat; they fire only in a served agent.

Keys and status

@Key binds keys in the terminal chat to a method. On a command method it runs that command, with the same rules and events as typing it; on any other method it calls the method with the agentContext and an empty text and shows what it returns. @Hint (or hint in the struct form) says what it does.

@Command
@Hint( "count a pulse" )
@Key( "ctrl+g" )
function pulse( agentContext, commandArguments ) { ... }

@Key( { keys : [ "ctrl+y", "alt+y" ], hint : "reset the count" } )
function resetPulse( agentContext, commandArguments ) { ... }

A key is named extension:method (pulse:pulse). /keys lists it with the built-in ones, and a person can give it other keys under chat: keys: in ~/.bxagents/Agent.yml. A key a built-in action already uses, or an earlier extension holds, is refused with a sentence that says so. A typed draft stays in the box while a key runs. Keys are for the terminal chat; the web page and chat platforms have commands.

@Status is a piece of status next to the size of the context: a method that returns a short text, asked each time the box is drawn in the terminal and after each change to the conversation on the web page (chips in the bar above the conversation, see Status items). Return an empty string to show nothing. It must be quick; one that throws is left out and the reason is put on its extension once.

@Status
function beats( agentContext ) {
	return variables.beats > 0 ? "beat #variables.beats#" : ""
}

extensions.disable takes extension:method for a key or a status item too.

register( registry )

What annotations cannot say, because it is worked out in code, is said as calls. If the class has a register( registry ) method it is called once, right after configure():

function register( registry ) {
	registry.command( "deploy", { run : ( agentContext, commandArguments ) => ..., hint : "ship it", admin : true, aliases : [ "ship" ] } )
	registry.key( "ctrl+d", "/deploy", { hint : "ship it" } )                    // a key that runs a command line
	registry.key( "ctrl+o", ( agentContext ) => "opened", { name : "open", hint : "open it" } )   // or any function
	registry.status( "branch", ( agentContext ) => "main" )
	registry.on( "onChatCommandAfter", ( data ) => ... )                         // an event, or an array of them
}

Prefixes and @ sources

Both are for the terminal chat only.

@Prefix claims the start of a line in the message box. The method gets the agentContext and the text after the prefix. It answers one of two ways: a Reply (or a string) is shown and nothing is sent, and { send : "text" } is sent to the agent as the message, after onChatInput has seen it.

@Prefix( "%" )
@Hint( "ask for an explanation: % why is the sky blue" )
function explain( agentContext, text ) {
	return { send : "Explain this in one short paragraph: #text#" }
}

@Prefix( "=" )
function count( agentContext, text ) {
	return agentContext.reply().ok( "#text.listToArray( ' ' ).len()# words" )
}

/, !, # and @ are the chat's own, and a lone ? asks for the keys; a prefix that starts with one of them, is empty or has a space is refused with a sentence. The longest prefix wins. Two extensions on one prefix are a warning and the later layer wins.

@Source( "ticket" ) brings content along with a message the way @path brings a file. Write @ticket:TCK-1 (or @ticket:"two words") and the method is called with the agentContext and the query. It returns { name, content }, an array of them or a string; the content goes with the message and the mention stays in it. @Suggest( "ticket" ) on another method is optional: it returns the values the menu offers as the person types after the colon. It is asked on keystrokes, so it must be quick; one that throws gives no suggestions and the reason is put on its extension once. A source name can be anything that starts with a letter, since files are plain @path.

@Source( "ticket" )
function ticket( agentContext, query ) { return { name : "ticket #query#", content : tickets[ query ] } }

@Suggest( "ticket" )
function ticketNames( agentContext, query ) { return tickets.keyArray() }

Written as calls: registry.prefix( "%", ( agentContext, text ) => ..., { hint : "..." } ) and registry.source( "ticket", ( agentContext, query ) => ..., { hint : "...", suggest : ( agentContext, query ) => [ ... ] } ).

The person chooses the prefix or the name, by the id extension:method, in ~/.bxagents/Agent.yml:

chat:
  prefixes:
    desk:explain: "?%"
  sources:
    desk:ticket: issue

A choice that cannot be used is reported and the extension's own is kept. extensions.disable takes extension:method for these too.

Asking the person

A command, key or prefix can put a question to the person while it runs:

var title    = agentContext.ask( "Title of the ticket?", { default : commandArguments, help : "A short sentence." } )
var priority = agentContext.choose( "Priority?", [ "low", "normal", { value : "high", label : "high", hint : "someone is blocked" } ] )
if ( agentContext.confirm( "Make the #priority# ticket?" ) ) { ... }

ask() returns the text, choose() returns the value picked, and confirm() is true only for a yes. Esc gives null (false for confirm()). Questions work in the terminal chat only. Where nobody can answer (the web page, chat platforms, a server) they answer at once with null (false) instead of waiting, and agentContext.canAsk() tells you beforehand so a command can say so.

Reloading

/reload loads the extensions again without leaving the chat: it runs onUnload() of what was loaded, reads ~/.bxagents/Agent.yml and the extensions: settings of Agent.yml anew, and loads what is found, with its commands, keys, status items, prefixes, sources and listeners. An extension that fails to load is reported and left out; the others load. It is for admins and works in the terminal chat only: a served app registers schedulers and ColdBox listeners when it starts, so restart it instead.

The web page: slots and web/

An extension can add to the web app four ways: slots (a string the server draws in a place of the Chat page), status items (chips above the conversation), commands (in the page's / menu), and files in web/ (styles and scripts linked into every page). The terminal chat has no page, so slots and web/ files are ignored there.

Slots

A slot puts a string in a named place of the Chat page. The method is called with the agentContext and returns the string:

PlaceWhere on the Chat page
headerthe bar above the conversation, after the context size and the status chips
sidebarunder the list of conversations
composerin the message box, before the Attach button
@Slot( "header" )
function badge( agentContext ) { return variables.pings > 0 ? "#variables.pings# pings" : "" }

@Slot( { place : "sidebar", html : true } )
function about( agentContext ) { return "<strong>Panel</strong><br>Use the Ping button." }

An empty string shows nothing. A place other than these three is refused when the extension loads. Written as a call: registry.slot( "header", ( agentContext ) => "...", { html : false, name : "badge" } ). extensions.disable takes extension:method for a slot.

Text or markup. The string is shown as text (textContent): <b> shows as <b>. Only a slot that says html : true has its string put into the page as markup (innerHTML). That is the author saying the markup is their own. The page does not clean it, so it must never carry what a visitor typed, a model wrote or a service sent: pass any such value through encodeForHTML(). The slot places are outside Alpine (x-ignore), so x-, : and @ attributes in a slot do nothing; behaviour belongs in a script of web/.

When it is drawn. The page asks for every slot in one request, GET /__bxagents/slots?conversationId= (the agent API's path, which agentApi.path can move), behind the same sign-in or token as the rest of the API. It asks when the Chat page opens and after each turn, command and change of conversation, at the same moments it reads the context size. Each draw replaces what the server drew before and leaves what a script added alone. A slot that throws is left out and the reason is put on its extension once. When no extension has a slot, GET /agent says capabilities.slots: false and the page does not ask.

Status items

@Status (see Keys and status) is shown on the web page too: a chip for each item, in the bar above the conversation, read from GET /__bxagents/status?conversationId= at the same moments as the slots. An empty string shows no chip.

Commands

A @Command whose transports include web (the default) is offered on the Chat page: in the menu that / opens and behind the lightning button, with the extension's name as a badge (GET /commands). Enter runs the line on the server with POST /command ({ line, conversationId }) and the page draws the Reply: text, a table, or buttons to pick from. A command that asks the person something gets null at once on the page (see Asking the person). A script runs one with bxagents.runCommand( "/ping" ), as if it were typed.

Files in web/

web/ is a folder inside a folder extension. Every file in it (images and fonts too, in subfolders as well) is served at <path>/ext/<name>/<file>, where <path> is the webui gateway's path: extensions/panel/web/logo.png is /chat/ext/panel/logo.png. The file is read from the extension itself in the built app (<app>/extensions/<name>/web/); nothing is copied next to the page.

extensions/panel/
  Extension.bx
  web/
    panel.css       linked into every page
    panel.js        linked into every page
    logo.png        served at <path>/ext/panel/logo.png
    img/icon.svg    served at <path>/ext/panel/img/icon.svg, not linked
  • The *.css and *.js files that sit directly in web/ are linked into every page of the app, in file name order: styles in the head, after the app's own; scripts at the end of the body, deferred, after the app's own script. Files in subfolders are served but not linked.
  • Like the page's own scripts and styles, these files are not behind the sign-in. Do not put anything secret in web/.
  • An address is checked before any file is read: the extension is a plain folder name, the file a relative path with no .., no part that starts with a dot and no backslash, and the file must be inside the extension's web/ folder. Anything else, a missing file, or an extension turned off in extensions.disable answers 404.
  • Which files are linked is written by bxAgents build, so build again after you add or rename one.
  • Only the project's own extensions/ bring web/ files (see What stays in the project).

A script runs on every page, but the slot places, the open conversation and the commands exist only on the Chat page. Elsewhere bxagents.slot() gives a box that is not in the page, conversationId() is "" and runCommand() does nothing. Check for the Chat page's message box (document.getElementById( "input" )) if a script should only run there.

The bxagents object

The page makes one object, window.bxagents, before the extensions' deferred scripts run. Its members are fixed (a browser test keeps them so):

MemberWhat it does
bxagents.apiBasethe agent API's path (/__bxagents, or what agentApi.path says), for your own fetch calls
bxagents.slot( place )a new box of your own in header, sidebar or composer to draw into. Another place throws an error
bxagents.runCommand( line )runs a slash command as if it were typed, and shows its answer in the conversation. Does nothing while a turn runs
bxagents.onRefresh( fn )calls fn() after each draw of the slots and status chips: when the Chat page opens and after each turn, command and change of conversation. A listener that throws is logged in the browser console and the others still run
bxagents.refresh()asks the Chat page to read the slots, the status chips and the context size now
bxagents.conversationId()the id of the conversation in view, or ""
bxagents.icon( name )the markup of one of the page's Phosphor icons (bxagents.icon( "robot" )), sized by the text around it. The names are in tools/webui-vendor/icons.json

There is no event bus and no other member. plug and notify are the page's own, not part of the contract. A call to the API from a script goes to bxagents.apiBase + "/..." on the same origin, so the sign-in cookie goes with it. A call that changes something must also send the header x-bxagents-csrf: 1. On an agent with an API password and no accounts, a script's own fetch does not carry the password: run a command instead.

Theming

The page's colours, shapes and fonts are CSS custom properties. Use them in your CSS and it follows light and dark, the visitor's accent and the gateway's theme block:

VariableWhat it is
--bg, --surface, --input-bgthe page, a card or panel, a text box
--fg, --muted, --bordertext, quieter text, lines
--accent, --accent-fgthe brand colour, and text on it
--accent-soft, --accent-ink, --ringa light tint of the accent, the accent as text or an icon, the focus glow
--radius, --radius-smlarge and small corners
--font, --font-mono, --font-sizethe text font, the code font, the base size

The dark theme sets the same variables on :root[data-theme="dark"], so a rule that uses them needs no dark copy. The gateway's theme block and the project's resources/webui/theme.css come after the extensions' styles in the page, so the operator's choices win over an extension's. Do not hard-code a colour: it breaks the dark theme and the operator's brand.

A worked example: the panel extension

The dev agent of the web app (ui/dev/agent/extensions/panel) uses all of it: a header slot that counts pings, a sidebar slot with markup, a /ping command, and a script that adds a Ping button to the message box.

extensions/panel/
  Extension.bx
  web/
    panel.css
    panel.js

Extension.bx:

class {

	function configure() {
		variables.settings = { name : "panel" }
		variables.pings = 0
	}

	// shown as text in the bar above the conversation, next to the context size
	@Slot( "header" )
	function badge( agentContext ) {
		return variables.pings > 0 ? "#settings.name#: #variables.pings# ping#variables.pings == 1 ? '' : 's'#" : ""
	}

	// markup the author wrote, under the list of conversations
	@Slot( { place : "sidebar", html : true } )
	function about( agentContext ) {
		return "<strong>#encodeForHTML( settings.name )#</strong><br>Use the Ping button by the message box."
	}

	@Command
	@Hint( "count a ping: the web page's Ping button runs it too" )
	function ping( agentContext, commandArguments ) {
		variables.pings++
		return agentContext.reply().ok( "pong #variables.pings#" )
	}

}

The sidebar slot is markup, so the setting in it goes through encodeForHTML(): settings.name can be changed in Agent.yml.

web/panel.css uses the page's variables, so the button follows light, dark and the accent:

.panel-button {
	font: inherit;
	padding: 0.25rem 0.6rem;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: transparent;
	color: inherit;
	cursor: pointer;
}

web/panel.js adds the button to the message box and runs the command:

( function () {
	var button = document.createElement( "button" );
	button.type = "button";
	button.className = "panel-button";
	button.textContent = "Ping";
	button.title = "Run /ping";
	button.addEventListener( "click", function () { bxagents.runCommand( "/ping" ); } );
	bxagents.slot( "composer" ).appendChild( button );
} )();

What happens on the Chat page:

  1. The page loads panel.css in the head and panel.js at the end of the body. The script finds bxagents there and puts the Ping button in the message box.
  2. The page asks GET /slots. The header slot is empty (no ping yet), so nothing shows there; the sidebar shows panel in bold and the line under it.
  3. A click on Ping runs /ping with POST /command. The answer, pong 1, shows in the conversation.
  4. After the command the page asks for the slots again, and the header shows panel: 1 ping. The button stays: it is in a box of the script's own, which a draw never removes.

/ping typed in the message box, or in the terminal chat, counts the same way. To try it, run the web app's dev stack (see Work on the web app) and open http://127.0.0.1:8780/chat.

Tools and skills

A folder extension can carry its own tools and skills:

extensions/helpdesk/
  Extension.bx
  tools/Tickets.bx             a normal bx-ai tool class
  skills/triage/SKILL.md       a normal skill folder

The extension stays as it is. The app reads the folders where they are (extensions/helpdesk/tools/ in the built app) and gives the tools to the root agent as if they were in the project's own tools/, and adds the skills to the global skills every agent gets. Nothing is copied or merged into the project's tools/ or skills/. A tool or skill of the project's own wins over an extension's of the same name, and a later extension wins over an earlier one. extensions.disable takes extension:Tickets (the tool's file name) or extension:ticket-triage (the skill's name) for one, or the extension's name for all of them.

Gateway types

A class in an extension's gateways/ folder is a gateway type, named after its file in lower case: extensions/matrix/gateways/Matrix.bx is the type matrix. It is an ordinary bx-ai gateway (see the built-in ones, which extend ScheduledGatewayBase); its getName() must be the same as its file, lower case, because that is the key bx-ai's gateway registry holds it under. A project then uses it like any other:

// gateways/chat.bx
class {
	function configure() {
		return { type : "matrix", homeserver : "https://matrix.example.org", tokenEnvVar : "MATRIX_TOKEN" };
	}
}

Every option named <name>EnvVar is the name of an environment variable: the gateway receives its value as <name> (here token), and it is read when the app starts, so a secret is never a literal in the build. The app builds the gateway from the extension's own class file and registers it when it starts.

All the types come from one registry, GatewayTypes: the built-in ones, and whatever extensions bring. A built-in type cannot be replaced (an extension cannot take over telegram). Two extensions on one type is a warning and the later one wins. A file name that is not a usable type name (a letter, then letters, digits and -) is refused. extensions.disable takes extension:Matrix for one type or the extension's name for all of them. The gateway classes are read from the project's extensions only.

Command line verbs

@Verb( { name : "greet", valueOptions : [ "name" ] } )
@Hint( "say hello from the command line: bxAgents greet --name=Ada" )
function greet( options ) { return "Hello, #options.name ?: 'there'#!" }

bxAgents greet --name=Ada finds the verb in the extensions (modules, the person's own and the project's, loaded as in the chat) when it is not one of the module's own. The method is called with the flags as a struct, as a built-in verb gets them (--projectRoot is always there). It returns an exit code, a message to print, { exitCode, message }, or nothing. A flag that must have a value is listed in valueOptions, so --name alone is refused as it is for a built-in verb. A method that throws is an error with exit code 1 that names the extension. A built-in verb cannot be replaced, and two extensions on one verb is a warning with the later one winning. bxAgents help lists the verbs extensions add. They are not in the generated shell completions, which stay as they are. registry.verb( "greet", ( options ) => ..., { hint, valueOptions } ) is the call form, and extensions.disable takes extension:method.

Where extensions come from

LayerFolderRuns in
modulesextensions/ of an installed BoxLang moduleeverywhere the module is installed
user~/.bxagents/extensions/the terminal chat on that machine only
project<project>/extensions/the terminal chat, the web page, chat platforms, the server

A later layer wins. An extension with the same name replaces the earlier one, and a command replaces an earlier command of the same name or alias, a built-in included. Both are shown in /extensions; nothing is replaced silently. The build copies the project's extensions/ into the app; a served agent never reads a developer's home folder.

Starting one

bxAgents add extension standup                       # asks what it should bring
bxAgents add extension standup --with=command,key    # or say so, for a pipe or CI
bxAgents add extension standup --with=command,tool --description="Daily standup"

(With the BoxLang 1.19.0 launcher a quoted value with spaces is split at the spaces; see Quoting flag values.)

add extension writes extensions/<name>.bx, or extensions/<name>/ with an Extension.bx when something needs a file of its own, with working stubs and a TODO where you fill in. --with takes any of command, key, status, prefix, source, slot, verb, listener (methods of the one class) and scheduler, gateway, tool, skill, web (files, so the extension is a folder). --layout=file|folder picks the shape when it can be either. Nothing is overwritten without --force, and --dry-run shows the files. It is yours: commit it with the project. Try it with bxAgents chat and /reload.

Installing extensions

bxAgents extensions install puts an extension into the project from a folder, a zip, GitHub or ForgeBox.

bxAgents extensions install ./my-ext                    # a folder
bxAgents extensions install ./my-ext.zip                # a zip file
bxAgents extensions install ./greet.bx                   # a one-class extension
bxAgents extensions install acme/tools                  # GitHub: owner/repo, or owner/repo#ref
bxAgents extensions install https://github.com/acme/tools
bxAgents extensions install https://example.org/ext.zip # a zip by address
bxAgents extensions install acme-tools@1.2.0            # a ForgeBox slug, optionally with a version
bxAgents extensions install ./my-ext --system           # for you, in ~/.bxagents/extensions

A folder that exists wins over owner/repo. To say which you mean, start with path:, github:, forgebox: or url:.

An extension is code that runs when the chat or the app starts, so install fetches it into a temporary folder, looks at it without running anything, and shows you what it adds (commands, keys, prefixes, listeners, gateways, tools, skills, web files, verbs) and what its code mentions (files, network, processes, java). It then asks for a yes. --yes skips the question and is required when there is no terminal. Nothing is placed until you agree.

CommandDoes
install <source>fetch, preview, ask, place. --name=<name> renames it, --force replaces one that is there, --system installs for you instead of the project
installwith no source, brings back everything extensions.lock.json lists
list --installedwhat was installed, where from, and whether it is intact, changed or missing
update [name...]fetches again, shows the change and asks. A source pinned to a version or ref (#v1, @1.2.0) is left alone
remove <name>deletes it and its lock entry. A folder you edited needs --force

The project keeps extensions.lock.json (~/.bxagents/extensions.lock.json with --system): the name, the source, the version or ref fetched, and a checksum of the files. Commit the lock. bxAgents build brings back anything in it that is missing, and refuses a package whose files no longer match their checksum. Installed extensions are not committed (see below), and the build restores them from the lock.

An installed extension is kept out of source control with one line per extension in the project's .gitignore (/extensions/acme-tools/, or /extensions/acme.bx), added on install and taken out on remove, only when the project has a .gitignore. An extension you wrote yourself in the same folder is still committed. Commit extensions.lock.json: it is what brings the rest back.

What install refuses: a zip entry with an absolute path, a .. part or a backslash, more than 5000 files or 50 MB, a name that is not safe as a folder name, a name already there that this command did not install (unless --force), a BoxLang module (ModuleConfig.bx), and anything that is not an extension. Symbolic links and .git are left out. The preview is a quick read of the text, not a security review: install what you trust.

bxAgents extensions link ./my-ext                 # ~/.bxagents/extensions/my-ext -> ./my-ext
bxAgents extensions link ./greet.bx --name=hi     # a one-class extension, under another name
bxAgents extensions unlink my-ext                 # takes the link away, never the folder

link makes a symbolic link in your own extensions folder, so the terminal chat on this machine loads the extension from where you are editing it, and /reload picks up a change with nothing to install again. There is no preview and no lock: the code is yours, and a link is a path on this machine, so it is not brought back on another one. A real folder or file in that place is never replaced, a name installed with install --system has to be removed first, and --force only points an existing link somewhere else. list --installed --system shows links beside installs, as linked or broken (the target went away). Because a link is for you, it is not part of a project and does not travel into a built app: put the extension in the project's extensions/ (or install it) for that.

Turning things off

extensions:
  disable: [ roll, "deploy:deploy", "acme-*" ]

A plain name turns off the extension of that name (and any command called that); extension:item turns off one command; * matches any run of characters. Both Agent.yml and ~/.bxagents/Agent.yml accept it.

Looking at them

/extensions in the chat, or from the shell:

bxAgents extensions          # the list, where each came from and what it added
bxAgents extensions --json

What stays in the project

Tools, skills, gateway types and web/ files are read from the project's own extensions/ folder, which the build copies into the app as it is. An extension in an installed module or in your own ~/.bxagents/extensions still adds commands, keys, prefixes, listeners and verbs to the chat and the command line, but it does not travel into a built app: a server never reads a developer's home folder.

Edit this page Download Markdown Last updated Nov 26, 2026, 8:45:51 AM Report an issue