# Philosophy, Computing, and Artificial Intelligence

PHI 319. Beliefs, Desires, and Intentions.

## The BDI Model of Practical Reasoning

The BDI ("belief, desire, intention") model stems from work by the philosopher Michael Bratman in Intentions, Plans, and Practical Reason. Harvard University Press, 1987. To implement the observation-thought-decision-action cycle in the logic programming/agent model, we need to think more about the steps in the cycle. In the "Fox and Crow" example, the cycle begins when the fox realizes it is hungry. In the case of a machine, we are imagining that it has sensors and that the information the sensors provide become beliefs in the KB.

So this part of the cycle is a matter of revising the beliefs in the KB based on the information perception provides. For the fox, this just meant adding the proposition that he is hungry to his KB. In general, though, the process of revising beliefs based on new information is more complicated. So we can pretend for now that there is a function, revise, that returns a revised set of beliefs given a set of beliefs and a percept. The cycle, then, looks something like this:

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  while true do
3.      get next percept p;
4.      KB ← revise (KB, p);
?.
?.  end-while

Somehow the fox gets a set of initial beliefs. The cycle begins with the "while true do," which means carry out the instructions that follow as long as "true" evaluates to true. It is part of the system that "true" evaluates to true, so the cycle continues forever. The fox gets the next percept. The KB is revised based on this percept. Some other things happen. Repeat.

Now we need to turn to what happens after the KB is revised. In the case of the fox, the new belief triggered a maintenance goal. The maintenance goal gave rise to an achievement goal.

We can think of achievement goals as desires. From its KB and maintenance goal, the fox gets the desire to have food and eat it. So we can pretend there is a function, options, that returns a set of desires (achievement goals) given the KB and the set of maintenance goals.

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  while true do
3.      get next percept p;
4.      KB ← revise (KB, p);
5.      D ← options (KB, MG);
?.
?.  end-while

Although it was not true in the example of "the fox and the crow," we can easily imagine that options returns a set of desires that has more than one member. So we need a way to settle on one desire the agent intends to pursue. We can pretend there is a function, filter, that returns this intention given the KB and the set of desires (achievement goals).

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  while true do
3.      get next percept p;
4.      KB ← revise (KB, p);
5.      D ← options (KB, MG);
6.      I ← filter (KB, D);
?.
?.  end-while

Given that the fox has his intention, he has to pursue it. In the example, the mechanism was to use backward chaining to determine whether the goal (as a query to the KB) was a logical consequence of the KB. It was not. So we gathered together what backward chaining showed the fox would have to believe for the goal to be a consequence, and we called that a plan.

This, however, is not quite right. What we gathered together are really new achievement goals. These goals arose in the context of the fox trying to achieve his intention to have food and eat it. So we need to change the functions options and filter in the cycle. The desires are a function of the KB, the maintenance goals, and current intentions. From among these desires, the one the agent intends to pursue is a function of the KB and the current intentions.

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  I ← Io;            /* Io are the initial intentions */
3.  while true do
4.      get next percept p;
5.      KB ← revise (KB, p);
6.      D ← options (KB, MG, I);
7.      I ← filter (KB, D, I);
?.
?.  end-while

So given achievement goals, what is the mechanism for achieving them? Somehow the agent must have plans. The agent can construct them or retrieve them from a plan library. We can pretend there is a function, plan, that returns a plan give the KB and the intention.

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  I ← Io;            /* Io are the initial intentions */
3.  while true do
4.      get next percept p;
5.      KB ← revise (KB, p);
6.      D ← options (KB, MG, I);
7.      I ← filter (KB, D, I);
8.      π ← plan (KB, I);
9.      execute (π)
10.  end-while

## An Algorithm for Executing the Plan

Executing the plan is a "while" loop too, but it does not go on forever.

It might be that there is no plan. This is what happens to the fox. It has goals but no plans to achieve them. So if the function plan returns an empty plan, that means there is no plan. In this case, execution of the plan stops before it begins. There are other possibilities too.

1.  KB ← KBo;    /* KBo are the initial beliefs */
2.  I ← Io;            /* Io are the initial intentions */
3.  while true do
4.      get next percept p;
5.      KB ← revise (KB, p);
6.      D ← options (KB, MG, I);
7.      I ← filter (KB, D, I);
8.      π ← plan (KB, I);
9.      while not empty(π) do
10.          α ← head of π;
11.          execute (α);
12.          π ← tail of π;
13.          end-while
14.  end-while

This way of thinking about plan execution, however, does not give the agent much intelligence. The agent just executes the plan one step at a time without thinking about how the world might have changed in the time it takes to execute the plan.

## The Fox and the Crow Again

One way to understand why the fox's thinking unfolds the way it does is to take his thinking to be event driven. The first event is him becoming hungry. This causes a new belief to be added to his KB. This addition triggers the maintenance goal because its antecedent is now a logical consequence of the KB. So now the fox has an achievement goal.

Suppose this achievement goal is "I have food." Now the fox needs a plan. What is it?

To answer this question, we need to think a little about plans. The fox needs a plan because something happened. He got a new achievement goal when he became hungry. So we can think of plans as having triggering events. In the case of the fox, the trigger was the addition of the achievement goal in its mind. A plan can be appropriate in one situation but not another. The description of the appropriate situation is the context for the plan.

triggering_event : context ← body.

In the case of the fox, we know the triggering event. It is the achievement goal "I have food." For the plan, it seems natural to suppose that the fox first asks himself whether he has food. If he does, he can count the goal as having succeeded and can move on with his life. "!" marks something as an achievement goal.

!I have food

"+" marks the addition of a goal and "-" marks that the deletion of a goal because it fails.

+!I have food

-!I have food

+!I have food
: true
← ?I have food.

So in the body of the plan, there is a query to the KB. If the query fails, the achievement goal fails and is deleted. Now the fox needs a plan to deal with this event.

We can imagine various possibilities. One is that the fox looks around to see who has food. This updates the KB, and the fox can try to achieve the goal by taking the food.

-!I have food
: true
← !I look around,
!I take the food.

We can suppose that looking around is a basic action for the fox. So it does not need a plan. We can imagine that, when the fox looked around, it observed and thus came to know that the crow has food and that the fox's plan is to take the food from the crow.

+!I take the food
: the crow has food
← !I take the food from the crow.

Given that the fox has certain beliefs about how to take the food, the plan to achieve this new goal can be to praise the crow and to pick up the food

+!Itake the food from the crow
: the crow has food
←  !I praise the crow,
!I pick up the food.

We can suppose that praising the crow and picking up the food are also basic actions for the fox. So, again, there is no plan to achieve them. The fox simply executes the actions.

## Logic-based Production Systems

To address some of the limitations of LP compared with other models of computation, Kowalski and his colleagues developed the language Logic-based Production System (LPS) Some slides that explain LPS. as an extension of logic programming (LP). The primary limitations LPS addresses are the inability of LP to execute actions and to perform change of state.

Without getting into all the details, we can think of LPS in terms of the BDI model.

The following is a program for a version of the fox and the crow example. The image (to the right) shows how the timeline unfolds when the program is run.

``` fluents has/2, near/2. events becomeHungry/1, beNear/2. actions sing/1, obtain/2, eat/2, praise/2, pickUp/2. food(cheese). initially has(crow, cheese). observe becomeHungry(fox) from 1. if becomeHungry(Agent) then food(X), obtain(Agent, X), eat(Agent, X). if praise(Agent, crow) then sing(crow). obtain(Agent, Object) if beNear(Agent, Object), near(Agent, Object), pickUp(Agent, Object). beNear(fox, cheese) if has(crow, cheese), praise(fox, crow). sing(crow) terminates has(crow, cheese) if has(crow, cheese). sing(crow) initiates near(fox, cheese) if has(crow, cheese). pickUp(Agent, Object) initiates has(Agent, Object). ```

We can see that when the fox observes that it has become hungry, it gets the maintenance goal to obtain and eat some food:

food(X), obtain(fox, X), eat(fox, X)

To achieve the first goal on this list, the fox asks itself for an instance of what it believes food is. The reply is that "cheese" is a food. This transforms the rest of list to

obtain(fox, cheese), eat(fox, cheese)

Consider this first goal. We can think that the plan is to be near to and pickup the cheese.

+!I obtain the cheese
: true
←  !I be near the cheese,
!I pickup the cheese.

We can think that the addition of the goal to be near the cheese triggers a plan with the context "The crow has the cheese") to praise the crow.

+!I be near to the cheese
: The crow has the cheese
←  !I praise the crow.

Praising the crow is a basic action for the fox. So he executes it.

The crow, in turn, perceives the event of the fox praising the crow. The crow's KB gets a new belief triggers its maintenance goal. Singing is a basic action for the crow. So the crow sings. This initiates initiates the event that the fox is near the cheese.

The fox realizes that now he is near the cheese, so his KB has this belief. The next subgoal is

+!I pickup the cheese
: I am near the cheese
←  true.

Praising the crow is a basic action for the fox. The fox simply executes it.

## What we have Accomplished in this Lecture

We looked at the BDI model to some insight into the intelligence displayed in practical reasoning. we cast the "Fox and the Crow" example in this model.