In my previous post, I explained the basic concepts of an agent: autonomy, reactivity, proactivity and social ability. In this post I want to answer a simple question: what makes an agent different from normal code?
Luis needs money
Luis needs 500 to fix his car, so he asks his neighbor Ana for a loan. What happens next depends on how we build Ana.
Agents vs. objects
If Ana is an object, Luis just calls a method and the money moves:
# Ana as an object: Luis just takes the money
ana.lend_money(luis, 500) # it always runs
An object has state and communicates through messages (method calls), but it doesn't control its behavior: if someone calls a public method, the method runs.
If Ana is an agent, Luis can't take the money. He has to ask, and Ana decides:
# Ana as an agent: Luis sends a request, Ana decides
luis.send(ana, Request("lend", amount=500))
# inside Ana
def on_request(self, msg):
if msg.amount <= self.savings * 0.2 and self.trust(msg.sender) > 0.7:
self.reply(msg, Agree())
else:
self.reply(msg, Refuse("I can't right now"))
Ana decides with her own information: how much money she has saved and how much she trusts Luis. Wooldridge sums it up like this: objects do it for free; agents do it because they want to.
There's another difference. An object waits until someone calls it. An agent has its own thread of control and flexible behavior (reactive, proactive and social): it acts even if nobody asks it to. In the city, Ana decides every moment what to do next, like going to work or looking for food.
Agents vs. expert systems
An expert system gives advice about a specific domain, but it's disembodied: it doesn't perceive its environment or act on it directly, only through a user. It also has no social ability: it doesn't cooperate or negotiate with other systems.
In the city, an expert system would be a calculator that tells you how much a used car is worth. It gives you a good answer, but it doesn't go out and negotiate the price for you. An agent does.
Side by side
| Object | Expert system | Agent | |
|---|---|---|---|
| Decides whether to act | No | No | Yes |
| Perceives and acts on its environment | No | No, only through a user | Yes |
| Acts on its own initiative | No | No | Yes |
| Talks to other systems | Only method calls | No | Yes, with messages |
| City example | A fridge | A car price calculator | Ana |
What this means for the city
Agents will receive messages from other agents and they will decide whether to do what they're asked. For example, an agent may want to buy a house, but the owner decides whether to sell it or not.
This gives me an important design rule: an agent should never change another agent's state directly. If Luis wants Ana's money, he can't run ana.money -= 500. He has to ask, and Ana decides.
What I found hard to understand
At first I thought "autonomy" meant that an agent can say no. Actually, autonomy means that nobody controls the agent from outside. Being able to say no to a request is what makes an agent different from an object.
What's next
But how does Ana decide if she lends the money? She needs beliefs about Luis (is he trustworthy?) and her own goals (she's saving for a car). That's where models like BDI and trust come in, and I'll get there in future posts. In the next one, I'll look at the different types of environments an agent can live in.
If you have built agents before, I'd like to know: where do you draw the line between an object and an agent in your code? Let me know in the comments.
Sources
- Michael Wooldridge, An Introduction to MultiAgent Systems (2nd ed.)
- Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach (4th ed.)

Top comments (0)