Bird
0
0

Identify the error in the following Agent API code snippet:

medium📝 Debug Q14 of 15
Agentic AI - Production Agent Architecture
Identify the error in the following Agent API code snippet:
class Agent:
    def receive(self, message):
        print(f"Got message: {message}")

def send_message(agent, message):
    return agent.receive(message)

agent = Agent()
response = send_message(agent, "Hi")
print(response)
AThe receive method should return a value, not just print
Bsend_message should not call agent.receive
CAgent class is missing an __init__ method
DThe print statement in send_message is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check receive method behavior

    receive only prints the message but does not return anything, so it returns None by default.
  2. Step 2: Analyze send_message and print(response)

    send_message returns None, so printing response outputs None, which is likely unintended.
  3. Final Answer:

    The receive method should return a value, not just print -> Option A
  4. Quick Check:

    receive must return message for send_message to work [OK]
Quick Trick: receive must return, not just print, to pass data back [OK]
Common Mistakes:
  • Ignoring that print returns None
  • Thinking __init__ is required here
  • Confusing print location with syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes