Skip to main content

Overview

PostProcessor allows you to modify or enhance AI-generated responses before they’re sent to users. Use postprocessors to add disclaimers, format output, inject dynamic content, or apply branding.
Response postprocessing for formatting, branding, and enhancement. Use with LuaAgent.
Streaming Support: PostProcessors now execute on both streaming and non-streaming requests. For streaming, post-processors run after the stream completes and emit a postprocess-complete event. See Channel Compatibility for details.

Use Cases

Disclaimers

Add legal or informational disclaimers

Formatting

Apply consistent formatting and styling

Branding

Add company branding or signatures

Dynamic Content

Inject user-specific information

Constructor

new PostProcessor(config)

Creates a new response postprocessor.
PostProcessorConfig
required
Postprocessor configuration object

Configuration Parameters

Required Fields

string
required
Postprocessor description for documentation
function
required
Function that processes AI responsesSignature: (user: UserDataInstance, message: string, response: string, channel: string) => Promise<PostProcessorResponse>Parameters:
  • user - User data instance with profile and custom data
  • message - Original user message (string)
  • response - AI-generated response to modify
  • channel - Channel identifier (e.g., ‘whatsapp’, ‘web’, ‘api’)
Recommended: Use the Lua Runtime API instead of the function parameters:
  • User: User.get() to retrieve the current user
  • Channel: Lua.request.channel for the current channel
  • Webhook: Lua.request.webhook?.payload for raw webhook data (WhatsApp, Slack, Teams, etc.)
The function parameters may be removed in a future version.

Optional Fields

string
Unique postprocessor name. Defaults to 'unnamed-postprocessor' if not provided.Examples: 'add-disclaimer', 'format-response'
number
default:"0"
Execution priority. Lower numbers run first. Use this to control the order when you have multiple postprocessors (e.g. translate before adding disclaimers).
boolean
default:"false"
When true, the postprocessor runs asynchronously — the agent’s response is sent to the user immediately and the postprocessor runs in the background. Use for non-blocking side effects (analytics, audit logs) where the user shouldn’t wait.When false (default), the response is held until the postprocessor returns, allowing it to mutate the text before delivery.

PostProcessorResponse

Your execute function must return:
The response object only contains modifiedResponse. The modified response becomes the input for the next postprocessor in the chain.

Complete Examples

Add Company Branding

Format Response

Add User-Specific Context

Add Call-to-Action

Translation Wrapper

Sentiment Adjuster

Using with LuaAgent

Postprocessors are added to your agent configuration:
Postprocessors execute in order of their priority value (lowest first). Priority is set when creating the postprocessor via the API. If not specified, default priority is 100.

Execution Flow

Each postprocessor receives the output of the previous one in the chain.

Best Practices

Order matters - structure flows logically
Don’t alter the core message
Fall back to original response on errors
Postprocessors should be quick (< 50ms)Avoid heavy computations or external API calls when possible.

Testing Postprocessors

Common Patterns

Conditional Processing

Regex Replacements

Markdown Formatting

PreProcessor

Process messages before agent

LuaAgent

Agent configuration

User API

Access user data

Data API

Store and retrieve data

See Also