Bird
Raised Fist0
Agentic AIml~20 mins

Agent perception-reasoning-action loop in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Agent Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the role of perception in the agent loop

In the agent perception-reasoning-action loop, what is the primary role of the perception component?

ATo gather information from the environment and convert it into a form the agent can understand
BTo decide the best action based on the current knowledge
CTo store past actions for future reference
DTo execute the chosen action in the environment
Attempts:
2 left
💡 Hint

Think about how the agent first learns about its surroundings.

Predict Output
intermediate
2:00remaining
Output of a simple agent loop step

Given the following Python code simulating one step of an agent loop, what is the printed output?

Agentic AI
class SimpleAgent:
    def __init__(self):
        self.state = 'idle'
    def perceive(self, data):
        return data.upper()
    def reason(self, info):
        if 'HELLO' in info:
            return 'greet'
        return 'wait'
    def act(self, action):
        if action == 'greet':
            return 'Hello, human!'
        return '...' 

agent = SimpleAgent()
data = 'hello world'
info = agent.perceive(data)
action = agent.reason(info)
result = agent.act(action)
print(result)
A...
Bgreet
Chello world
DHello, human!
Attempts:
2 left
💡 Hint

Follow the flow: perceive converts to uppercase, reason checks for 'HELLO', then act responds.

Model Choice
advanced
2:00remaining
Choosing the best reasoning model for an agent

Which model type is best suited for the reasoning component of an agent that must make decisions based on uncertain and changing environments?

AProbabilistic graphical model (e.g., Bayesian network)
BDeterministic rule-based system
CStatic lookup table
DSimple linear regression
Attempts:
2 left
💡 Hint

Consider models that handle uncertainty and update beliefs.

Hyperparameter
advanced
2:00remaining
Hyperparameter affecting agent action speed

In an agent using reinforcement learning for action selection, which hyperparameter primarily controls how quickly the agent explores new actions versus exploiting known good actions?

ALearning rate (alpha)
BDiscount factor (gamma)
CExploration rate (epsilon)
DBatch size
Attempts:
2 left
💡 Hint

Think about the balance between trying new things and sticking to what works.

🔧 Debug
expert
3:00remaining
Debugging an agent loop causing infinite action repetition

Consider this agent loop snippet that causes the agent to repeat the same action endlessly. What is the most likely cause?

Agentic AI
class LoopAgent:
    def __init__(self):
        self.memory = []
    def perceive(self, env):
        return env.get_state()
    def reason(self, state):
        if state not in self.memory:
            self.memory.append(state)
            return 'explore'
        else:
            return 'explore'
    def act(self, action):
        return f'Action: {action}'

agent = LoopAgent()
env = type('Env', (), {'get_state': lambda self: 'state1'})()
for _ in range(3):
    s = agent.perceive(env)
    a = agent.reason(s)
    print(agent.act(a))
AThe perceive method does not update the environment state
BThe reason method returns 'explore' regardless of memory, causing repeated actions
CThe memory list is cleared after each action
DThe act method modifies the action incorrectly
Attempts:
2 left
💡 Hint

Look at the condition and returned action in the reason method.

Practice

(1/5)
1. What is the correct order of steps in the agent perception-reasoning-action loop?
easy
A. Act, Reason, Perceive
B. Act, Perceive, Reason
C. Reason, Act, Perceive
D. Perceive, Reason, Act

Solution

  1. Step 1: Understand the agent loop components

    The agent loop consists of three main steps: perceiving the environment, reasoning about the information, and then acting based on that reasoning.
  2. Step 2: Identify the correct sequence

    The agent must first perceive to gather data, then reason to decide what to do, and finally act to affect the environment.
  3. Final Answer:

    Perceive, Reason, Act -> Option D
  4. Quick Check:

    Agent loop order = Perceive, Reason, Act [OK]
Hint: Remember: see first, think second, do last [OK]
Common Mistakes:
  • Mixing up the order of reasoning and acting
  • Thinking action happens before perception
  • Skipping the reasoning step
2. Which of the following code snippets correctly represents the agent loop structure in Python?
easy
A. while True: reason() act() perceive()
B. while True: act() perceive() reason()
C. while True: perceive() reason() act()
D. while True: act() reason() perceive()

Solution

  1. Step 1: Check the order of function calls

    The agent loop must call perceive() first, then reason(), then act() inside the loop.
  2. Step 2: Verify the code snippet matches this order

    while True: perceive() reason() act() calls perceive(), then reason(), then act(), which matches the correct loop order.
  3. Final Answer:

    while True:\n perceive()\n reason()\n act() -> Option C
  4. Quick Check:

    Code order = perceive, reason, act [OK]
Hint: Loop order matches perception, reasoning, then action [OK]
Common Mistakes:
  • Calling act() before perceive()
  • Swapping reason() and act() calls
  • Incorrect indentation causing syntax errors
3. Given this simplified agent loop code, what will be printed?
def perceive():
    return "data"
def reason(data):
    return data.upper()
def act(result):
    print(f"Action: {result}")

for _ in range(2):
    data = perceive()
    result = reason(data)
    act(result)
medium
A. Action: DATA\nAction: DATA
B. Error: missing argument in reason()
C. Action: Data\nAction: Data
D. Action: data\nAction: data

Solution

  1. Step 1: Trace the function calls in the loop

    Each loop iteration calls perceive() returning "data", then reason(data) converts it to uppercase "DATA", then act(result) prints "Action: DATA".
  2. Step 2: Repeat for two iterations

    The loop runs twice, so the print happens twice with "Action: DATA" each time.
  3. Final Answer:

    Action: DATA\nAction: DATA -> Option A
  4. Quick Check:

    Uppercase output printed twice = Action: DATA [OK]
Hint: Check function returns and loop count carefully [OK]
Common Mistakes:
  • Assuming reason() returns original lowercase
  • Forgetting to pass argument to reason()
  • Confusing print output formatting
4. Identify the error in this agent loop code snippet:
def perceive():
    return "info"
def reason():
    # missing parameter
    return "processed"
def act(result):
    print(result)

while True:
    data = perceive()
    result = reason()
    act(result)
    break
medium
A. act() should not print the result
B. reason() should accept an argument but does not
C. perceive() should not return a value
D. while loop should not have a break

Solution

  1. Step 1: Check function parameters and calls

    perceive() returns "info" which is stored in data, but reason() is called without arguments though it should process data.
  2. Step 2: Identify mismatch causing error

    reason() lacks a parameter to receive data, so calling reason() without argument causes a logic error or mismatch.
  3. Final Answer:

    reason() should accept an argument but does not -> Option B
  4. Quick Check:

    Function parameter mismatch = reason() missing argument [OK]
Hint: Match function parameters with calls exactly [OK]
Common Mistakes:
  • Ignoring missing parameter in reason()
  • Thinking perceive() should not return data
  • Assuming break is incorrect in loop
5. You want to design an agent that perceives temperature, reasons if it's too hot or cold, and acts by turning on a heater or cooler. Which code snippet correctly implements this agent loop?
hard
A. def perceive(): return 30 def reason(temp): if temp > 25: return "cooler" elif temp < 18: return "heater" else: return "off" def act(action): print(f"Turn {action} on") while True: temp = perceive() action = reason(temp) act(action) break
B. def perceive(): return 30 def reason(): if temp > 25: return "cooler" elif temp < 18: return "heater" else: return "off" def act(action): print(f"Turn {action} on") while True: temp = perceive() action = reason() act(action) break
C. def perceive(): return 30 def reason(temp): if temp < 18: return "cooler" elif temp > 25: return "heater" else: return "off" def act(action): print(f"Turn {action} on") while True: temp = perceive() action = reason(temp) act(action) break
D. def perceive(): return 30 def reason(temp): if temp > 25: return "heater" elif temp < 18: return "cooler" else: return "off" def act(action): print(f"Turn {action} on") while True: temp = perceive() action = reason(temp) act(action) break

Solution

  1. Step 1: Check perception and reasoning logic

    perceive() returns temperature 30. reason(temp) correctly returns "cooler" if temp > 25, "heater" if temp < 18, else "off".
  2. Step 2: Verify action and loop structure

    act(action) prints the correct command. The loop calls perceive(), reason(temp), and act(action) in correct order and breaks after one iteration.
  3. Final Answer:

    Option A correctly implements the agent loop with proper logic and function calls -> Option A
  4. Quick Check:

    Correct logic and loop = def perceive(): return 30 def reason(temp): if temp > 25: return "cooler" elif temp < 18: return "heater" else: return "off" def act(action): print(f"Turn {action} on") while True: temp = perceive() action = reason(temp) act(action) break [OK]
Hint: Match temperature conditions with correct actions [OK]
Common Mistakes:
  • Missing parameter in reason() function
  • Swapping heater and cooler logic
  • Calling reason() without argument