Agent Communication - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Agent Communication

Description:

To create a message, you have to indicate its type (performative) and set the content. ... The AMS keeps track of all agents in the system ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 18
Provided by: will178
Category:

less

Transcript and Presenter's Notes

Title: Agent Communication


1
Agent Communication
  • Sensor Web TITAN Research
  • 12/22/2009

2
Agent Communication
  • A fundamental charactistic of MAS
  • Individual agents communicate and interact
  • Accomplished through the exchange of messages
  • To understand each other, agents agree on the
    format and semantics of these messages.
  • Messages adhere strictly to the ACL (Agent
    Communication Language) standard which allows
    several possibilities for the encoding of the
    actual content

3
Structure of a JADE message
  • Performative FIPA message type
  • Addressing
  • Receiver
  • Sender Initialized automatically
  • Content Message content
  • ConversationID Links messages in the same
    conversation

4
Structure of a JADE message (cont.)
  • Language
  • Ontology
  • Protocol
  • ReplyWith
  • InReplyTo
  • ReplyBy

5
Creating a message
  • To create a message, you have to indicate its
    type (performative) and set the content.
  • ACLMessage msg new ACLMessage(
    ACLMessage.INFORM )
  • msg.setContent("I sell seashells at 10/kg" )

6
ACL Performatives
  • INFORM One agent gives another some useful
    information
  • QUERY One agent asks another a question
  • REQUEST One agent asks another to do something
  • PROPOSE Used to start bargaining between agents
  • AGREE Accept a proposition
  • REFUSE Refuse a proposition

7
Sending messages
  • With an Agent ID (AID) for the recipient, sending
    a message is fairly easy
  • AID dest ...
  • msg.addReceiver( dest )
  • send(msg)
  • Note addReceiver allows for adding several
    receivers to the message and the one send
    broadcasts it to all of them.

8
Receiving messages
  • Messages are routed to the receiving agents
    message queue.
  • 2 basic ways for the receiver to get its
    messages.
  • blockingReceive() agent suspends all its
    activities until a message arrives
  • ACLMessage msg blockingReceive()
  • receive() examines the message queue, returning
    a message if there is one or null otherwise. This
    is the normal technique used when an agent is
    involved in parallel activities and has multiple
    active Behaviours.
  • ACLMessage msg receive()
  • if (msg ! null)
  • lt.... handle message...gt
  • else
  • lt... do something else like block() ...gt
  • These methods have variants with additional
    arguments to alter their behaviour. With
    blockingReceive(), one can add a pattern object
    to select the kinds of message that we want to
    receive.

9
Receiver Example
  • public class Receiver extends Agent
  • protected void setup()
  • addBehaviour(new CyclicBehaviour(this)
  • public void action()
  • ACLMessage msg receive()
  • if (msg!null)
  • System.out.println( " - "
  • myAgent.getLocalName() " lt-
    "
  • msg.getContent() )
  • block()
  • )

10
Receiving messages w/ block()
  • NOTE block doesn't stop execution, it just
    schedules the next execution
  • Without block, the behaviour is essentially a LOOP

11
Answering messages
  • All messages have a sender ID attribute, so we
    can answer a message as follows
  • ACLMessage msg receive()
  • ACLMessage reply new ACLMessage(ACLMessage.
    INFORM)
  • reply.setContent( "Pong" )
  • reply.addReceiver( msg.getSender() )
  • send(reply)

12
Answering messages
  • public void action()
  • ACLMessage msg receive()
  • if (msg!null)
  • System.out.println( " - "
  • myAgent.getLocalName() "
    lt- "
  • msg.getContent() )
  • ACLMessage reply
    msg.createReply()
  • reply.setPerformative(ACLMessa
    ge.INFORM)
  • reply.setContent(" Pong" )
  • reply.send()
  • block()
  • NOTE The advantage to using createReply appears
    when other attributes like conversationID or
    ontology have to correspond to the original
    message.

13
Searching the AMS for agents to talk to
  • The AMS keeps track of all agents in the system
  • Searching the AMS an array of all presently known
    agents

14
Searching the AMS Example
  • // Required imports
  • import jade.domain.AMSService
  • import jade.domain.FIPAAgentManagement.
  • ...
  • AMSAgentDescription agents null
  • try
  • SearchConstraints c new
    SearchConstraints()
  • c.setMaxResults ( new Long(-1) )
  • agents AMSService.search( this, new
    AMSAgentDescription (), c )
  • catch (Exception e) ...

15
Ping Pong Example
  • Sends Ping messages to all agents, including
    itself and the 2 system agents
  • Includes a search of the AMS for the agents

16
Ping Pong Example
  • AMSAgentDescription agents null
  • try
  • SearchConstraints c new SearchConstraints()
    c.setMaxResults (new Long(-1))
  • agents AMSService.search( this, new
    AMSAgentDescription (), c )
  • catch (Exception e)
  • System.out.println( "Problem searching AMS " e
    ) e.printStackTrace()

17
Ping Pong Example (cont.)
  • ACLMessage msg new ACLMessage(ACLMessage.INFORM)
    msg.setContent( "Ping" )
  • for (int i0 iltagents.lengthi)
  • msg.addReceiver( agentsi.getName() )
  • send(msg)
  • addBehaviour(new CyclicBehaviour(this)
  • public void action()
  • ACLMessage msg receive()
  • if (msg!null)
  • System.out.println( " Answer" " lt- "
    msg.getContent() " from " msg.getSender().getN
    ame() )
  • block()
  • )
Write a Comment
User Comments (0)
About PowerShow.com