Patterns of agents Massimo Cossentino Cossentino Luca Sabatucci
Patterns of agents Massimo Cossentino, Cossentino Luca Sabatucci ICAR/CNR High performance computing and networks institute Italian National Research Council
The Goal of This Work We aim to drastically affect the cost of developing a multi-agent application. But… it is not easy to achieve this goal without simplifying the problem. We decided of using FIPA-compliant platforms and this reduces effectively the dimension of the problem (almost all of these platforms are JAVA-based and have a similar structure). By now we refer to two different platforms: FIPA-OS and JADE
Difference in implementing a simple agent behavior in FIPA-OS and JADE FIPA-OS Shutdown Different Same Constructor structure use method and of the ofsetup indone method behaviors FIPA-OS in both the inonly but the platforms different two platforms name of methods JADE FIPA-OS JADE
What is a pattern n Christopher Alexander* definition: “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice” *C. Alexander, S. Ishikawa, M. Silverstein, M. Jacobson, I. Fiksdahl. King, and S. Angel. A pattern language. Oxford Univ. Press, New York, 1977
OO Patterns classification According to Gamma *, patterns can be classified using two criteria: • Purpose: what the pattern does. They can belong to the following categories: • creational (dealing with the process of object creation), • structural (dealing with the composition of classes and objects) or • behavioural (describing the interactions of classes/objects) patterns. • Scope: classification is directed to separate patterns that apply to classes or object. • Class patterns deal with the relationships among classes (usually structural, for example inheritance), • Object patterns include relationships among object (usually dynamic and established at runtime). E. Gamma and R. Helm and R. Johnson and J. Vlissides - "Design Patterns Elements of Reusable Object Oriented Software“ - "Addison-Wesley", 1994
AO patterns classification n Lind 1 classifies agent-oriented patterns in accordance to the views defined by the author in the MASSIVE methodology. ¡ n Categories reported in this work are: Interaction, Role, Architecture, Society, System, Task, and Environment. Aridor 2 clusters patterns in these categories: ¡ ¡ ¡ traveling (dealing with agent mobility issues), task (regarding the breakdown of agents tasks and the delegation of them from one agent to another) interaction (dealing with agents communications) categories. (1) Jurgen Lind, "Patterns in Agent-Oriented Software Engineering", in Proc. Of AOSE Workshop at AAMAS 2002. July 2002, Bologna(Italy) (2) Y. Aridor and D. B. Lange, "Agent Design Patterns: Elements of Agent Application Design", in Proc. Of the Autonomous Agents '98 Conf. , 1998.
Our concept of patterns We consider a pattern of agent as composed of its design level description and the corresponding JAVA code. More in detail each pattern is composed of: ¡ A structure n n ¡ A behavior n n ¡ Usually a base agent class and a set of task/behavior classes. Described using UML class diagrams Expressed by the agent using its structural elements Detailed in UML dynamic diagrams (activity/state chart diagrams) A portion of code n Some lines of code implementing the structure and behavior described in the previous diagram
The proposed AO classification n We think that: ¡ ¡ n n the basic duality (structure/dynamics) that exists in software is captured by the Gamma's approach we also consider the importance of enriching it in order to fit the specific context (agents not objects). We classify the patterns using two main criteria (like in Gamma et al. ) and include agent specific subcategories in them. Classification Criteria: ¡ ¡ Application context: it regards the structural aspects of the pattern, whether it is to be applied to one agent, more agents or to their composing elements (tasks/behaviors). Functionality: it regards the functional/behavioral aspects of the pattern.
Application Context patterns category Sub-categories: n n Action patterns. They address a functionality of the system; for instance they can be implemented as a method of either an agent class or a task class. Behavior patterns. They address a specific behavior of an agent; we can look at each of them as a collection of actions. Component patterns. They are entire agent patterns; these patterns propose a solution composed of the entire structure of an agent together with its tasks. Service pattern. Concerned about the collaborations between two or more agents; they can be thought as an aggregation of component patterns.
Functionality patterns category Sub-categories: n Access to local resources. They deal with information retrieval and manipulation of data source. n Communication. They represent the solution to the problem of making two agents communicate by an interaction protocol. n Elaboration. They are used to deal with the agent's functionality devoted to perform some kind of elaboration on its knowledge. n Mobility. These patterns describe the possibility for an agent to move from a platform to another
Patterns in our repository
Patterns documentation n Name ¡ n Classification ¡ n The initial situation in which the pattern can be applied. Post-conditions ¡ n A scenario that illustrates a design problem and how the agents and their tasks in the pattern solve the problem. Pre-conditions ¡ n A description of what the pattern does and its rationale and intent Motivation ¡ n The classification of the pattern according to the categories reported in the previous slides Intent ¡ n The name of the pattern The consequences of the application of the pattern: what changes the pattern introduces into the system Structure ¡ A graphical representation of the structure of the agent and its tasks (usually done with a class diagram)
Patterns documentation n Participants ¡ n Collaborations ¡ n Comments on the most significant code fragments to illustrate the pattern implementation in the specific agent platforms Implementation Code ¡ n Availability of the implementation code for the FIPA-OS/JADE platforms. Availability of the UML diagrams of the solution (XMI) for importing them in the existing system design Implementation description ¡ n A (graphical) representation of the collaborations of the agents involved in the pattern (if any) Implementation availability ¡ n A description of the agents involved in the pattern and their roles FIPA-OS/JADE code of the solution Related Patterns ¡ Patterns that should be used in conjunction with this one
The phases of the pattern production/reuse process Class Diagram(s) Meta- pattern XSLT platform specialization pattern XSLT constraints resolver Java skeleton + Activity Diagram Constraints XSL rules Action pattern Design Representation UML Multi-Platform Representation Platform-Specific Representation XML JAVA Java agent complete code
The design level representation of the pattern Class Diagram(s) Meta- pattern XSLT platform … specialization pattern XSLT constraints Query. Receive. Task resolver Java skeleton + Activity Diagram XSL rules Design Representation UML Design level representation of the pattern using UML class and activity diagrams Constraints Action pattern Java agent complete code
The XML meta-pattern representation <Agent name="Query. Initiator"> <Visibility>public</Visibility> Class <Extends. Agent. Shell/> Diagram(s) <Agent. Constructor> <Code>constructor@generic_agent</Code> </Agent. Constructor> XSLT platform XSLT … Java Meta- pattern Java agent <Agent. Setup> constraints + specialization skeleton complete code resolver <Code>setup@generic_agent</Code> </Agent. Setup> Activity <Shutdown> Diagram <Code>shutdown@generic_agent</Code> Constraints Action pattern XSL rules </Shutdown> <Task name="Query. Receive. Task "> Multi-Platform Design <Visibility>public</Visibility> Representation <Extends. Task. Shell/> <Task. Constructor> XML UML <Argoment type="Conversation" name="conv"/> <Code>constructor@query_initiator_task</Code> • Meta-patterns are </Task. Constructor> <Task. Setup> platform independent <Code>setup@query_initiator_task</Code> • Meta-patterns contain </Task. Setup> all the common <Method name="handle. Refuse" type="void"> <Visibility>public</Visibility> elements of patterns <Argoment type="Conversation" name="conv"/> for different MA <Code>handle_refuse@query_initiator_task</Code> platforms </Method>
From meta-patterns to patterns – XSL rules Class Diagram(s) Meta- pattern XSLT platform specialization Activity Diagram XSL rules Design Representation UML Multi-Platform Representation XML • Each pattern is specific for one of the selected platforms. • In order to obtain a FIPA-OS pattern we apply to the metapattern the XSLT transformation shown on the right pattern XSLT … constraints resolver Java skeleton + Java agent complete code <!—FIPA-OS SPECIFIC TRANSFORMATION-> <xsl: template match="Extends. Agent. Shell"> Constraints Action pattern <Extends>FIPAOSAgent</Extends> </xsl: template> <xsl: template match="Agent. Constructor"> <Constructor name="{parent: : */@name}"> <Visibility>public</Visibility> <Argument type="String" name="platform"> </Argument> <Argument type="String" name="name"> </Argument> <Argument type="String" name=“ownership"> </Argument> <xsl: copy-of select="Code" /> </Constructor> </xsl: template> <xsl: template match="Agent. Setup"> <Method name="setup" type="void"> <Visibility>private</Visibility> <xsl: copy-of select="Code" /> …
From meta-patterns to patterns Class Diagram(s) Meta- pattern XSLT platform specialization pattern XSLT … constraints resolver Java Meta-pattern skeleton + Java agent complete code Activity Diagram XSL rules Design Representation UML Multi-Platform Representation XML • The resulting pattern is localized to a specific platform • The pattern is still general and can be customized for the specific application Constraints Action pattern <Agent_description agent_system="FIPAOS"> <Agent name="Query. Initiator"> <Visibility>public</Visibility> <Extends>FIPAOSAgent</Extends> <Constructor> <Visibility>public</Visibility> XSL <Argoment type="String" name="platform"/> <Argoment type="String" name="name"/> Transformation <Argoment type="String" name="ownership"/> <Code>constructor@generic_agent</Code> </Constructor> Pattern <Method name="setup" type="void"> <Visibility>public</Visibility> <Code>setup@generic_agent</Code> </Method> …
Patterns introduction in the project generates constraints n When a pattern is applied to a project, it modifies the context in which it is placed (introducing new functionality into the system) n The relationship between the pattern and existing elements could be expressed with a constraint. n A constraint is a rule composed of three elements: n ¡ A target that specifies what agent/task will be influenced by the rule. ¡ A platform that specifies which is the application context (FIPA-OS or JADE) ¡ A content that expresses the changes to be applied when the pattern is inserted into the project (it could be an aggregation of attributes, constructors or methods). An example in FIPA-OS: ¡ When we insert a communication task pattern into an existing agent, the listener task (Idle. Task) should have a handle. X method to catch performative acts of a particular type (i. e. Query. If, Request, Inform, …)
Constraints Class Diagram(s) Meta- pattern XSLT platform specialization pattern XSLT constraints resolver Java skeleton … + Java agent complete code Activity Diagram Constraints XSL rules Action pattern Design Representation UML Multi-Platform Representation Platform-Specific Representation XML <Constraint> <Idle_task platform="FIPAOS"> <Method name="handle. Query. If" type="void"> <Visibility>public</Visibility> <Argument type="Conversation" name="conv"/> <Code>a_function</Code> </Method> </Parent_task> </Constraint> … JAVA From the previous example: here we have the constraint used to introduce the handle. Query. If method in the Idle. Task class of a FIPA-OS agent
From skeleton of classes to complete code n With the previous steps we obtained a skeleton of the agent with its tasks/behaviors that is complete down to the method interfaces of each class n In order to (partially) fill the skeleton with the remaining code, action patterns are applied. n An action pattern is a portion of JAVA code realizing some kind of behavior. It is specific for each platform. ¡ n For example the registration to the DF service (Directory Facilitator, the yellow pages of the platform) it is part of the setup@generic_agent action pattern and it is introduced in the setup method of the agent Action patterns are stored in a database of pieces of code and the correct one for each method is selected referring to the value of the Code tag for the specific module (see the XML pattern representation)
Constraints Class Diagram(s) Meta- pattern XSLT platform specialization pattern XSLT constraints resolver Java skeleton + Java agent complete code Activity Diagram Constraints XSL rules Action pattern Design Representation UML Multi-Platform Representation Platform-Specific Representation XML JAVA try { register. With. DF( AGENT_TYPE ); DIAGNOSTICS. println("Registered with DF", this, DIAGNOSTICS. LEVEL_MAX ); } catch (DFRegistration. Exception dfre) { DIAGNOSTICS. println(dfre, this, DIAGNOSTICS. LEVEL_MAX ); String reason = dfre. get. Exception. Reason(); if ( reason == null || !reason. equals(FIPAMANCONSTANTS. The action pattern for the AGENT_ALREADY_REGISTERED) ) setup method of a generic { FIPA-OS agent shutdown(); return; } } …
The Agent. Factory web application
Screenshots n Create a new multi agent system n Select the agent platform (FIPA-OS or Agent)
Screenshots n Add a component pattern to the MAS n Select the Generic Agent pattern
Screenshots Static, dynamic structure of the pattern and tree representation of the system
Screenshots n Add a behaviour pattern to ‘my. Task’ n Select the FIPA Query Initiator pattern
Screenshots n Static structure of the FIPA Query Initiator pattern n Select the previously created agent from the list
Screenshots n The result of the pattern application: the agent structure, the automatically generated code…
Screenshots n … the static structure and the dynamic behavior
Conclusions and future works
Conclusions and future works n Experimental results are encouraging but the amount of code automatically produced depends on the dimension of the pattern repository n It is difficult to synchronize the DB of patterns for many different platforms n An high level representation of patterns is needed in order to facilitate reuse in early stages of design processes
- Slides: 32