Skip to main content
PostProcessor runs your code on the model’s reply before it reaches the end user and returns the text to send instead. Register instances on LuaAgent under postProcessors. Inside execute, the runtime objects (User, Data, Lua, env) are available as in a tool. For where a postprocessor sits in a turn, see processors. Verified against lua-cli 3.33.0.

Quick example

A postprocessor that appends a support address to replies sent by email:
src/postprocessors/SupportFooter.ts

Constructor

Creates a postprocessor from a PostProcessorConfig. The class is also exported under the alias LuaPostprocessor.
ErrorsPostProcessor requires a non-empty \name` (used as the server-side identifier).whenname` is missing or blank.

Configuration

string
required
Server-side identifier, and the name lua push postprocessor --name and lua postprocessors address. Kebab-case, for example support-footer.
string
required
Short description shown in listings. Not seen by the model.
(user, message, response, channel) => Promise<PostProcessorResponse>
required
Called once per turn with the end user’s UserDataInstance, the end user’s message, the reply produced by the model or by the previous postprocessor, and the channel identifier ('web', 'whatsapp', 'email', …). message is typed string; a turn that carried an image or file arrives as the array of content parts instead.
number
default:100
Execution order. Lower numbers run first, so a translator at 10 runs before a footer at 100.
There is no async field: the reply is always held until every postprocessor has returned.

Result

execute returns an object with one field. There is no action.
modifiedResponse becomes the input of the next postprocessor and, after the last one, the reply sent to the end user. An empty string is treated as no change: the previous text is kept.

Instance methods

Execution order

  • Only postprocessors that are pushed and active run (lua postprocessors activate). They run in ascending priority, one at a time; each receives the text the previous one returned.
  • A postprocessor that throws or times out is logged (lua logs --type postprocessor) and skipped, and the chain continues with the current text. There is no fail-closed mode.
  • execute has 180 seconds to return.
  • On streaming channels the model’s text is streamed to the end user first; the chain runs when the stream ends, and a changed reply replaces the streamed text. The web stream waits at most 10 seconds for the chain; past that, the model’s own text stands and the rewrite is discarded.
  • lua chat in the sandbox sends a PostProcessorOverride for every postprocessor listed in lua.skill.yaml, so the sandbox turn runs your sandbox version in place of the production one. You never construct overrides yourself.

CLI commands

The lua test input object accepts message, response, and channel.

Types

All of these are exported from 'lua-cli'.
interface
{ name; description; priority?; execute } as documented under Configuration.
interface
{ modifiedResponse: string }.
interface
{ postprocessorId: string; sandboxId: string }. Sent by lua chat to run a sandbox version.
alias
The same class as PostProcessor.

See also