What if your robot could watch, think, and act all by itself--making your life easier?
Why Agent architecture (observe, think, act) in Prompt Engineering / GenAI? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine trying to control a robot manually to clean your house. You have to watch every corner, decide what to do next, and move the robot step by step yourself.
This manual control is slow and tiring. You might miss spots, make mistakes, or get overwhelmed by too many decisions at once. It's hard to keep track of everything happening around the robot.
Agent architecture breaks this problem into three simple steps: observe what's around, think about the best action, and then act. This way, the robot can work on its own, making smart choices quickly and reliably.
while True: watch_environment() decide_next_move() move_robot()
while True: agent.observe() agent.think() agent.act()
This approach lets machines handle complex tasks by themselves, adapting to new situations without constant human help.
Self-driving cars use this agent architecture to watch the road, think about traffic and obstacles, and then steer safely without a driver's constant input.
Manual control is slow and error-prone for complex tasks.
Agent architecture splits tasks into observe, think, and act steps.
This makes machines smarter and more independent in real time.
Practice
observe step in an agent architecture?Solution
Step 1: Understand the role of observation
The observe step is about gathering data or signals from the environment around the agent.Step 2: Differentiate from other steps
Thinking is about decision-making, and acting is about doing something. Observation is just about sensing.Final Answer:
Collecting information from the environment -> Option AQuick Check:
Observe = Collect data [OK]
- Confusing observe with think or act
- Thinking observe means acting
- Mixing observe with storing data
Solution
Step 1: Recall the agent cycle
The agent first observes the environment, then thinks (decides), and finally acts.Step 2: Match the sequence
Only the sequence Observe, Think, Act matches the correct order of operations.Final Answer:
Observe, Think, Act -> Option DQuick Check:
Order = Observe, Think, Act [OK]
- Mixing up the order of steps
- Starting with act before observe
- Confusing think and observe order
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?
Solution
Step 1: Follow the observe method
The agent observes the value 5 and stores it in self.data.Step 2: Follow the think method
The think method returns self.data * 2, which is 5 * 2 = 10.Step 3: Follow the act method
The act method prints "Action: 10" using the result from think.Final Answer:
Action: 10 -> Option BQuick Check:
5 * 2 = 10 printed [OK]
- Confusing observe data with result
- Forgetting to multiply by 2
- Expecting no output or error
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?
Solution
Step 1: Identify missing observe call
The code calls think before observe, so self.data is not set.Step 2: Understand consequence
Calling think tries to use self.data which does not exist, causing an error.Step 3: Fix by calling observe first
Call agent.observe(some_value) before think to set self.data properly.Final Answer:
Error: self.data not set before think; fix by calling observe first -> Option AQuick Check:
Observe must run before think [OK]
- Ignoring the missing observe call
- Thinking act needs return
- Confusing parameter names
think method?Solution
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.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.Final Answer:
def think(self): return self.data > 30 -> Option CQuick Check:
Think returns True if hot (>30) [OK]
- Using wrong comparison operators
- Returning True for less than 30
- Multiplying data instead of comparing
