Chapter 14. Initial States

Initial states of an agent or a capability represent their configuration at creation time. In an initial state, instance elements can be declared that are created when the agent (resp. the capability) is started. This means an initial state is the right place to specify which plans should initially run or which goals the agent shall pursue after creation. It is possible to declare any number of initial states for a single agent or capability. When starting an agent or including a capability you can choose among the available initial states (called configurations). In Figure 14.1, “The Jadex initialstates XML schema part” the XML portion for specifying initial states is depicted. Each initial state must have a name for identification purposes. The default initial state can be set up by using the default attribute of the <initialstates> base tag. If no explicit default initial state is specified, the first one declared in the ADF is used.

The Jadex initialstates XML schema part

Figure 14.1. The Jadex initialstates XML schema part

An initial state allows to specify various properties. Generally, the initial state allows two different kinds of adaptations. The first one is the creation of instance elements for declared types, e.g., initial goals or plans. The second one is the configuration of instance elements such as beliefs or capabilities. In the following, the possible settings will be discussed.

14.1. Capabilities

The <capabilities> tag allows to configure included capabilities. For this purpose a reference to an included <initialcapability> must be declared. The reference to the capability is established by setting the ref attribute to the symbolic name of the capability specified within the <capabilities> section of the agent/capability (i.e., not the type name but the instance name). The initial state to be used by the included capability can be set by using the initialstate attribute of the initial capability.

The Jadex initial capabilities XML schema part

Figure 14.2. The Jadex initial capabilities XML schema part

In Figure 14.3, “Initial capability configuration” an example is shown how the initial state can be used to declare two different initial states. In state "one" the included capability "mycap" is configured to use its initial state "a", while in state "two" "b" is used. Per default the agent would start using initial state "two" as it is declared as default.

<agent ...>
    ...
    <capabilities>
        <capability name="mycap" file="SomeCapability"/>
    </capabilities>
    ...
    <initialstates default="two">
        <initialstate name="one">
            <capabilities>
                <initialcapability ref="mycap" initialstate="a"/>
            </capabilities>
        </initialstate>
        <initialstate name="two">
            <capabilities>
                <initialcapability ref="mycap" initialstate="b"/>
            </capabilities>
        </initialstate>
    </initialstates>
</agent>

Figure 14.3. Initial capability configuration

14.2. Beliefs

In the <beliefs> section the initial facts of beliefs and belief sets can be altered or newly introduced. In order to set the initial fact(s) of a belief or belief set an <initialbelief> resp. an <initialbelief set> tag should be used. The connection to the "real" belief is again established via the ref attribute and the facts can be declared in the same way as default values of beliefs and belief sets. The initial state does not distinguish between original beliefs and references to beliefs from other capabilities, therefore the same tags can also be used to change initial facts of belief references and belief set references as well.

The Jadex initial beliefs XML schema part

Figure 14.4. The Jadex initial beliefs XML schema part

The example in Figure 14.5, “Initial belief configuration” shows how an initialstate can be used to change belief facts. Belief "name" has a default value of "Jim" which is overridden by the initial belief fact "John". The belief set "names" has no default values. In the initial state it is filled with some data from a database. This means that for all results that the method DB.queryNames() produces, a new fact is added to the belief set.

<agent ...>
    ...
    <beliefs>
        <belief name="name" class="String">
            <fact>"Jim"</fact>
        </belief>
        <beliefset name="names" class="String"/>
    </beliefs>
    ...
    <initialstates>
        <initialstate name="one">
            <beliefs>
                <initialbelief ref="name">
                    <fact>"John"</fact>
                </initialbelief>
                <initialbelief set ref="names">
                    <facts>DB.queryNames()</facts>
                </initialbelief set>
            </beliefs>
        </initialstate>
    </initialstates>
</agent>

Figure 14.5. Initial belief configuration

14.3. Goals

In the <goals> section initial goals can be specified. This means that a new goal instance is created for each declared initial goal. The specification of an <initialgoal> requires the connection to the underlying goal template which is used for instantiation. For this purpose the ref attribute is used. Optionally, further parameter(set) values can be declared by using the corresponding <parameter> and <parameterset> tags.

The Jadex initial goals XML schema part

Figure 14.6. The Jadex initial goals XML schema part

In Figure 14.7, “Initial goals” an example is depicted how an initial goal can be created. The initial goal refers to the declared "play_song" perform goal of the agent and provides a new parameter value for the song parameter. When the agent is started in this initial state it creates the initial goal and pursues it. So, given that the agent has some plan to play an mp3 file, it will play a welcome song in this example.

<agent ...>
    ...
    <goals>
        <performgoal name="play_song">
            <parameter name="song" class="URL"/>
        </performgoal>
    </goals>
    ...
    <initialstates>
        <initialstate name="one">
            <goals>
                <initialgoal ref="play_song">
                    <parameter ref="song">
                        <value>new URL("http://someserver/welcome.mp3")</value>
                    </parameter>
                </initialgoal>
            </goals>
        </initialstate>
    </initialstates>
</agent>

Figure 14.7. Initial goals

14.4. Plans

In the <plans> section initial plans can be specified. This means that a new plan instance is created for each declared initial plan. The specification of an <initialplan> requires the connection to the underlying plan template which is used for instantiation. For this purpose the ref attribute is used. Optionally, further parameter(set) values can be declared by using the corresponding <parameter> and <parameterset> tags.

The Jadex initial plans XML schema part

Figure 14.8. The Jadex initial plans XML schema part

In Figure 14.9, “Initial plans” an example is depicted how an initial plan can be used. In this case an initial "print_hello" plan is declared which refers to the "print_hello" plan template of the agent. As result the agent will print "Hello World!" to the console on start-up.

<agent ...>
    ...
    <plans>
        <plan name="print_hello">
            <body>new PrintOnConsolePlan("Hello World!")</body>
        </plan>
    </plans>
    ...
    <initialstates>
        <initialstate name="one">
            <plans>
                <initialplan ref="print_hello"/>
            </plans>
        </initialstate>
    </initialstates>
</agent>

Figure 14.9. Initial plans

14.5. Events

Finally, in the <events> section initial events can be specified. This means that a new event instance is created for each declared initial event. It is possible to define initial internal and initial message events (goal events are not necessary as initial goals can be declared). The specification of an <initialinternalevent> or an <initialmessageevent> requires the connection to the underlying event template which is used for instantiation. For this purpose the ref attribute is used. Optionally, further parameter(set) values can be declared by using the corresponding <parameter> and <parameterset> tags.

The Jadex initial events XML schema part

Figure 14.10. The Jadex initial events XML schema part

In Figure 14.11, “Initial events” an example is shown how an initial message event can be created. The intial message event refers to the underlying message event template "inform_born" and sets the parameter values for the content as well as for the receiver. When the agent "Harry" is started, it sends an initial message event with the content "Harry is born." to an agent named "Uncle" on the same platform.

<events>
    <messageevent name="inform_born" type="fipa" direction="send">
        <parameter name="performative" class="String" direction="fixed">
            <value>SFipa.INFORM</value>
        </parameter>
    </messageevent>
</events>
...
<initialstates>
    <initialstate name="one">
        <events>
            <initialmessageevent ref="inform_born">
                <parameter ref="content">
                    <value>$agent.getAgentName()+" is born."</value>
                </parameter>
                <parameterset ref="receivers">
                    <value>new AgentIdentifier("Uncle", true)</value>
                </parameterset>
            </initialmessageevent>
        </events>
    </initialstate>
</initialstates>

Figure 14.11. Initial events