#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Home / Blog /

Learning Agent in AI: Architecture

Comprehensive Insights and Components

Published
5 min read
Scroll Down

What is a learning agent?

A learning agent is an agent that improves its own performance through experience. Instead of relying only on the knowledge its designer built in, it observes the results of its actions, judges how well it did, and changes its future behaviour.

Every other agent type can be turned into a learning agent: a simple reflex agent can learn better condition-action rules, a model-based agent can learn a more accurate model of the world, and a utility-based agent can learn better utility estimates. Learning matters most when the environment is unknown or changing, one of the properties of environments that decide how an agent must be built. The four-part architecture below is the one given by Russell and Norvig in Artificial Intelligence: A Modern Approach.

Architecture of a learning agent

            Performance standard
                     |
                     v
 Sensors ------> [ CRITIC ] ---- feedback ----+
    ^                                         |
    |                                         v
 ENVIRONMENT                         [ LEARNING ELEMENT ]
    |                                  |             |
    |                          changes |             | learning goals
    |                                  v             v
 Actuators <---- [ PERFORMANCE ELEMENT ]   [ PROBLEM GENERATOR ]
                    ^      (knowledge)            |
                    +------ suggested experiments -+

A learning agent is divided into four conceptual components:

  1. Performance element: the part that selects actions. It takes percepts and decides what to do. This is what we would call "the agent" if it did not learn.
  2. Critic: tells the learning element how well the agent is doing, by comparing behaviour against a fixed performance standard. The standard has to come from outside the agent; if the agent could change it, it could simply lower the bar instead of improving.
  3. Learning element: uses the critic's feedback to decide how the performance element should be changed, and makes those changes to its knowledge (rules, model, weights or utility estimates).
  4. Problem generator: suggests exploratory actions that may be worse in the short term but lead to new, informative experiences. Without it, the agent would keep repeating whatever looks best now and might never discover a better option.

Worked example: an automated taxi

Russell and Norvig use a self-driving taxi to show how the four parts work together:

ComponentWhat it does for the taxi
Performance elementHolds the driving knowledge and chooses actions: steer, brake, change lane, pick a route.
CriticWatches the result of each action against the performance standard. After a sharp lane change across three lanes, it notices the shocked reaction of other drivers and reports that the action was bad.
Learning elementTurns that feedback into a new rule, for example "do not cut across several lanes at once", or updates its estimate of braking distance on a wet road.
Problem generatorSuggests experiments, such as trying a different route at rush hour or testing the brakes on a new road surface, to learn things the current behaviour would never reveal.

A learning agent in Python

This small program makes all four components explicit. The agent must pick one of three routes for a daily trip. It does not know how often each route arrives on time; it learns that by driving.

import random

random.seed(7)
TRUE_SUCCESS = {'route_A': 0.3, 'route_B': 0.8, 'route_C': 0.5}   # hidden from the agent

class LearningAgent:
    def __init__(self, actions, epsilon=0.1):
        self.estimate = {a: 0.0 for a in actions}   # knowledge used by the performance element
        self.count = {a: 0 for a in actions}
        self.epsilon = epsilon

    def performance_element(self):
        return max(self.estimate, key=self.estimate.get)          # best action known so far

    def problem_generator(self):
        if random.random() < self.epsilon:                         # sometimes try something new
            return random.choice(list(self.estimate))
        return None

    def critic(self, arrived_on_time):
        return 1.0 if arrived_on_time else 0.0                     # performance standard: on time = 1

    def learning_element(self, action, feedback):
        self.count[action] += 1
        n = self.count[action]
        self.estimate[action] += (feedback - self.estimate[action]) / n   # running average

    def step(self):
        action = self.problem_generator() or self.performance_element()
        percept = random.random() < TRUE_SUCCESS[action]          # environment responds
        self.learning_element(action, self.critic(percept))
        return action

agent = LearningAgent(TRUE_SUCCESS)
for trip in range(1, 501):
    agent.step()
    if trip in (10, 100, 500):
        est = {a: round(v, 2) for a, v in agent.estimate.items()}
        print(f"after {trip:3} trips: estimates {est}, uses per route {agent.count}")
print("chosen route:", agent.performance_element())

Output:

after  10 trips: estimates {'route_A': 0.75, 'route_B': 0.67, 'route_C': 0.67}, uses per route {'route_A': 4, 'route_B': 3, 'route_C': 3}
after 100 trips: estimates {'route_A': 0.5, 'route_B': 0.83, 'route_C': 0.67}, uses per route {'route_A': 12, 'route_B': 82, 'route_C': 6}
after 500 trips: estimates {'route_A': 0.5, 'route_B': 0.82, 'route_C': 0.39}, uses per route {'route_A': 26, 'route_B': 451, 'route_C': 23}
chosen route: route_B
  • Performance element: performance_element() picks the route with the best estimated on-time rate.
  • Critic: critic() applies the performance standard (on time = 1, late = 0).
  • Learning element: learning_element() updates the running average for the route just used.
  • Problem generator: problem_generator() picks a random route 10% of the time (an epsilon-greedy strategy).

Early on, the agent overrates route A by luck (0.75 after 4 trips). Because the problem generator keeps sampling the other routes, it finds out that route B is better and ends up using it for about 90% of trips. Set epsilon=0 and the agent can lock onto whichever route got lucky first; that is exactly why the problem generator exists. (Output shown is from Python 3 with random.seed(7).)

How learning agents learn

The kind of feedback the critic can give decides the type of learning:

TypeFeedback availableExample
Supervised learningThe correct answer for each exampleLearning to recognise stop signs from labelled photos
Reinforcement learningA reward or penalty after acting, often delayedThe route agent above; game-playing agents
Unsupervised learningNo feedback; find structure in the dataGrouping customers by behaviour

The difference between supervised and unsupervised learning is covered separately. In the learning-agent picture, the critic is what makes reinforcement learning possible: it converts raw percepts into a signal of "good" or "bad".

Advantages and limitations

  • Works in unknown environments: the designer does not need to foresee every situation.
  • Keeps improving as conditions change, such as new traffic patterns or new user preferences.
  • Needs a good performance standard: a badly chosen standard teaches the wrong behaviour.
  • Exploration has a cost: trying worse actions to learn can be expensive or unsafe, so real systems limit where exploration is allowed.
  • Needs data and time: early behaviour can be poor until enough experience has been collected.

For the other agent types that a learning agent builds on, see intelligent agents and the basic kinds of agent programs. Learned rules are often stored as condition-action rules, the same form used in production systems. Agents, search and learning are covered in Uncodemy's Artificial Intelligence course.