Engine reference — generated from the canonical engineering source. Do not edit this page by hand.
Plugin Development Guide
Sol’s plugin system runs Lua code inside a sandboxed Luerl VM. Plugins respond to lifecycle events, poll on intervals, and access 14 bridge namespaces under sol.* for server capabilities.
Plugin Structure
my-plugin/
├── plugin.json # Config: name, version, description, config schema
└── plugin.lua # Code: lifecycle functions
plugin.json Schema
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Unique plugin identifier |
version | Yes | string | Semantic version |
description | No | string | Human-readable description |
type | No | string | Plugin type (e.g., "channel") |
config | No | object | Configuration values (overrides schema defaults) |
config_schema | No | object | Schema with required and optional fields |
Example plugin.json
{
"name": "my-plugin",
"version": "1.0.0",
"description": "My custom Sol plugin",
"type": "channel",
"config_schema": {
"required": ["api_key"],
"optional": [
{"name": "timeout", "default": 5000},
{"name": "base_url", "default": "https://api.example.com"}
]
},
"config": {
"api_key": "${MY_PLUGIN_API_KEY}"
}
}
Environment variable expansion: ${ENV_VAR} in config values are replaced with the corresponding environment variable at load time.
Lifecycle Functions
Plugins implement Lua functions that Sol calls at specific points.
init(config)
Called once when the plugin is loaded. Receives the merged configuration (schema defaults + plugin.json config + overrides).
function my_plugin.init(config)
_config = config
sol.log.info("plugin initialized with timeout=" .. tostring(config.timeout))
return true
end
start(channel_id)
Called when a channel using this plugin is started. For channel-type plugins only.
function my_plugin.start(channel_id)
Initialize per-channel state
return true
end
stop(channel_id)
Called when a channel using this plugin is stopped. Clean up resources.
function my_plugin.stop(channel_id)
Clean up
return true
end
send_message(channel_id, message)
Called when a message should be delivered to this channel.
function my_plugin.send_message(channel_id, message)
sol.http.post("https://example.com/hook", '{"text":"' .. message .. '"}')
return true
end
send_to(chat_id, text)
: the addressed send — called when a reply must land on
the chat that asked (the inbound webhook’s authenticated chat id), not on the
channel’s static configured destination. A channel that received an inbound
message carries task_meta.channel_origin = #{plugin, channel_id, chat_id}
through the task; when the task terminates, the channel plane calls
format_event/2 and then send_to(chat_id, text) on the origin plugin.
Return true on delivery; nil, err on failure. Transports with no
per-message destination (Slack/Teams/Discord incoming webhooks) accept the
parameter for contract parity and deliver to their configured webhook.
function my_plugin.send_to(chat_id, text)
local resp = sol.http.post("https://api.example.com/send/" .. chat_id,
'{"text":"' .. text .. '"}')
if resp and resp.status == 200 then return true end
return nil, "send failed: " .. tostring(resp and resp.status)
end
Transport limits
The channel plane clamps every outbound message to the destination
transport’s real limit (and the bundled plugins reserve room for their
[truncated] marker plus the zerg task-status <id> full-result pointer):
| Plugin | Limit | Source |
|---|---|---|
telegram | 4096 chars | Telegram Bot API sendMessage text (1–4096 chars) |
discord | 2000 chars | Discord Execute Webhook content (up to 2000 chars) |
slack | 40000 chars | Slack chat.postMessage text hard limit (4000 is Slack’s “best results” budget) |
teams | 28000 chars | Microsoft Teams Incoming Webhook card payload limit (28 KB) |
sol_channel:transport_limit/1 is the authoritative table; a plugin
config_schema max_message_len that exceeds it is still clamped.
format_event(event_type, event_data)
Called to format an event for channel delivery. Return a string to send, or nil to skip.
function my_plugin.format_event(event_type, event_data)
command replies (for example /tasks) arrive as a string
if event_type == "command_response" then
return tostring(event_data)
end
if event_type == "worker_task_completed" then
return "Task done: " .. tostring(event_data.task_id)
end
return nil
end
poll(method_or_interval)
Called periodically if polling is enabled. The manager calls poll(n) with
the configured interval (ms) for timer pollers, or poll("getUpdates") for
long-poll channel plugins. Return a list of updates or nil.
function my_plugin.poll(method)
if method ~= "getUpdates" then return nil end
local resp = sol.http.get("https://api.example.com/updates")
if resp and resp.status == 200 then
return resp.body -- must be a list
end
return nil
end
handle_update(update)
Called for each update returned by poll.
function my_plugin.handle_update(update)
sol.events.emit("plugin.my_plugin.incoming", update.text)
return update.text
end
Bridge Modules
All bridge modules are available under the sol.* namespace inside the plugin VM.
sol.log
Structured logging to the Sol logger.
sol.log.info("operation completed")
sol.log.warn("slow response detected")
sol.log.error("connection failed: " .. err)
sol.log.debug("retry attempt 3")
sol.http
HTTP client via gun (Erlang HTTP client). Connection pooling with automatic reconnect. TLS verification is enabled for HTTPS URLs.
GET request
local resp = sol.http.get("https://api.example.com/status")
if resp and resp.status == 200 then
sol.log.info("body: " .. tostring(resp.body))
end
POST request
local resp = sol.http.post("https://api.example.com/hook", '{"key":"value"}')
Response object:
| Field | Type | Description |
|---|---|---|
status | number | HTTP status code |
body | string | Response body |
sol.config
Read-only access to plugin configuration.
local value = sol.config.get("timeout", 5000)
sol.events
Event pub/sub within Sol.
Emit an event. The type MUST live inside this plugin's OWN namespace:
exactly `plugin.<plugin-name>` or `plugin.<plugin-name>.<suffix>`.
Foreign plugin namespaces are refused (`event type outside the plugin
namespace`) and counted.
sol.events.emit("plugin.my_plugin.my_custom_event", {key = "value"})
Subscribe to plugin.* events (subject to the admission rules:
plugin.* namespace only, <= 128 bytes, no wildcard-all, per-plugin cap).
subscribe takes the event-type string; delivery arrives at the plugin's
on_event(event_type, data) — a second callback argument is tolerated
but IGNORED.
sol.events.subscribe("plugin.task.completed")
sol.events.unsubscribe("plugin.task.completed")
sol.channel
Channel state management for channel-type plugins.
sol.channel.set_status(channel_id, "active")
local info = sol.channel.get_info(channel_id)
sol.json
Safe JSON string escaping.
local escaped = sol.json.encode_string('He said "hello" and left\n')
Returns: "He said \"hello\" and left\\n"
Note: Only encode_string is available. For full JSON encoding of tables, build manually or use string concatenation.
sol.time
Timestamp utilities.
local wall_ms = sol.time.time_ms() -- wall-clock milliseconds
local mono_ms = sol.time.time_mono_ms() -- monotonic milliseconds
sol.tools
Register custom tools that the LLM agent can invoke. Tool calls are dispatched through the plugin VM; on the wire the tool is exposed as plugin__<plugin>__<name> (reserved names and cross-plugin ownership conflicts are refused).
sol.tools.register("my_tool", "Does something useful",
{ type = "object", properties = { query = { type = "string" } } },
function(input)
return { result = "processed: " .. input.query }
end)
sol.tools.unregister("my_tool")
A 5th argument declares the tool’s permission class — enforced at dispatch since then: the caller’s grant is checked against the declared class on the same execute/write ladder the builtin tools use.
declared "read": any caller with a non-empty grant may invoke
sol.tools.register("stats", "Read plugin stats", {}, function(i) ... end, "read")
declared "write": requires:write/:manage authority (or execute-grade)
sol.tools.register("flush", "Flush caches", {}, function(i) ... end, "write")
declared "execute": requires execute-grade ("*" or tasks:execute)
sol.tools.register("run", "Run a job", {}, function(i) ... end, "execute")
Undeclared tools default to the write class. A refusal answers the
typed {error, {plugin_permission_denied, Tool, Declared, Class}} and
bumps plugin_tool_permission_denied_total. There are no carve-outs:
the ladder runs for EVERY identity. The server’s own internal callers pass
through the same check because they present the server’s single-sourced
grant (sol_identity:system_identity/0 — the <<"*">> admin grant,
expressed in the same vocabulary user grants use), which genuinely covers
every class. A <<"system">> stamp without a covering grant (the degraded
unknown-task posture) and a bare empty identity are refused like any
unprivileged caller.
sol.commands — REMOVED
The slash-command registration surface had no consumers and is no longer
installed in the sandbox. A plugin calling sol.commands.register gets a
clean nil-table error.
sol.sessions
Access session metadata and trigger session operations.
local sessions = sol.sessions.list()
for _, s in ipairs(sessions) do
sol.log.info("Session: " .. tostring(s.id))
end
sol.providers
Query available inference providers and their status.
local providers = sol.providers.list()
for _, p in ipairs(providers) do
sol.log.info(p.name .. " status: " .. p.status)
end
sol.workflows
Interact with the workflow engine — list workflows, attach steps, and observe step progress.
local workflows = sol.workflows.list()
sol.workflows.add_step("my_step", step_def)
sol.workflows.on_step(function(step_name, result)
sol.log.info("step finished: " .. tostring(step_name))
end)
sol.agents
Query and spawn agent workers.
local agents = sol.agents.list()
sol.agents.spawn({ prompt = "Summarize this", model = "glm-4.7-flash" })
sol.agents.on_spawned(function(agent_id)
sol.log.info("spawned: " .. tostring(agent_id))
end)
sol.memory
Scoped key-value storage with TTL support. Keys are automatically scoped to the plugin’s namespace.
sol.memory.set("key", "value", 3600000) -- TTL in ms (1 hour)
local val = sol.memory.get("key")
sol.memory.delete("key")
sol.scheduler
Schedule deferred or recurring tasks from within a plugin.
at(unix_timestamp, event_name) — one-shot, fires the plugin's on_event
sol.scheduler.at(os.time() + 60, "reminder_event")
every(interval_ms, event_name) — recurring, floor = plugin_min_interval_ms
sol.scheduler.every(60000, "heartbeat_tick")
cancel(job_id)
sol.scheduler.cancel(job_id)
Example: Hello World Plugin
hello/
├── plugin.json
└── plugin.lua
Plugin.json:
{
"name": "hello",
"version": "1.0.0",
"description": "Hello World plugin"
}
Plugin.lua:
local hello = {
name = "hello",
version = "1.0.0",
description = "Hello World plugin"
}
function hello.init(config)
sol.log.info("Hello World plugin initialized!")
return true
end
function hello.start(channel_id)
sol.log.info("Hello started for channel " .. tostring(channel_id))
return true
end
function hello.stop(channel_id)
sol.log.info("Hello stopped for channel " .. tostring(channel_id))
return true
end
function hello.send_message(channel_id, message)
sol.log.info("Message: " .. tostring(message))
return true
end
function hello.format_event(event_type, event_data)
return "[" .. event_type .. "] " .. tostring(event_data)
end
return hello
Example: Webhook Plugin
A plugin that posts events to an external URL:
local webhook = {
name = "webhook",
version = "1.0.0",
description = "Webhook delivery plugin",
type = "channel",
config_schema = {
required = {"url"},
optional = {
{name = "method", default = "POST"},
{name = "headers", default = "{}"}
}
}
}
local _config = {}
function webhook.init(config)
_config = config
return true
end
function webhook.start(channel_id)
return true
end
function webhook.stop(channel_id)
return true
end
function webhook.send_message(channel_id, message)
local body = '{"text":"' .. sol.json.encode_string(message) .. '"}'
local resp = sol.http.post(_config.url, body)
if resp and resp.status >= 200 and resp.status < 300 then
return true
end
return nil, "HTTP " .. tostring(resp and resp.status or "none")
end
function webhook.format_event(event_type, event_data)
if event_type == "worker_task_completed" then
return "Task " .. tostring(event_data.task_id) .. ": " .. tostring(event_data.status)
elseif event_type == "worker_crashed" then
return "Worker crashed: " .. tostring(event_data.worker_id)
end
return nil
end
return webhook
Reference: Telegram Plugin
The bundled Telegram plugin (server/priv/plugins/telegram/plugin.lua) demonstrates a complete channel plugin with:
Configuration schema with required/optional fields
MarkdownV2 escaping and message truncation
Rate-limited message queue with configurable depth
Long polling via poll/handle_update for incoming messages
Health check against Telegram Bot API
Event formatting for task completion, crashes, and scheduled tasks
Study it at server/priv/plugins/telegram/plugin.lua (247 lines).
Discovery Locations
Sol loads plugins from two directories:
- Bundled:
server/priv/plugins/— shipped with Sol - User:
~/.sol/plugins/(or path fromplugin_user_dirconfig) — user-installed
Plugins are discovered at startup via sol_plugin_loader. Each subdirectory containing a plugin.lua is a candidate.
Loading
Plugins listed in plugins.json (in the plugin directory or configured via environment) are loaded at boot. The load process:
- Find plugin path (bundled or user dir)2. Trust gate — a
plugins.jsonentry may pin"sha256": "<64 lowercase hex of plugin.lua>"; a mismatch REFUSES the boot (tamper detection, bundled plugins included). A plugin resolving from the USER dir (~/.sol/plugins) without a pin loads only behind the explicit operator ackSOL_PLUGIN_USER_DIR_LOAD_ACK=true(CRITICAL-logged); without it the load is refused (plugin_consent_required). Bundledpriv/pluginswithout a pin are trusted-by-repo - Initialize sandboxed Luerl VM
- Strip
os,io,debug,package,print,eprint,load,loadfile,loadstring,dofile,require( — use thesol.logbridge instead ofprint) - Load bridge modules into
sol.*namespace - Load and execute
plugin.lua - Read metadata (
name,version,type,description) - Validate config against
config_schema - Expand
${ENV_VAR}in config values — allowlist-only ( ): onlyplugin_env_allowlistnames interpolate; anything else expands to an empty string (no host-environment passthrough) - Call
init(config)
** — postures:**
plugin_config_path empty (the shipped sys.config default) or pointing
at a missing/unreadable/invalid file is a degraded posture: Sol boots
with zero backends, logs a WARNING once naming the exact remediation, and
the channels API answers 503 channel_backends_unavailable with the cause
instead of a bare per-request 400 plugin not loaded. Set
plugin_config_path to a plugins.json (for example
server/priv/plugins.json) to load bundled backends.
Lua config_schema arrays (required = {"bot_token"}, optional = {...})
are normalized from luerl’s table decode before validation — the bundled
telegram/discord plugins load with their schema-validated config.
Security Sandbox
| Restriction | Details |
|---|---|
No os library | Cannot execute OS commands |
No io library | Cannot read/write files directly |
No debug library | Cannot inspect VM internals |
No package library | Cannot load external modules |
| Network access | Only via sol.http bridge |
| Reduction budget | plugin_max_reductions (default 5,000,000) — an over-budget runner is killed and the call returns {error, budget_exceeded} |
| Heap budget | plugin_max_heap_mb (default 256) — every runner is spawned with max_heap_size and a heap watchdog; an allocation bomb (t[i] =... table growth) is killed and the call returns {error, heap_budget_exceeded} (metric plugin_heap_killed_total) |
| Wall-clock budget | plugin_lifecycle_timeout_ms (default 3000) — lifecycle/poll/on_event calls time out with {error, timeout}; since then lifecycle Lua runs in offloaded workers, the manager stays responsive while a plugin stalls |
| Closure wall clock | plugin_lifecycle_wall_clock_ms — bounds a WHOLE lifecycle closure (a multi-call poll fold can hold the FIFO for N × the per-call budget); past the deadline the worker is killed and the call returns {error, wall_clock_exceeded} |
| Periodic GC | Luerl VM garbage collected periodically |
Since:
Load-time identity — bridge calls made at the top of your plugin’s
chunk (sol.tools.register, sol.events.subscribe, memory writes)
are attributed to the loading plugin, never to <<"unknown">>.
Unload revokes registrations — unloading a plugin removes every
tool/command/subscription row it registered; worker registries stop
advertising its tools immediately, and a reload starts fresh (no
resurrected rows).
Lifecycle offload — init, poll, on_event, format_event and
tool handlers run in budgeted worker processes; a slow/hostile plugin
cannot block pending_tool_count, is_loaded, or list_plugins.
Bounded event-type admission — sol.events.emit creates at most
plugin_max_event_types (default 1024) unique atoms; past the cap a new
event type is rejected ([false, "unknown event type"]) without creating
an atom. Slots are released at unload.
sol.scheduler events route back — a job created via
sol.scheduler.at/every delivers its event to the plugin’s on_event
(rate-limited like subscription events) instead of dispatching a
prompt-less task.
sol.commands removed — the registration surface had no consumers;
sol.commands is no longer installed in the sandbox (a plugin calling
it gets a clean nil-table error).
sol.http responses are real tables — resp.status and
resp.body work; response bodies are capped at plugin_http_max_body
(default 5 MB, {error, body_too_large} beyond it).
Plugin names must not contain __ or the plugin__ prefix and
must be ≤ 64 bytes — ambiguous wire names (plugin__a__b__tool) are
rejected at load time with {error, invalid_plugin_name}.
Since:
sol.scheduler.every floor — intervals below
plugin_min_interval_ms (default 1000) are refused with a loud Lua
error; a fire-per-ms flood is no longer expressible.
Unload cancels attributed jobs — unloading a plugin cancels its
sol.scheduler jobs (cancel_by_plugin); cancelled jobs stay
cancelled across a reload. Jobs skipped as currently-running finish
their current run and are then gone.
sol.events.subscribe admission — patterns must be in the
plugin.* namespace, ≤ 128 bytes; '*' (wildcard-all) and foreign
namespaces are refused. A plugin holds at most plugin_max_subscriptions
(default 64) rows; refusals return [false, "<reason>"].
sol.events.emit namespace ownership — an emit
must name the caller’s own namespace: exactly plugin.<plugin-name> or
plugin.<plugin-name>.<suffix>. A forged plugin.<other-plugin>.* event
is refused (event type outside the plugin namespace) and counted in
sol_plugin_event_foreign_namespace_total; subscribers of the other
plugin’s namespace can never receive it.
Queue dwell — at/over plugin_queue_dwell_max (default 16) queued
entries per plugin, calls refuse immediately with
{error, {busy, RetryHintMs}} instead of waiting in the FIFO (both
tool and lifecycle calls; the hard cap plugin_max_queue_len returns
the same shape).
Nested payload redaction — event payloads delivered to
on_event are redacted recursively (sensitive keys at any depth up to
16), not just at the top level.
Schema decode bounds — config_schema and tool-registration
schemas are depth/size-capped (16 deep / 1024 nodes); over-bounds
schemas fail the load or refuse the registration loudly.
sol.sessions/sol.providers callback registrations removed —
on_created/on_destroyed/on_registered/on_error were dead APIs: they
stashed callbacks in a short-lived runner’s process dictionary with
zero readers and silently died with it. Calling them is now a clean
nil-field error. A lifetime-anchored reimplementation is a future need.
Degraded-identity clamp — tasks dispatched under a degraded
system identity (e.g. an unknown-task plugin execution) clamp
permission_mode like any read-only requester; the internal
allow-all bypass requires an explicit trusted-internal stamp (see
plan/archive/v0617-v0630-cycle/v0625-degraded-identity.md).
Since:
One budget for tool execution — plugin_execute_timeout_ms
(default 60000) is the single budget for a plugin tool call. Every leg
derives from it: the manager-side kill, the caller leg’s wait (budget +
5s reply-hop slack, sol_plugin_manager:tool_call_timeout/0), and the
executor worker’s kill timer. Pre-fix the caller gave up at a hardcoded
15s while the manager-side Lua worker kept running — a 15–60s tool
produced an error frame AND kept committing state write-backs, so a
retry inside the window executed the tool twice.
At-least-once tool semantics — a tool that outlives the budget is
killed manager-side; the worker receives a distinguishable
plugin_timeout error (never execution_crashed). Because the tool’s
bridge side effects may already be committed when the kill lands, a
plugin_timeout answer means the tool MAY HAVE RUN — agents retry
knowing the outcome is not guaranteed clean. A completion that lands
after its dispatch already closed is counted
(plugin_tool_late_completion_total, warning-logged): the stale
write-back is dropped, the committed effects stand, and the fact is
never silent.
The sandboxed VM provides no access to the filesystem, OS commands, or module loading. All external interaction is mediated through the bridge modules.