Bird
0
0

Review this production agent code snippet:

medium📝 Debug Q7 of 15
Agentic AI - Production Agent Architecture
Review this production agent code snippet:
class Agent:
    def run(self):
        try:
            self.act()
        except Exception as e:
            self.recover(e)
    def act(self):
        raise ValueError('Error')
    def recover(self, error):
        print('Recovered from', error)

agent = Agent()
agent.run()
What is the bug in this code?
AThe recover method is correctly called with the exception, so there is no bug.
BThe act method does not raise any exceptions, so recover is never called.
CThe recover method requires an argument, but it is not provided in the except block.
DThe run method should not catch exceptions to allow them to propagate.
Step-by-Step Solution
Solution:
  1. Step 1: Check exception handling

    The except block catches Exception as e and passes e to recover.
  2. Step 2: Verify recover method signature

    recover accepts an error parameter and prints it.
  3. Step 3: Confirm act method behavior

    act raises a ValueError, triggering the except block.
  4. Final Answer:

    The recover method is correctly called with the exception, so there is no bug. -> Option A
  5. Quick Check:

    Exception passed correctly to recover method [OK]
Quick Trick: Check method signatures match exception handling calls [OK]
Common Mistakes:
  • Assuming recover is called without arguments
  • Thinking act does not raise exceptions
  • Believing exceptions should not be caught

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes