Skip to main content

Beliefs

Beliefs are a fundamental concept in the BDI model: they are the agent's knowledge about the world, itself, and other agents. Beliefs change as the agent perceives, receives messages, or acts.

A belief can be any Kotlin type: a string, a data class, an enum. Beliefs are compared with equals, so the belief base never holds the same belief twice. An incarnation can fix a richer type: with the Prolog incarnation, a belief is a Prolog fact or inference rule.

tip

The examples come in two flavours: plain Kotlin types, and the Prolog incarnation. Pick one tab, and every page keeps showing that one.

Initial beliefs​

Initial beliefs are declared with believes { }, adding each belief with +. They can also be added one at a time with addBelief(belief) in the agent builder.

A barista who starts with some coffee beans, from the sub-goals example:

agent<String, Task> {
embodiedAs { Any() }
believes {
+"beans"
}
}

Updating beliefs from plans​

Plan bodies change beliefs with agent.believe(...) and agent.forget(...):

adding.goal { this as? Grind } triggers {
agent.print("Grinding the beans")
agent.forget("beans")
}

Querying beliefs​

Plan guards read the current belief base as beliefs, and plan bodies as agent.beliefs.

The belief base is a collection, queried like any other: grinding is applicable only while there are beans.

adding.goal { this as? Grind } onlyWhen { context.takeIf { "beans" in beliefs } } triggers {
// ...
}

Perceptions and messages​

Agents do not share a global belief base: each agent turns what it perceives from its node into its own beliefs, with handlesPerceptionEvents (see Perception), and does the same with the messages it receives, with handlesMessageEvents (see Receiving messages).

Belief events​

Every change to the belief base generates an event that can trigger plans: adding.belief { } reacts to additions and removing.belief { } to removals. See Triggers. Adding a belief already present, or removing one that is not, changes nothing and triggers no plan.