Package com.tnsai.models.agent
Interface DesireConflictResolver
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy interface for resolving conflicts between desires with the same priority.
When multiple desires have the same priority level, this resolver determines which desire should take precedence. This is particularly useful when desires conflict with each other (e.g., "minimize cost" vs "maximize quality").
Built-in Strategies
FIRST_WINS- Keep the first desire in the listLAST_WINS- Keep the last desire in the listRANDOM- Randomly select one desireMERGE_RATIONALE- Create new desire with combined rationaleKEEP_ALL- No resolution, keep all desires
Usage Example
// Specure agent with conflict resolver
agent.setDesireConflictResolver(DesireConflictResolver.FIRST_WINS);
// Add potentially conflicting desires
agent.addDesire(new Desire("Minimize cost", Priority.HIGH, "Budget constraints"));
agent.addDesire(new Desire("Maximize quality", Priority.HIGH, "Customer satisfaction"));
// Only one remains (based on strategy)
// Using LLM-based resolver
agent.setDesireConflictResolver(new com.tnsai.llm.LLMBasedConflictResolver(llmClient));
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DesireConflictResolverDefault strategy: first wins.static final DesireConflictResolverStrategy that keeps the first desire in the list.static final DesireConflictResolverStrategy that keeps all desires (no resolution).static final DesireConflictResolverStrategy that keeps the last desire in the list.static final DesireConflictResolverStrategy that merges all desires into one with combined rationale.static final DesireConflictResolverStrategy that randomly selects one desire. -
Method Summary
Modifier and TypeMethodDescriptionstatic DesireboostPriority(Desire desire) Creates a priority-boosted desire if resolution results in tie-breaking.default booleanmightConflict(Desire d1, Desire d2) Checks if two desires might conflict with each other.Resolves conflicts among a list of desires with the same priority.
-
Field Details
-
FIRST_WINS
Strategy that keeps the first desire in the list. -
LAST_WINS
Strategy that keeps the last desire in the list. -
RANDOM
Strategy that randomly selects one desire. -
MERGE_RATIONALE
Strategy that merges all desires into one with combined rationale. -
KEEP_ALL
Strategy that keeps all desires (no resolution). -
DEFAULT
Default strategy: first wins.
-
-
Method Details
-
resolve
Resolves conflicts among a list of desires with the same priority.- Parameters:
conflicting- list of conflicting desires (same priority)- Returns:
- the resolved desire, or empty if all should be removed
-
mightConflict
Checks if two desires might conflict with each other. Default implementation uses simple heuristics.- Parameters:
d1- first desired2- second desire- Returns:
- true if desires might conflict
-
boostPriority
Creates a priority-boosted desire if resolution results in tie-breaking.- Parameters:
desire- the desire to boost- Returns:
- a new desire with increased priority (if not already CRITICAL)
-