Package jason.asSemantics
Class Agent
java.lang.Object
jason.asSemantics.Agent
- All Implemented Interfaces:
ToDOM
,Serializable
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 Summary
Modifier and TypeFieldDescriptionprotected String
protected BeliefBase
protected Logger
protected PlanLibrary
protected TransitionSystem
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes all occurrences of bel in BB.boolean
Adds bel in belief base (calling brf) and generates the events.void
addFunction
(Class<? extends ArithFunction> c) register an arithmetic function implemented in Javavoid
addFunction
(String function, int arity, String literal) register an arithmetic function implemented in AS (by a rule, literal, or internal action)void
Belief b will be stored to be included as an ordinary belief when the agent will start running.protected void
void
add the initial beliefs in BB and produce the corresponding eventsvoid
goal g will be stored to be included as an initial goal when the agent will start runningprotected void
void
includes all initial goals in the agent reasonervoid
applicablePlans
(List<Option> rp) boolean
believes
(LogicalFormula bel, Unifier un) Returns true if BB contains the literal bel (using unification to test).This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.This function should revise the belief base with the given literal to add, to remove, and the current intention that triggered the operation.int
buf
(Collection<Literal> percepts) Belief Update Function: adds/removes percepts into belief base.void
Clear Agent's Beliefs and Plan LibraryClone BB, PL, Circumstance.static Agent
Set up the default agent configuration.boolean
If the agent believes in bel, removes it (calling brf) and generate the event.Find a literal in BB using unification to test.Gets the agent program (Beliefs and plans) as XMLGets the agent "mind" (beliefs, plans, and circumstance) as XMLGets the agent "mind" as XMLReturns the .asl file source used to create this agentgetBB()
getFunction
(String function, int arity) get the object the implements the arithmetic function function/arity, either global (like math.max) or local (like .count).getPL()
static ScheduledExecutorService
getTS()
boolean
void
Imports beliefs, plans and initial goals from another agent.void
initAg()
Initialises the TS and other components of the agentinitAg
(AgArch arch, BeliefBase bb, String asSrc, Settings stts) Deprecated.Prefer the initAg method with only the source code of the agent as parameter.void
Deprecated.use initAg() and load(src)void
boolean
Returns true if this agent accepts to be killed by another agent called agName.void
Deprecated.void
Deprecated.void
parse and load some agent code, asSrc may be null it does not load kqml default plans and does not trigger initial beliefs and goalsvoid
loadInitialAS
(String asSrc) parse and load the initial agent code + kqml plans + project bels and goals, asSrc may be nullvoid
parse and load asl codevoid
Adds beliefs and plans form a filevoid
parseAS
(InputStream asIn, String sourceId) void
void
Adds beliefs and plans form an URLvoid
relevantPlans
(Trigger teP, Event evt) selectAction
(Queue<ActionExec> actions) selectEvent
(Queue<Event> events) selectIntention
(Queue<Intention> intentions) selectMessage
(Queue<Message> messages) selectOption
(List<Option> options) void
void
setBB
(BeliefBase bb) void
setConsiderToAddMIForThisAgent
(boolean add) void
setIA
(String iaName, InternalAction ia) void
void
setPL
(PlanLibrary pl) void
TS Initialisation (called by the AgArch)boolean
Follows the default implementation for the agent's message acceptance relation and selection functionsvoid
stopAg()
toString()
-
Field Details
-
bb
-
pl
-
ts
-
aslSource
-
logger
-
-
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
parse and load the initial agent code + kqml plans + project bels and goals, asSrc may be null- Throws:
Exception
-
loadAS
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
parse and load asl code- Throws:
Exception
-
clearAgMemory
public void clearAgMemory()Clear Agent's Beliefs and Plan Library -
stopAg
public void stopAg() -
clone
Clone BB, PL, Circumstance. A new TS is created (based on the cloned circumstance). -
cloneInto
-
setLogger
-
getLogger
-
getScheduler
-
getASLSrc
Returns the .asl file source used to create this agent -
setASLSrc
-
parseAS
Adds beliefs and plans form an URL- Throws:
Exception
-
parseAS
- Throws:
Exception
-
parseAS
Adds beliefs and plans form a file- Throws:
Exception
-
parseAS
- Throws:
ParseException
JasonException
-
parseAS
- Throws:
ParseException
JasonException
-
getIA
-
setIA
-
initDefaultFunctions
public void initDefaultFunctions() -
addFunction
register an arithmetic function implemented in Java -
addFunction
register an arithmetic function implemented in AS (by a rule, literal, or internal action) -
getFunction
get the object the implements the arithmetic function function/arity, either global (like math.max) or local (like .count). -
addInitialBel
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
-
addInitialBelsInBB
add the initial beliefs in BB and produce the corresponding events- Throws:
JasonException
-
addInitialBelsFromProjectInBB
protected void addInitialBelsFromProjectInBB() -
addInitialGoal
goal g will be stored to be included as an initial goal when the agent will start running -
getInitialGoals
-
addInitialGoalsInTS
public void addInitialGoalsInTS()includes all initial goals in the agent reasoner -
addInitialGoalsFromProjectInBB
protected void addInitialGoalsFromProjectInBB() -
importComponents
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
Follows the default implementation for the agent's message acceptance relation and selection functions -
killAcc
Returns true if this agent accepts to be killed by another agent called agName. This method can be overridden to customize this option. -
selectEvent
-
selectOption
- Throws:
NoOptionException
-
selectIntention
-
selectMessage
-
selectAction
-
relevantPlans
- Throws:
JasonException
-
applicablePlans
- Throws:
JasonException
-
setTS
TS Initialisation (called by the AgArch) -
getTS
-
setBB
-
getBB
-
setPL
-
getPL
-
buf
Belief Update Function: adds/removes percepts into belief base.- Returns:
- the number of changes (add + dels)
-
believes
Returns true if BB contains the literal bel (using unification to test). The unifier un is updated by the method. -
findBel
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
Adds bel in belief base (calling brf) and generates the events. If bel has no source, addsource(self)
. (the belief is not cloned!)- Throws:
RevisionFailedException
-
delBel
If the agent believes in bel, removes it (calling brf) and generate the event.- Throws:
RevisionFailedException
-
abolish
Removes all occurrences of bel in BB. If un is null, an empty Unifier is used.- Throws:
RevisionFailedException
-
hasCustomSelectOption
public boolean hasCustomSelectOption() -
getAgState
Gets the agent "mind" (beliefs, plans, and circumstance) as XML -
toString
-
getAsDOM
Gets the agent "mind" as XML -
getAgProgram
Gets the agent program (Beliefs and plans) as XML -
initAg
Deprecated.use initAg() and load(src)parse and load the agent code, asSrc may be null- Throws:
Exception
-
load
Deprecated.- Throws:
Exception
-
loadAgSrc
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 likeTransitionSystem ts = ag.initAg(arch, bb, asSrc, stts)
can be replaced bynew 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
-