Agent behaviours (part 3) Agent communication (part 1) Fabiano Dalpiaz Agent-Oriented Software Engineering (AOSE) 2009-10 Behaviour execution in dedicated thread • JADE scheduler changes beahviour only when an action() method returns – Pros: efficiency and scalability – Cons: What if an action() method never returns or takes long time? • JADE allows for threaded execution of a behaviour – A dedicated thread is given to the behaviour – How to? • Create a ThreadedBehaviourFactory • When adding a behaviour b, call addBehaviour(tbf.wrap(b)) Behaviour execution in dedicated thread • Be careful when using threaded behaviours – The method removeBehaviour() of Agent (you can guess its semantics) does not work with threaded behaviours – Threaded behaviours must be explicitly killed • Take the thread by calling the getThread() method of ThreadedBehaviourFactory • Call the thread's interrupt() method – Synchronization is not handled by JADE • If the threaded behaviour uses shared resources, the programmer is in charge of concurrency management Exercise 1: Concurrent Behaviours • Create one agent – One shared integer variable value – Its top-level behaviour is a parallel one – The parallel behaviour has three sub-behaviours • A wakeup behaviour which deletes the agent after 12 sec • Two identical behaviours that cyclically – Increment value, wait for n milliseconds, print value – The actual value of n is passed in the constructor » Behaviour 1: 2000 ms » Behaviour 2: 3000 ms – Behaviour 2 is executed in a dedicated thread – HINT: you might have troubles with CyclicBehaviour!!! Agent communication • Agents typically are not isolated – They operate in multi-agent systems! • Agents communicate by messaging – What is a message? – How is a message defined? – What is a protocol? Agent communication basics • JADE agents have communication capabilities – The adopted paradigm is asynchronous message passing. • Each agent has a sort of mailbox (the agent message queue) – JADE posts into the mailbox the messages sent by other agents – Whenever a message is posted in the message queue the receiving agent is notified – The programmer decides when to get the message from the message queue 6 Messages: the reference model Software Agent Agent Platform Agent Management Directory System Facilitator ACC Internal Platform Message Transport 7 F. Dalpiaz – AOSE 2008-09 How do agents communicate? • Messages exchanged by JADE agents have a format specified by the FIPA ACL (Agent Communication Language) – Instances of the jade.lang.acl.ACLMessage class. • JADE provides methods to get and set all the fields defined by the ACL language – – – – – – – get/setPerformative() get/setSender() add/getAllReceiver() get/setLanguage() get/setOntology() get/setContent() … 8 F. Dalpiaz – AOSE 2008-09 Anatomy of an ACL message FIPA performatives • inform: Tell another agent something. • confirm: The sender confirms to the receiver the truth of the content. • disconfirm: The sender confirms to the receiver the falsity of the content. • not-understood: Sent when the agent did not understand the message. • propagate: Asks another agent to forward this same propagate message to others. FIPA performatives • query-if: The action of asking another agent whether or not a given proposition is true. • inform-if: Used as content of request to ask another agent to tell us is a statement is true or false. • query-ref: The action of asking another agent for the object referred to by an referential expression. • inform-ref: Like inform-if but asks for the value of the expression. FIPA performatives • request: The sender requests the receiver to perform some action. • request-when: The sender wants the receiver to perform some action when some given proposition becomes true. • request-whenever: The sender wants the receiver to perform some action as soon as some proposition becomes true and thereafter each time the proposition becomes true again. FIPA performatives • agree: The action of agreeing to perform a requested action made by another agent. Agent will carry it out. • refuse: The action of refusing to perform a given action, and explaining the reason for the refusal. • cancel: Agent wants to cancel a previous request. • failure: Tell the other agent that a previously requested action failed. FIPA performatives • cfp: Agent issues a call for proposals. It contains the actions to be carried out and any other terms of the agreement. • propose: Used as a response to a cfp. Agent proposes a deal. • accept-proposal: The action of accepting a previously submitted propose to perform an action. • reject-proposal: The action of rejecting a proposal to perform some action during a negotiation. FIPA performatives • proxy: The sender wants the receiver to select target agents denoted by a given description and to send an embedded message to them. • subscribe: The act of requesting a persistent intention to notify the sender of the value of a reference, and to notify again whenever the object identified by the reference changes.
© Copyright 2026 Paperzz