Bird
0
0

Identify the error in this agent code snippet:

medium📝 Debug Q7 of 15
Agentic AI - Future of AI Agents
Identify the error in this agent code snippet:
class Agent:
    def __init__(self):
        self.memory = []
    def act(self, input):
        self.memory.append(input)
        return self.memory

agent = Agent()
print(agent.act('data'))
AThe print statement is missing parentheses
BThe memory list is not initialized properly
CThe append method is incorrectly used
DThe act method returns the list instead of its length
Step-by-Step Solution
Solution:
  1. Step 1: Review the code

    The act method appends input to memory and returns the memory list.
  2. Step 2: Identify expected behavior

    Typically, act should return a summary like length, not the entire list.
  3. Step 3: Analyze options

    The act method returns the list instead of its length correctly identifies that returning the list may be unintended. Other options are incorrect as append is used correctly, memory is initialized properly, and print syntax is correct.
  4. Final Answer:

    The act method returns the list instead of its length -> Option D
  5. Quick Check:

    Returns list instead of length [OK]
Quick Trick: Check if return value matches expected output type [OK]
Common Mistakes:
  • Returning entire list instead of summary
  • Misusing append method
  • Incorrect initialization of attributes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes