Bird
0
0

Given this code for a production agent, what will be the output if an error occurs in act()?

medium📝 Predict Output Q4 of 15
Agentic AI - Production Agent Architecture
Given this code for a production agent, what will be the output if an error occurs in act()? class Agent: def act(self): raise ValueError('Fail') def recover(self): print('Recovered') def run(self): try: self.act() except Exception: self.recover() agent = Agent() agent.run()
AFail
BError traceback
CNo output
DRecovered
Step-by-Step Solution
Solution:
  1. Step 1: Analyze act() method

    act() raises a ValueError exception when called.
  2. Step 2: Check run() method behavior

    run() calls act() inside try block and catches exceptions, then calls recover() which prints 'Recovered'.
  3. Final Answer:

    Recovered -> Option D
  4. Quick Check:

    Error caught and recovered = B [OK]
Quick Trick: Exceptions trigger recover() printing 'Recovered' [OK]
Common Mistakes:
  • Expecting error message printed
  • Thinking no output occurs
  • Assuming traceback shows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes