Package com.tnsai.planning
Class UtilityAIPlanner
java.lang.Object
com.tnsai.planning.UtilityAIPlanner
- All Implemented Interfaces:
Planner
Utility AI planner that selects actions based on cost/value trade-offs.
Unlike BackwardChainingPlanner which plans toward goals,
UtilityAIPlanner greedily selects the action with highest utility at each step.
This is ideal for:
- Exploratory behaviors (chatbots)
- Dynamic environments
- Cost optimization
- Reactive agents
Algorithm
for each applicable action:
score = 0
for each consideration:
score += consideration.evaluate(action, state) * consideration.weight()
if score > bestScore:
bestAction = action
return bestAction
Usage
UtilityAIPlanner planner = UtilityAIPlanner.builder()
.consideration(Consideration.cost())
.consideration(Consideration.value())
.consideration(Consideration.preconditionSatisfied())
.build();
// Or with defaults
UtilityAIPlanner planner = new UtilityAIPlanner(MyRole.class);
- Author:
- TnsAI Team
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for UtilityAIPlanner. -
Constructor Summary
ConstructorsConstructorDescriptionUtilityAIPlanner(Class<?> roleClass) Creates a planner from a role class.UtilityAIPlanner(Class<?> roleClass, List<Consideration> considerations) Creates a planner from a role class with custom considerations.UtilityAIPlanner(List<PlanningGoal> goals, List<PlanningAction> actions, List<Consideration> considerations) Creates a planner with explicit goals, actions, and considerations. -
Method Summary
Modifier and TypeMethodDescriptionapplyEffects(PlanningAction action, Map<String, Object> state) Simulates applying an action's effects to a state.static UtilityAIPlanner.Builderbuilder()Creates a builder for UtilityAIPlanner.floatcalculateUtility(PlanningAction action, Map<String, Object> state) Calculates total utility score for an action.findActionsForGoal(PlanningGoal goal, Map<String, Object> state) Finds actions that can help achieve a goal.findApplicableActions(Map<String, Object> state) Finds actions whose preconditions are satisfied.findSatisfiedGoals(Map<String, Object> state) Finds goals that are currently satisfied.findUnsatisfiedGoals(Map<String, Object> state) Finds goals that are not currently satisfied.Returns all registered actions.getActionsByUtility(Map<String, Object> state) Gets all actions sorted by utility (highest first).getGoals()Returns all registered goals.booleanisGoalSatisfied(PlanningGoal goal, Map<String, Object> state) Checks if a goal is satisfied.booleanisGoalSatisfied(String goalName, Map<String, Object> state) Checks if a specific goal is satisfied.Creates a plan to achieve unsatisfied goals.Creates a plan with optional chaining.selectBestAction(Map<String, Object> state) Selects the action with highest utility score.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.planning.Planner
getAction, getGoal, isPreconditionSatisfied
-
Constructor Details
-
UtilityAIPlanner
Creates a planner from a role class.Extracts actions with nested @Utility configuration from @Action.
- Parameters:
roleClass- class with @Action methods (optionally with utility = @Utility(...))
-
UtilityAIPlanner
Creates a planner from a role class with custom considerations.- Parameters:
roleClass- class with @Action methodsconsiderations- list of considerations
-
UtilityAIPlanner
public UtilityAIPlanner(List<PlanningGoal> goals, List<PlanningAction> actions, List<Consideration> considerations) Creates a planner with explicit goals, actions, and considerations.- Parameters:
goals- planning goalsactions- available actionsconsiderations- utility considerations
-
-
Method Details
-
builder
Creates a builder for UtilityAIPlanner.- Returns:
- new builder
-
plan
Description copied from interface:PlannerCreates a plan to achieve unsatisfied goals. -
plan
Description copied from interface:PlannerCreates a plan with optional chaining. -
selectBestAction
Selects the action with highest utility score.- Parameters:
state- current world state- Returns:
- best action, or empty if no applicable action
-
getActionsByUtility
Gets all actions sorted by utility (highest first).- Parameters:
state- current world state- Returns:
- sorted list of applicable actions
-
calculateUtility
Calculates total utility score for an action.- Parameters:
action- action to evaluatestate- current state- Returns:
- utility score
-
getGoals
Description copied from interface:PlannerReturns all registered goals. -
getActions
Description copied from interface:PlannerReturns all registered actions.- Specified by:
getActionsin interfacePlanner- Returns:
- list of actions
-
findUnsatisfiedGoals
Description copied from interface:PlannerFinds goals that are not currently satisfied.- Specified by:
findUnsatisfiedGoalsin interfacePlanner- Parameters:
state- current state- Returns:
- unsatisfied goals, ordered by priority (highest first)
-
findSatisfiedGoals
Description copied from interface:PlannerFinds goals that are currently satisfied.- Specified by:
findSatisfiedGoalsin interfacePlanner- Parameters:
state- current state- Returns:
- satisfied goals
-
isGoalSatisfied
Description copied from interface:PlannerChecks if a specific goal is satisfied.- Specified by:
isGoalSatisfiedin interfacePlanner- Parameters:
goalName- goal namestate- current state- Returns:
- true if goal condition is satisfied
-
isGoalSatisfied
Description copied from interface:PlannerChecks if a goal is satisfied.- Specified by:
isGoalSatisfiedin interfacePlanner- Parameters:
goal- goal to checkstate- current state- Returns:
- true if goal condition is satisfied
-
findActionsForGoal
Description copied from interface:PlannerFinds actions that can help achieve a goal.- Specified by:
findActionsForGoalin interfacePlanner- Parameters:
goal- target goalstate- current state- Returns:
- applicable actions for the goal
-
findApplicableActions
Description copied from interface:PlannerFinds actions whose preconditions are satisfied.- Specified by:
findApplicableActionsin interfacePlanner- Parameters:
state- current state- Returns:
- applicable actions
-
applyEffects
Description copied from interface:PlannerSimulates applying an action's effects to a state.- Specified by:
applyEffectsin interfacePlanner- Parameters:
action- action to applystate- state to modify (returns new state)- Returns:
- new state after applying effects
-