Programming Multi-Agent Systems in Agentspeak Using Jason Wiley Series in Agent Technology
Total Page:16
File Type:pdf, Size:1020Kb
Programming Multi-Agent Systems in AgentSpeak using Jason Wiley Series in Agent Technology Series Editor: Michael Wooldridge, University of Liverpool, UK The ‘Wiley Series in Agent Technology’ is a series of comprehensive practical guides and cutting-edge research titles on new developments in agent technologies. The series focuses on all aspects of developing agent-based applications, drawing from the Internet, Telecommunications, and Artificial Intelligence communities with a strong applications/technologies focus. The books will provide timely, accurate and reliable information about the state of the art to researchers and developers in the Telecommunications and Computing sectors. Titles in the series: Padgham/Winikoff: Developing Intelligent Agent Systems 0470861207 (June 2004) Bellifemine/Caire/Greenwood: Developing Multi-Agent Systems with JADE 978-0-470-05747-6 (February 2007) Programming Multi-Agent Systems in AgentSpeak using Jason Rafael H. Bordini University of Durham, UK Jomi Fred Hübner University of Blumenau, Brazil Michael Wooldridge University of Liverpool, UK Copyright ≤ 2007 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777 Email (for orders and customer service enquiries): [email protected] Visit our Home Page on www.wileyeurope.com or www.wiley.com All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the Publisher. Requests to the Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620. Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The Publisher is not associated with any product or vendor mentioned in this book. All trademarks referred to in the text of this publication are the property of their respective owners. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the Publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought. Other Wiley Editorial Offices John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany John Wiley & Sons Australia Ltd, 42 McDougall Street, Milton, Queensland 4064, Australia John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809 John Wiley & Sons Canada Ltd, 6045 Freemont Blvd, Mississauga, Ontario, L5R 4J3, Canada Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Anniversary Logo Design: Richard J. Pacifico Library of Congress Cataloging-in-Publication Data Bordini, Rafael H. Programming multi-agent systems in AgentSpeak using Jason / Rafael H. Bordini, Jomi Fred HŸbner, Michael Wooldridge. p. cm. Includes bibliographical references. ISBN 978-0-470-02900-8 (cloth) 1. Intelligent agents (Computer software) 2. Computer programming. I. Hübner, Jomi Fred. II. Wooldridge, Michael J., 1966- III. Title. QA76.76.I58B67 2007 006.3 3 − dc22 2007021099 British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library ISBN 978-0-470-02900-8 (HB) Typeset in 11/13.6pt Garamond by Laserwords Private Limited, Chennai, India Printed and bound in Great Britain by Antony Rowe Ltd, Chippenham, Wiltshire This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production. To Idahyr (in memoriam), Maria, Ricardo, Lizete, Roberto, Renato, Rubens, Liliane and Thays. (RHB) To Ilze, Morgana and Thales. (JFH) To Lily May and Thomas Llewelyn. (MW) Contents Preface xi Acknowledgements xvii 1 Introduction 1 1.1 AutonomousAgents......................... 1 1.2 CharacteristicsofAgents....................... 2 1.3 Multi-AgentSystems......................... 5 1.4 HelloWorld!............................. 7 2 The BDI Agent Model 15 2.1 Agent-OrientedProgramming.................... 15 2.2 PracticalReasoning.......................... 17 2.3 AComputationalModelofBDIPracticalReasoning........ 20 2.4 TheProceduralReasoningSystem.................. 22 2.5 AgentCommunication........................ 25 3TheJason Agent Programming Language 31 3.1 Beliefs................................. 32 3.2 Goals................................. 40 3.3 Plans.................................. 41 3.4 Example:ACompleteAgentProgram................ 58 3.5 Exercises................................ 65 4 Jason Interpreter 67 4.1 TheReasoningCycle......................... 67 4.2 PlanFailure.............................. 86 4.3 InterpreterConfigurationandExecutionModes.......... 93 4.4 Pre-DefinedPlanAnnotations.................... 97 4.5 Exercises................................ 98 viii CONTENTS 5 Environments 101 5.1 Support for Defining Simulated Environments ........... 102 5.2 Example:RunningaSystemofMultipleSituatedAgents......109 5.3 Exercises................................ 114 6 Communication and Interaction 117 6.1 AvailablePerformatives........................ 118 6.2 Informal Semantics of Receiving Messages . ........... 119 6.3 Example:ContractNetProtocol................... 130 6.4 Exercises................................ 135 7 User-Defined Components 139 7.1 DefiningNewInternalActions................... 140 7.2 CustomisingtheAgentClass..................... 144 7.3 CustomisingtheOverallArchitecture................ 151 7.4 CustomisingtheBeliefBase..................... 155 7.5 Pre-ProcessingDirectives....................... 160 7.6 Exercises................................ 162 8 Advanced Goal-Based Programming 165 8.1 BDIProgramming.......................... 166 8.2 Declarative(Achievement)GoalPatterns.............. 169 8.3 CommitmentStrategyPatterns................... 172 8.4 OtherUsefulPatterns........................ 175 8.5 Pre-ProcessingDirectivesforPlanPatterns............. 176 9 Case Studies 179 9.1 CaseStudyI:GoldMiners...................... 180 9.2 CaseStudyII:ElectronicBookstore................. 194 10 Formal Semantics 201 10.1SemanticRules............................ 207 10.2SemanticsofMessageExchangeinaMulti-AgentSystem...... 212 10.3 Semantic Rules for Receiving Messages ............... 215 10.4SemanticsoftheBDIModalitiesforAgentSpeak.......... 221 11 Conclusions 225 11.1 Jason andAgent-OrientedProgramming.............. 225 11.2OngoingWorkandRelatedResearch................ 227 11.3GeneralAdviceonProgrammingStyleandPractice........ 230 CONTENTS ix Appendix: Reference Guide 235 A.1EBNFfortheAgentLanguage.................... 235 A.2EBNFfortheMulti-AgentSystemsLanguage............ 236 A.3StandardInternalActions...................... 237 A.4Pre-DefinedAnnotations....................... 255 A.5Pre-ProcessingDirectives....................... 256 A.6InterpreterConfiguration...................... 258 References 261 Index 269 Preface A typical day: You are waiting for the bus to take you to the airport: it is late, and you begin to be concerned about whether, if it is much later, you will have enough time to make your flight. You decide to abandon your plan of travelling by bus, and flag down a taxi instead. The taxi driver does not know which terminal your flight departs from; neither do you. As you approach the airport, you telephone the information line number printed on your ticket, and you are told that the flight departs from terminal one. The taxi drops you off at terminal one, and you enter the terminal, to be confronted by long queues at the check-in counters. You realise that, since you have no check-in baggage, you can use an express check-in counter, and within a minute, an attendant is checking you in. The attendant asks you whether you packed the bag yourself. No, you reply, but immediately point out to her that the bag was packed by your partner. You are given a boarding card and told to proceed through security; you do not know where the security gate is, so you ask. Proceeding through security, the metal detector goes off; you realise your mobile phone is in your pocket, so you remove it, but the detector still goes off. You remove your belt, then your wallet, and you are allowed through. In the departure lounge, you look for a cafe, and buy a sandwich. While you are eating your sandwich, you open your laptop, and quickly check through your email, deleting a dozen or so spam messages, scanning the genuine mail for anything important. While doing this, you keep half an eye on the departure board; your flight is called, so you finish your sandwich, shutdown your laptop, and board. There does not seem to be anything magical about this scenario, does there? Yet an enormous range