Introduction
Agents can do many tasks by themselves, while chatbots mainly chat with you. This helps computers be more helpful and smart in different ways.
Jump into concepts and practice - no test required
Agent = AI system that can plan, act, and learn Chatbot = AI system that mainly talks and answers # Example: agent.perform_task(input) chatbot.reply(message)
agent = Agent()
response = agent.perform_task('Book a flight')chatbot = Chatbot()
reply = chatbot.reply('What is the weather?')class Chatbot: def reply(self, message): if 'hello' in message.lower(): return 'Hi! How can I help you?' return 'Sorry, I only say hello.' class Agent: def perform_task(self, task): if task == 'greet': return 'Hello! I am your agent.' elif task == 'calculate': return 2 + 2 else: return 'Task not recognized.' chatbot = Chatbot() agent = Agent() print(chatbot.reply('Hello')) print(chatbot.reply('What is 2+2?')) print(agent.perform_task('greet')) print(agent.perform_task('calculate')) print(agent.perform_task('unknown'))
class SimpleChatbot:
def respond(self, message):
return "Hello! How can I help?"
class Agent:
def plan(self, goal):
return ["Step 1", "Step 2", "Step 3"]
def execute(self, steps):
return "Tasks done"
bot = SimpleChatbot()
agent = Agent()
print(bot.respond("Hi"))
print(agent.plan("Clean room"))
print(agent.execute(agent.plan("Clean room")))
What is the output of this code?class Agent:
def plan(self, goal):
return ["Step 1", "Step 2"]
agent = Agent()
print(agent.respond("Hello"))
What is the error and how to fix it?