Package com.tnsai.agents.variant
Class VariantManager
java.lang.Object
com.tnsai.agents.variant.VariantManager
Manages agent variants and handles runtime switching.
The VariantManager provides:
- Runtime variant switching
- Automatic variant selection based on task complexity
- Variant usage tracking and statistics
- Event notification for variant changes
Usage
VariantManager manager = new VariantManager(AgentVariant.MEDIUM);
// Manual switching
manager.setVariant(AgentVariant.HIGH);
// Auto selection
manager.setAutoMode(true);
AgentVariant suggested = manager.suggestVariant("Refactor the authentication system");
// Listen for changes
manager.onVariantChange(event -> {
System.out.println("Switched from " + event.previous() + " to " + event.current());
});
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandle returned by listener registration that allows unregistration.static final recordEvent fired when variant changes.static classStatistics for a variant. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a manager with the default MEDIUM variant.VariantManager(AgentVariant initialVariant) Creates a manager with the specified initial variant. -
Method Summary
Modifier and TypeMethodDescriptionGets all statistics.Gets the current variant configuration.Gets the current variant.getStats(AgentVariant variant) Gets statistics for a variant.booleanReturns true if auto mode is enabled.Registers a listener for variant changes.voidrecordTask(AgentVariant variant, long durationMs, boolean success) Records a completed task for statistics.booleanRemoves a previously registered listener.voidsetAutoMode(boolean enabled) Enables or disables auto mode.voidsetVariant(AgentVariant variant) Sets the variant.voidsetVariantSpec(AgentVariant variant, VariantSpec config) Sets a custom configuration for a variant.suggestVariant(String taskDescription) Suggests a variant based on task description.
-
Constructor Details
-
VariantManager
public VariantManager()Creates a manager with the default MEDIUM variant. -
VariantManager
Creates a manager with the specified initial variant.
-
-
Method Details
-
getCurrentVariant
Gets the current variant. -
getCurrentSpec
Gets the current variant configuration. -
setVariant
Sets the variant. -
setVariantSpec
Sets a custom configuration for a variant. -
setAutoMode
public void setAutoMode(boolean enabled) Enables or disables auto mode. -
isAutoMode
public boolean isAutoMode()Returns true if auto mode is enabled. -
suggestVariant
Suggests a variant based on task description. If auto mode is enabled, also switches to the suggested variant. -
recordTask
Records a completed task for statistics. -
getStats
Gets statistics for a variant. -
getAllStats
Gets all statistics. -
onVariantChange
public VariantManager.Registration onVariantChange(Consumer<VariantManager.VariantChangeEvent> listener) Registers a listener for variant changes.- Parameters:
listener- The listener to register- Returns:
- A Registration that can be used to unregister the listener
-
removeVariantChangeListener
Removes a previously registered listener.- Parameters:
listener- The listener to remove- Returns:
- true if the listener was removed
-