Bird
Raised Fist0
Prompt Engineering / GenAIml~20 mins

Agent architecture (observe, think, act) in Prompt Engineering / GenAI - 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 Architect Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the 'Observe' step in agent architecture
In the agent architecture model, what is the primary role of the 'Observe' step?
ATo decide the best action based on past experiences
BTo collect data from the environment through sensors or inputs
CTo execute actions that change the environment
DTo store the results of previous actions for future use
Attempts:
2 left
💡 Hint

Think about how an agent first learns about its surroundings.

Predict Output
intermediate
1:30remaining
Output of agent decision-making code snippet
What will be the output of the following code simulating an agent's 'Think' step?
Prompt Engineering / GenAI
environment_data = {'temperature': 30, 'light': 'bright'}

# Agent thinks based on temperature
if environment_data['temperature'] > 25:
    action = 'turn_on_cooler'
else:
    action = 'do_nothing'

print(action)
Aturn_on_cooler
Bdo_nothing
CKeyError
DSyntaxError
Attempts:
2 left
💡 Hint

Check the temperature value and the condition in the if statement.

Model Choice
advanced
2:00remaining
Choosing the best model for the 'Act' step in an agent
Which type of model is most suitable for the 'Act' step where an agent must perform actions in a continuous environment?
ALinear regression model
BUnsupervised clustering model
CAutoencoder neural network
DReinforcement learning policy network
Attempts:
2 left
💡 Hint

Consider models that learn to make decisions based on rewards.

Metrics
advanced
2:00remaining
Evaluating agent performance metrics
Which metric best measures how well an agent balances exploring new actions and exploiting known good actions during learning?
AExploration rate (epsilon) in epsilon-greedy policy
BPrecision of classification
CMean squared error of predictions
DCumulative reward over time
Attempts:
2 left
💡 Hint

Think about the parameter controlling randomness in action choice.

🔧 Debug
expert
2:30remaining
Debugging an agent's 'Think' step causing wrong action
Given the code below, why does the agent always choose 'do_nothing' even when the temperature is 30?
Prompt Engineering / GenAI
environment_data = {'temperature': 30}

# Agent thinks and decides action
if environment_data['temperature'] < 25:
    action = 'turn_on_cooler'
else:
    action = 'do_nothing'

print(action)
AThe dictionary key 'temperature' is misspelled causing a KeyError
BThe agent lacks an 'Observe' step to get temperature data
CThe condition is reversed; it should be '>' instead of '<' to turn on the cooler when hot
DThe print statement is outside the if-else block causing no output
Attempts:
2 left
💡 Hint

Check the logic condition comparing temperature to 25.

Practice

(1/5)
1. Which of the following best describes the observe step in an agent architecture?
easy
A. Collecting information from the environment
B. Making decisions based on data
C. Performing actions to change the environment
D. Storing past experiences for learning

Solution

  1. Step 1: Understand the role of observation

    The observe step is about gathering data or signals from the environment around the agent.
  2. Step 2: Differentiate from other steps

    Thinking is about decision-making, and acting is about doing something. Observation is just about sensing.
  3. Final Answer:

    Collecting information from the environment -> Option A
  4. Quick Check:

    Observe = Collect data [OK]
Hint: Observe means sensing or collecting data first [OK]
Common Mistakes:
  • Confusing observe with think or act
  • Thinking observe means acting
  • Mixing observe with storing data
2. Which of the following is the correct order of steps in a simple agent architecture?
easy
A. Act, Think, Observe
B. Think, Observe, Act
C. Think, Act, Observe
D. Observe, Think, Act

Solution

  1. Step 1: Recall the agent cycle

    The agent first observes the environment, then thinks (decides), and finally acts.
  2. Step 2: Match the sequence

    Only the sequence Observe, Think, Act matches the correct order of operations.
  3. Final Answer:

    Observe, Think, Act -> Option D
  4. Quick Check:

    Order = Observe, Think, Act [OK]
Hint: Remember: Sense first, then decide, then do [OK]
Common Mistakes:
  • Mixing up the order of steps
  • Starting with act before observe
  • Confusing think and observe order
3. Consider this simple Python agent code snippet:
class Agent:
    def observe(self, data):
        self.data = data
    def think(self):
        return self.data * 2
    def act(self, result):
        print(f"Action: {result}")

agent = Agent()
agent.observe(5)
result = agent.think()
agent.act(result)

What will be printed when this code runs?
medium
A. No output, error occurs
B. Action: 10
C. Action: 25
D. Action: 5

Solution

  1. Step 1: Follow the observe method

    The agent observes the value 5 and stores it in self.data.
  2. Step 2: Follow the think method

    The think method returns self.data * 2, which is 5 * 2 = 10.
  3. Step 3: Follow the act method

    The act method prints "Action: 10" using the result from think.
  4. Final Answer:

    Action: 10 -> Option B
  5. Quick Check:

    5 * 2 = 10 printed [OK]
Hint: Multiply observed data by 2, then print [OK]
Common Mistakes:
  • Confusing observe data with result
  • Forgetting to multiply by 2
  • Expecting no output or error
4. This agent code has a bug:
class Agent:
    def observe(self, data):
        self.data = data
    def think(self):
        return self.data + 1
    def act(self, result):
        print(f"Action: {result}")

agent = Agent()
result = agent.think()
agent.act(result)

What is the error and how to fix it?
medium
A. Error: self.data not set before think; fix by calling observe first
B. Error: act method missing return; fix by adding return statement
C. Error: observe method has wrong parameter; fix by renaming parameter
D. No error; code runs fine

Solution

  1. Step 1: Identify missing observe call

    The code calls think before observe, so self.data is not set.
  2. Step 2: Understand consequence

    Calling think tries to use self.data which does not exist, causing an error.
  3. Step 3: Fix by calling observe first

    Call agent.observe(some_value) before think to set self.data properly.
  4. Final Answer:

    Error: self.data not set before think; fix by calling observe first -> Option A
  5. Quick Check:

    Observe must run before think [OK]
Hint: Always observe before think to set data [OK]
Common Mistakes:
  • Ignoring the missing observe call
  • Thinking act needs return
  • Confusing parameter names
5. You want to build an agent that observes temperature, thinks if it's too hot (>30°C), and acts by turning on a fan. Which code snippet correctly implements the think method?
hard
A. def think(self): return self.data == 30
B. def think(self): if self.data < 30: return True else: return False
C. def think(self): return self.data > 30
D. def think(self): return self.data * 30

Solution

  1. Step 1: Understand the condition for action

    The agent should act if temperature is greater than 30°C, so think returns True if data > 30.
  2. Step 2: Check each option

    def think(self): return self.data > 30 returns True if data > 30, matching the requirement. Others do not correctly check this condition.
  3. Final Answer:

    def think(self): return self.data > 30 -> Option C
  4. Quick Check:

    Think returns True if hot (>30) [OK]
Hint: Think returns True if temperature > 30 [OK]
Common Mistakes:
  • Using wrong comparison operators
  • Returning True for less than 30
  • Multiplying data instead of comparing