Class Agent

java.lang.Object
jason.asSemantics.Agent
All Implemented Interfaces:
ToDOM, Serializable

public class Agent extends Object implements Serializable, ToDOM
The Agent class has the belief base and plan library of an AgentSpeak agent. It also implements the default selection functions of the AgentSpeak semantics.
See Also:
  • Field Details

  • Constructor Details

    • Agent

      public Agent()
  • Method Details

    • create

      public static Agent create(AgArch arch, String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws Exception
      Set up the default agent configuration.

      Creates the agent class defined by agClass, default is jason.asSemantics.Agent. Creates the TS for the agent. Creates the belief base for the agent.

      Throws:
      Exception
    • setConsiderToAddMIForThisAgent

      public void setConsiderToAddMIForThisAgent(boolean add)
    • initAg

      public void initAg()
      Initialises the TS and other components of the agent
    • addToMindInspectorWeb

      public void addToMindInspectorWeb()
    • loadInitialAS

      public void loadInitialAS(String asSrc) throws Exception
      parse and load the initial agent code + kqml plans + project bels and goals, asSrc may be null
      Throws:
      Exception
    • loadAS

      public void loadAS(String asSrc) throws Exception
      parse and load some agent code, asSrc may be null it does not load kqml default plans and does not trigger initial beliefs and goals
      Throws:
      Exception
    • loadKqmlPlans

      public void loadKqmlPlans() throws Exception
      parse and load asl code
      Throws:
      Exception
    • clearAgMemory

      public void clearAgMemory()
      Clear Agent's Beliefs and Plan Library
    • stopAg

      public void stopAg()
    • clone

      public Agent clone(AgArch arch)
      Clone BB, PL, Circumstance. A new TS is created (based on the cloned circumstance).
    • cloneInto

      public Agent cloneInto(AgArch arch, Agent a)
    • setLogger

      public void setLogger(AgArch arch)
    • getLogger

      public Logger getLogger()
    • getScheduler

      public static ScheduledExecutorService getScheduler()
    • getASLSrc

      public String getASLSrc()
      Returns the .asl file source used to create this agent
    • setASLSrc

      public void setASLSrc(String file)
    • parseAS

      public void parseAS(URL asURL) throws Exception
      Adds beliefs and plans form an URL
      Throws:
      Exception
    • parseAS

      public void parseAS(URL asURL, String sourceId) throws Exception
      Throws:
      Exception
    • parseAS

      public void parseAS(File asFile) throws Exception
      Adds beliefs and plans form a file
      Throws:
      Exception
    • parseAS

      public void parseAS(InputStream asIn, String sourceId) throws ParseException, JasonException
      Throws:
      ParseException
      JasonException
    • parseAS

      public void parseAS(Reader asIn, String sourceId) throws ParseException, JasonException
      Throws:
      ParseException
      JasonException
    • getIA

      Throws:
      ClassNotFoundException
      InstantiationException
      IllegalAccessException
      IllegalArgumentException
      InvocationTargetException
      NoSuchMethodException
      SecurityException
    • setIA

      public void setIA(String iaName, InternalAction ia)
    • initDefaultFunctions

      public void initDefaultFunctions()
    • addFunction

      public void addFunction(Class<? extends ArithFunction> c)
      register an arithmetic function implemented in Java
    • addFunction

      public void addFunction(String function, int arity, String literal)
      register an arithmetic function implemented in AS (by a rule, literal, or internal action)
    • getFunction

      public ArithFunction getFunction(String function, int arity)
      get the object the implements the arithmetic function function/arity, either global (like math.max) or local (like .count).
    • addInitialBel

      public void addInitialBel(Literal b)
      Belief b will be stored to be included as an ordinary belief when the agent will start running. This method is usually called by the parser; at compile time, when the TS may not be ready yet and thus no events can be produced. Beliefs are then scheduled here to be definitely included later when the TS is ready.
    • getInitialBels

      public List<Literal> getInitialBels()
    • addInitialBelsInBB

      public void addInitialBelsInBB() throws JasonException
      add the initial beliefs in BB and produce the corresponding events
      Throws:
      JasonException
    • addInitialBelsFromProjectInBB

      protected void addInitialBelsFromProjectInBB()
    • addInitialGoal

      public void addInitialGoal(Literal g)
      goal g will be stored to be included as an initial goal when the agent will start running
    • getInitialGoals

      public Collection<Literal> getInitialGoals()
    • addInitialGoalsInTS

      public void addInitialGoalsInTS()
      includes all initial goals in the agent reasoner
    • addInitialGoalsFromProjectInBB

      protected void addInitialGoalsFromProjectInBB()
    • importComponents

      public void importComponents(Agent a) throws JasonException
      Imports beliefs, plans and initial goals from another agent. Initial beliefs and goals are stored in "initialBels" and "initialGoals" lists but not included in the BB / TS. The methods addInitialBelsInBB and addInitialGoalsInTS should be called in the sequel to add those beliefs and goals into the agent.
      Throws:
      JasonException
    • socAcc

      public boolean socAcc(Message m)
      Follows the default implementation for the agent's message acceptance relation and selection functions
    • killAcc

      public boolean killAcc(String agName)
      Returns true if this agent accepts to be killed by another agent called agName. This method can be overridden to customize this option.
    • selectEvent

      public Event selectEvent(Queue<Event> events)
    • selectOption

      public Option selectOption(List<Option> options) throws NoOptionException
      Throws:
      NoOptionException
    • selectIntention

      public Intention selectIntention(Queue<Intention> intentions)
    • selectMessage

      public Message selectMessage(Queue<Message> messages)
    • selectAction

      public ActionExec selectAction(Queue<ActionExec> actions)
    • relevantPlans

      public List<Option> relevantPlans(Trigger teP, Event evt) throws JasonException
      Throws:
      JasonException
    • applicablePlans

      public List<Option> applicablePlans(List<Option> rp) throws JasonException
      Throws:
      JasonException
    • setTS

      public void setTS(TransitionSystem ts)
      TS Initialisation (called by the AgArch)
    • getTS

      public TransitionSystem getTS()
    • setBB

      public void setBB(BeliefBase bb)
    • getBB

      public BeliefBase getBB()
    • setPL

      public void setPL(PlanLibrary pl)
    • getPL

      public PlanLibrary getPL()
    • buf

      public int buf(Collection<Literal> percepts)
      Belief Update Function: adds/removes percepts into belief base.
      Returns:
      the number of changes (add + dels)
    • believes

      public boolean believes(LogicalFormula bel, Unifier un)
      Returns true if BB contains the literal bel (using unification to test). The unifier un is updated by the method.
    • findBel

      public Literal findBel(Literal bel, Unifier un)
      Find a literal in BB using unification to test. Returns the belief as it is in BB, e.g. findBel(a(_),...) may returns a(10)[source(ag)]. The unifier un is updated by the method.
    • brf

      public List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i) throws RevisionFailedException
      This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.

      In its return, List[0] has the list of actual additions to the belief base, and List[1] has the list of actual deletions; this is used to generate the appropriate internal events. If nothing change, returns null.

      Throws:
      RevisionFailedException
    • brf

      public List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i, boolean addEnd) throws RevisionFailedException
      This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.

      In its return, List[0] has the list of actual additions to the belief base, and List[1] has the list of actual deletions; this is used to generate the appropriate internal events. If nothing change, returns null.

      Throws:
      RevisionFailedException
    • addBel

      public boolean addBel(Literal bel) throws RevisionFailedException
      Adds bel in belief base (calling brf) and generates the events. If bel has no source, add source(self). (the belief is not cloned!)
      Throws:
      RevisionFailedException
    • delBel

      public boolean delBel(Literal bel) throws RevisionFailedException
      If the agent believes in bel, removes it (calling brf) and generate the event.
      Throws:
      RevisionFailedException
    • abolish

      public void abolish(Literal bel, Unifier un) throws RevisionFailedException
      Removes all occurrences of bel in BB. If un is null, an empty Unifier is used.
      Throws:
      RevisionFailedException
    • hasCustomSelectOption

      public boolean hasCustomSelectOption()
    • getAgState

      public Document getAgState()
      Gets the agent "mind" (beliefs, plans, and circumstance) as XML
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAsDOM

      public Element getAsDOM(Document document)
      Gets the agent "mind" as XML
      Specified by:
      getAsDOM in interface ToDOM
    • getAgProgram

      public Document getAgProgram()
      Gets the agent program (Beliefs and plans) as XML
    • initAg

      @Deprecated public void initAg(String asSrc) throws Exception
      Deprecated.
      use initAg() and load(src)
      parse and load the agent code, asSrc may be null
      Throws:
      Exception
    • load

      @Deprecated public void load(String asSrc) throws Exception
      Deprecated.
      Throws:
      Exception
    • loadAgSrc

      @Deprecated public void loadAgSrc(String asSrc) throws Exception
      Deprecated.
      Throws:
      Exception
    • initAg

      @Deprecated public TransitionSystem initAg(AgArch arch, BeliefBase bb, String asSrc, Settings stts) throws JasonException
      Deprecated.
      Prefer the initAg method with only the source code of the agent as parameter. A call of this method like
           TransitionSystem ts = ag.initAg(arch, bb, asSrc, stts)
           
      can be replaced by
           new TransitionSystem(ag, new Circumstance(), stts, arch);
           ag.setBB(bb); // only if you use a custom BB
           ag.initAg(asSrc);
           TransitionSystem ts = ag.getTS();
           
      Throws:
      JasonException