Skip to main content

What are PostProcessors?

PostProcessors modify or enhance AI-generated responses before they’re sent to users. They allow you to add disclaimers, apply formatting, inject dynamic content, or transform the output in any way.

Think of it as:

A final editor - reviews and enhances responses before they go to users
New in v3.0.0: Response postprocessing for consistent formatting, branding, and enhancement.

Why PostProcessors?

Consistency

Apply consistent formatting and style to all responses

Branding

Add company branding, signatures, or footers automatically

Legal Protection

Add disclaimers to medical, financial, or legal advice

Personalization

Inject user-specific information or context

How PostProcessors Work

1

AI Generates Response

Your agent creates a response using its tools and knowledge
2

PostProcessors Run

Each postprocessor modifies the response in priority order
3

Transformation

PostProcessors can:
  • Add content (disclaimers, footers)
  • Format text (markdown, styling)
  • Replace placeholders
  • Translate or enhance
4

Final Response

Modified response is sent to the user

Simple Example

import { PostProcessor, UserDataInstance } from 'lua-cli';

const addDisclaimer = new PostProcessor({
  name: 'add-disclaimer',
  description: 'Add legal disclaimer to responses',
  
  execute: async (user: UserDataInstance, message: string, response: string, channel: string) => {
    return {
      modifiedResponse: response + 
        "\n\n_Disclaimer: This is AI-generated content for informational purposes only._"
    };
  }
});
Tip: You can also access the channel via Lua.request.channel, the user via User.get(), and raw webhook data via Lua.request.webhook?.payload. See the Lua API for details.

Common Use Cases

Add legal or informational disclaimers
execute: async (user, message, response, channel) => {
  if (containsMedicalAdvice(response)) {
    return {
      modifiedResponse: response + 
        "\n\n⚠️ **Medical Disclaimer:** Please consult a healthcare professional."
    };
  }
  return { modifiedResponse: response };
}

Execution Order

PostProcessors run in order of their priority value (lowest first). Priority is set when creating the postprocessor via the API.
AI Agent Response

PostProcessor 1 (priority: 1)   → Runs first

PostProcessor 2 (priority: 10)  → Runs second

PostProcessor 3 (priority: 100) → Runs last

Final Response to User
Default priority: 100 (if not specified) Each postprocessor receives the output of the previous one in the chain.

Adding to Your Agent

import { LuaAgent } from 'lua-cli';
import addDisclaimer from './postprocessors/disclaimer';
import addBranding from './postprocessors/branding';

export const agent = new LuaAgent({
  name: "my-agent",
  persona: "...",
  skills: [...],
  
  // Add postprocessors
  postProcessors: [
    addDisclaimer,  // Runs first
    addBranding     // Runs second
  ]
});

Best Practices

Don’t alter the core message
// ✅ Add to response
modifiedResponse: response + "\n\nAdditional info..."

// ❌ Don't completely replace
modifiedResponse: "Something different"
Order matters - structure flows logically
priority: 1   // Translation (first)
priority: 10  // Formatting
priority: 50  // Content injection
priority: 100 // Disclaimer (last)
Fall back to original response on errors
execute: async (user, message, response, channel) => {
  try {
    return { modifiedResponse: process(response) };
  } catch (error) {
    return { modifiedResponse: response };
  }
}
PostProcessors should be quick (< 50ms)Avoid heavy computations or external API calls

Testing PostProcessors

lua test
# Select: PostProcessor → add-disclaimer
# Provide test response
# See transformed output

Next Steps