Basic chain
public class AgentChain {
private final List stages;
public AgentResponse invoke(String input) {
String current = input;
for (LlmAgent stage : stages) {
current = stage.invoke(current).text();
}
return AgentResponse.of(current);
}
}
AgentChain chain = new AgentChain(List.of(
parserAgent, validatorAgent, transformerAgent, summarizerAgent
)); Advertisement
Passing more than text
Real pipelines carry structured state. Use a PipelineContext instead of raw strings.
public record PipelineContext(String userInput, Map extracted, List warnings) {} Advertisement
Skipping stages conditionally
Not every stage runs every time. Give each stage a shouldRun(ctx) guard so the chain becomes a decision tree.