Agents are smart programs that can think and act on their own. They help AI do more complex tasks by making decisions step-by-step, like a helpful assistant.
Why agents represent the next AI paradigm in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Agentic AI
class Agent: def __init__(self, environment): self.environment = environment def perceive(self): # Get information from environment pass def decide(self): # Choose an action based on perception pass def act(self): # Perform the chosen action pass def run(self): while not self.environment.is_done(): self.perceive() self.decide() self.act()
An agent works by perceiving its surroundings, deciding what to do, and then acting.
This loop continues until the task is complete or stopped.
Examples
Agentic AI
class SimpleAgent: def perceive(self): print('Seeing environment') def decide(self): print('Deciding next step') def act(self): print('Taking action') agent = SimpleAgent() agent.perceive() agent.decide() agent.act()
Agentic AI
class LearningAgent: def __init__(self): self.knowledge = [] def perceive(self, data): self.knowledge.append(data) def decide(self): return 'action based on ' + str(self.knowledge[-1]) def act(self, action): print(f'Performing {action}') agent = LearningAgent() agent.perceive('new info') action = agent.decide() agent.act(action)
Sample Model
This program shows a simple agent interacting with an environment. The agent perceives the state, decides an action, and acts. It repeats this until the environment signals it is done.
Agentic AI
class Environment: def __init__(self): self.steps = 0 self.max_steps = 3 def is_done(self): return self.steps >= self.max_steps def get_state(self): return f'State at step {self.steps}' def update(self): self.steps += 1 class Agent: def __init__(self, environment): self.environment = environment def perceive(self): state = self.environment.get_state() print(f'Perceiving: {state}') return state def decide(self, state): action = f'Action based on {state}' print(f'Deciding: {action}') return action def act(self, action): print(f'Acting: {action}') self.environment.update() def run(self): while not self.environment.is_done(): state = self.perceive() action = self.decide(state) self.act(action) env = Environment() agent = Agent(env) agent.run()
Important Notes
Agents help AI handle tasks that need multiple steps and decisions.
They can learn and adapt, making AI smarter over time.
Understanding agents is key to building advanced AI systems.
Summary
Agents are programs that perceive, decide, and act to solve tasks.
They represent a new way AI can work by planning and adapting.
Using agents helps AI handle complex, changing problems better.
Practice
1. What is the main reason agents are considered the next AI paradigm?
easy
Solution
Step 1: Understand what agents do
Agents perceive their environment, make decisions, and take actions to solve tasks.Step 2: Compare options to agent capabilities
Only They can perceive, decide, and act to solve tasks autonomously. correctly describes this autonomous behavior; others are incorrect or unrelated.Final Answer:
They can perceive, decide, and act to solve tasks autonomously. -> Option DQuick Check:
Agent autonomy = They can perceive, decide, and act to solve tasks autonomously. [OK]
Hint: Agents act autonomously by perceiving and deciding [OK]
Common Mistakes:
- Thinking agents only store data
- Believing agents need no input
- Confusing agents with programming languages
2. Which of the following is the correct way to describe an agent's decision process?
easy
Solution
Step 1: Recall agent decision steps
Agents first perceive their environment, then plan decisions, and finally act.Step 2: Match options to this process
Only An agent perceives input, plans, then acts. correctly states the sequence: perceive, plan, act.Final Answer:
An agent perceives input, plans, then acts. -> Option CQuick Check:
Decision process = perceive, plan, act [OK]
Hint: Agents perceive first, then plan and act [OK]
Common Mistakes:
- Assuming agents act randomly
- Thinking agents act before perceiving
- Ignoring the planning step
3. Consider this simple agent code snippet:
What is the value of
class Agent:
def __init__(self):
self.state = 0
def perceive(self, input):
self.state += input
def act(self):
return self.state * 2
agent = Agent()
agent.perceive(3)
agent.perceive(2)
output = agent.act()What is the value of
output after running this code?medium
Solution
Step 1: Track the agent's state changes
Initially, state = 0. After perceive(3), state = 3. After perceive(2), state = 5.Step 2: Calculate the action output
act() returns state * 2 = 5 * 2 = 10.Final Answer:
10 -> Option AQuick Check:
State sum 5 * 2 = 10 [OK]
Hint: Sum inputs before doubling output [OK]
Common Mistakes:
- Using only last input instead of sum
- Forgetting to multiply by 2
- Confusing initial state as output
4. The following agent code has a bug:
What is the bug and how to fix it?
class Agent:
def __init__(self):
self.state = 0
def perceive(self, input):
self.state = input
def act(self):
return self.state * 2
agent = Agent()
agent.perceive(3)
agent.perceive(2)
output = agent.act()What is the bug and how to fix it?
medium
Solution
Step 1: Identify the bug in perceive method
perceive sets state = input, overwriting previous state instead of accumulating.Step 2: Fix by accumulating inputs
Change perceive to add input to state: self.state += input.Final Answer:
Bug: perceive overwrites state; fix by adding input to state. -> Option AQuick Check:
Accumulate inputs in perceive [OK]
Hint: Check if state accumulates or overwrites inputs [OK]
Common Mistakes:
- Changing act method instead of perceive
- Adding missing methods not needed here
- Ignoring state update logic
5. Why do agents better handle complex, changing problems compared to traditional AI models?
hard
Solution
Step 1: Understand agent capabilities in complex environments
Agents perceive changes, plan accordingly, and adapt their actions continuously.Step 2: Compare with traditional AI limitations
Traditional AI often uses fixed rules and lacks continuous adaptation, unlike agents.Final Answer:
Because agents can plan, adapt, and act continuously in dynamic environments. -> Option BQuick Check:
Adaptation and planning = Because agents can plan, adapt, and act continuously in dynamic environments. [OK]
Hint: Agents adapt and plan in changing environments [OK]
Common Mistakes:
- Thinking agents memorize fixed rules
- Believing agents ignore environment
- Assuming agents work without input
