Transformers
Using transformers with agents to process inputs and outputs, enabling structured extraction and multi-stage pipelines.
Agents can use transformers to pre-process inputs and post-process outputs, enabling structured extraction, content cleaning, and multi-stage AI pipelines.
Output Transformation
Transform agent responses automatically via pipeline:
import bxModules.bxai.models.transformers.TextCleanerTransformer;
agent = aiAgent(
name : "Content Generator",
instructions: "Generate content based on user requests"
)
// Post-process the agent's output
cleaner = new TextCleanerTransformer( {
stripHTML : true,
removeExtraSpaces: true
} )
pipeline = aiMessage()
.user( "${prompt}" )
.to( agent )
.transform( r => r.content )
.to( cleaner )
.transform( cleaned => {
return {
cleaned : cleaned,
wordCount : cleaned.listLen( " " ),
charCount : len( cleaned )
}
} )
result = pipeline.run( { prompt: "Write about BoxLang AI" } )
println( "Word count: #result.wordCount#" )Input Processing
Pre-process user input before it reaches the agent:
Structured Output from Agents
Use transformers to extract and parse structured data from agent responses:
Multi-Stage Agent Processing
Chain multiple agents with transformers between them to form complex workflows:
Related Pages
Getting Started — Creating your first agent
Streaming — Streaming output with agents
Advanced Patterns — Pipeline integration and chaining
Transformers — All built-in transformer types
Last updated