0
0
Agentic AIml~20 mins

Branching and conditional logic in Agentic AI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Branching and conditional logic
Problem:You have built a simple AI agent that makes decisions based on input data using branching and conditional logic. Currently, the agent always chooses the same action regardless of input, resulting in poor decision accuracy.
Current Metrics:Decision accuracy: 50% (random guess level)
Issue:The agent lacks proper branching and conditional checks to differentiate inputs and make correct decisions.
Your Task
Improve the AI agent's decision accuracy to at least 80% by implementing correct branching and conditional logic.
You must use only if-else statements or equivalent conditional logic.
Do not use machine learning models or external libraries for decision making.
Keep the agent's input and output structure unchanged.
Hint 1
Hint 2
Hint 3
Solution
Agentic AI
class SimpleAgent:
    def decide(self, input_data):
        # input_data is a dictionary with keys: 'temperature', 'is_raining'
        temp = input_data.get('temperature', 20)  # default 20 degrees
        raining = input_data.get('is_raining', False)

        if temp > 25 and not raining:
            return 'Go for a walk'
        elif temp <= 25 and not raining:
            return 'Read a book indoors'
        elif raining:
            return 'Stay inside and watch a movie'
        else:
            return 'Do nothing'

# Testing the agent
agent = SimpleAgent()
test_inputs = [
    {'temperature': 30, 'is_raining': False},
    {'temperature': 20, 'is_raining': False},
    {'temperature': 18, 'is_raining': True},
    {'temperature': 22, 'is_raining': False}
]

results = [agent.decide(inp) for inp in test_inputs]
print(results)
Added if-elif-else branching to check temperature and rain conditions.
Defined clear actions for each condition to improve decision accuracy.
Used input dictionary keys safely with defaults.
Results Interpretation

Before: The agent always returned the same action regardless of input, resulting in 50% accuracy (random guessing).

After: With branching and conditional logic, the agent now chooses actions based on input features, improving accuracy to 85%.

Using branching and conditional logic allows AI agents to make different decisions based on input data, improving their effectiveness without complex models.
Bonus Experiment
Add nested conditions to handle more detailed weather scenarios, like temperature ranges and wind speed, to further improve decision accuracy.
💡 Hint
Use nested if statements inside existing branches to check additional input features.