Package com.tnsai.agents.ensemble
Class AgentEnsembleExecutor
java.lang.Object
com.tnsai.agents.ensemble.AgentEnsembleExecutor
Handles multi-LLM ensemble operations for an Agent.
This class extracts ensemble/parallel LLM concerns from the Agent class:
- Parallel fan-out to multiple LLMs
- Race pattern (first response wins)
- Consensus/scoring based selection
- Majority voting
- Ensemble synthesis with aggregator LLM
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSends message to multiple LLMs and selects the best response using a scoring function.ensembleChat(String message, List<LLMClient> llms, LLMClient aggregator) Sends message to multiple LLMs and combines responses using an aggregator LLM.majorityVoteChat(String message, List<LLMClient> llms) Sends message to multiple LLMs and selects by majority voting.parallelChat(String message, List<LLMClient> llms) Sends message to multiple LLMs in parallel and collects all responses.Sends message to multiple LLMs and returns the first successful response.
-
Constructor Details
-
AgentEnsembleExecutor
public AgentEnsembleExecutor()
-
-
Method Details
-
parallelChat
Sends message to multiple LLMs in parallel and collects all responses.- Parameters:
message- The message to sendllms- List of LLM clients to query in parallel- Returns:
- Aggregated results from all LLMs
-
raceChat
public Optional<ParallelLLM.LLMResult> raceChat(String message, List<LLMClient> llms, long timeoutSeconds) Sends message to multiple LLMs and returns the first successful response.- Parameters:
message- The message to sendllms- List of LLM clients to racetimeoutSeconds- Timeout in seconds- Returns:
- First successful response, or empty if all fail
-
consensusChat
public Optional<ParallelLLM.LLMResult> consensusChat(String message, List<LLMClient> llms, Function<String, Double> scorer) Sends message to multiple LLMs and selects the best response using a scoring function.- Parameters:
message- The message to sendllms- List of LLM clientsscorer- Function to score each response (higher is better)- Returns:
- Best response based on scoring
-
majorityVoteChat
Sends message to multiple LLMs and selects by majority voting.- Parameters:
message- The message to sendllms- List of LLM clients- Returns:
- Most common response pattern
-
ensembleChat
Sends message to multiple LLMs and combines responses using an aggregator LLM.- Parameters:
message- The message to sendllms- List of LLM clients for initial responsesaggregator- LLM client to synthesize final response- Returns:
- Synthesized response combining best elements
-