Knowledge-Based
Agents
Chapter7.1-7.3
SomematerialadoptedfromnotesbyAndreasGeyer-SchulzandChuckDyer
BigIdea
• Drawingreasonableconclusionsfrom
asetofdata(observaEons,beliefs,etc.)seems
keytointelligence
• Logicisapowerfulandwelldeveloped
approachtothisandhighlyregardedbypeople
• Logicisalsoastrongformalsystemthat
computerstouse(cf.JohnMcCarthy)
• WecansolvesomeAIproblemsbyrepresentingtheminlogicandapplyingstandardproof
techniquestogeneratesoluEons
InferenceinPeople
• Peoplecandologicalinference,butare
notverygoodatit
• ReasoningwithnegaEonand
disjuncEonseemstobeparEcularly
difficult
• But,peopleseemtoemploymany
kindsofreasoningstrategies,mostof
whichareneithercompletenorsound
3
ThinkingFastandSlow
• Apopular2011bookbyaNobel
prizewinningauthor
• Hismodelisthatwehave2differenttypesofreasoningfaciliEes
• System1operatesautomaEcally
andquickly,withliXleornoeffort
andnosenseofvoluntarycontrol
• System2allocatesaXenEonto
theefforYulmentalacEviEesthat
demandit,includingcomplex
computaEons
QuesBon#1
Hereisasimplepuzzle.
Donottrytosolveitbutlistentoyour
intuiEon:
Abatandballcost$1.10.
Thebatcostsonedollarmorethantheball.
Howmuchdoestheballcost?
Theballcosts$0.05.
QuesBon#2
Trytodetermine,asquicklyasyoucan,ifthe
argumentislogicallyvalid.Doesthe
conclusionfollowthepremises?
Allrosesareflowers.
Someflowersfadequickly.
Thereforesomerosesfadequickly.
Itispossiblethattherearenoroses
amongtheflowersthatfadequickly.
QuesBon#3
Ifittakes5machines5minutestomake5
widgets,
howlongwouldittake100machinestomake
100widgets?
100minutesor5minutes?
5minutes
WasonSelecBonTask
• Ihaveapackofcards;eachhasaleXerwriXen
ononesideandanumberontheother
• Iclaimthefollowingruleistrue:
Ifacardhasavowelononeside,thenithas
anevennumberontheother
• Forthesecards,whichshouldyouturnoverin
ordertodecidewhethertheruleistrueor
false?
E 4 T 7
Wikipedia
WasonSelecBonTask
• Wason(1966)showedthatpeoplearebadat
thistask
• TodisproveruleP=>Q,findasituaEonin
whichPistruebutQisfalse,i.e.,showP^~Q
• Todisprovevowel=>even,findacardwitha
vowelandanoddnumber
• Thus,turnoverthecardsshowingvowelsand
turnovercardsshowingoddnumbers
E 4 T 7
WasonSelecBonTask
• Thisversioniseasierforpeople,asshown
byGriggs&Cox,1982
• Youarethebouncerinabar;whichofthese
peopledoyoucardgiventherule:Youmust
be21oroldertodrinkbeer.
beer coke
22
20
• Perhapseasierbecauseit’smorefamiliaror
becausepeoplehavespecialstrategiesto
reasonaboutcertainsituaEons,suchas
cheaEnginasocialsituaEon
13
NegaBoninNaturalLanguage
• Weooenmodelthemeaningofnatural
languagesentencesasalogicstatements
• Thismapstheseintoequivalentstatements
– Allelephantsaregray
– Noelephantarenotgray
• DoublenegaEoniscommonininformal
language:thatwon’tdoyounogood
• Butwhatdoesthismean:wecannot
underes?matetheimportanceoflogic
LogicasaMethodology
Evenifpeopledon’tuseformallogicalreasoningforsolvingaproblem,logicmightbeagood
approachforAIforanumberofreasons
– Airplanesdon’tneedtoflaptheirwings
– LogicmaybeagoodimplementaEonstrategy
– SoluEoninaformalsystemcanofferother
benefits,e.g.,lerngusproveproperEesofthe
approach
• Seeneatsvs.scruffies
Knowledge-basedagents
• Knowledge-basedagentshaveaknowledgebase
(KB)andaninferencesystem
• AKBisasetofrepresentaEonsoffactsbelieved
true
• EachindividualrepresentaEoniscalledasentence
• SentencesareexpressedinaknowledgerepresentaBonlanguage
• Theagentoperatesasfollows:
1.ItTELLstheKBwhatitperceives
2.ItASKstheKBwhatacEonitshouldperform
3.ItperformsthechosenacEon
ArchitectureofaKBagent
• KnowledgeLevel
– Themostabstractlevel:describeagentbysaying
whatitknows
– Ex:AtaxiagentmightknowthattheGoldenGateBridge
connectsSanFranciscowiththeMarinCounty
• LogicalLevel
– Thelevelatwhichtheknowledgeisencodedintosentences
– Ex:links(GoldenGateBridge,SanFrancisco,MarinCounty)
• ImplementaBonLevel
– PhysicalrepresentaEonofthesentencesinthelogicallevel
– Ex:asatupleserializedas(links goldengatebridge
sanfrancisco marincounty)
WumpusWorldenvironment
• BasedonHunttheWumpuscomputergame
• Agentexploresacaveofroomsconnected
bypassageways
• LurkinginaroomistheWumpus,abeast
thateatsanyagentthatentersitsroom
• SomeroomshaveboAomlesspitsthattrap
anyagentthatwandersintotheroom
• Somewhereisaheapofgoldinaroom
• Goalistocollectgoldandexitw/obeing
eatenbyWumpus
Jargonfileon“HunttheWumpus”
WUMPUS/wuhm'p*s/n.Thecentralmonster(and,inmanyversions,the
name)ofafamousfamilyofveryearlycomputergamescalled“HuntThe
Wumpus,”daEngbackatleastto1972(severalyearsbeforeADVENT)onthe
DartmouthTime-SharingSystem.Thewumpuslivedsomewhereinacavewith
thetopologyofadodecahedron'sedge/vertexgraph(laterversionssupported
othertopologies,includinganicosahedronandMobiusstrip).Theplayer
startedsomewhereatrandominthecavewithfive“crookedarrows”;these
couldbeshotthroughuptothreeconnectedrooms,andwouldkillthewumpus
onahit(laterversionsintroducedthewoundedwumpus,whichgotvery
angry).Unfortunatelyforplayers,themovementnecessarytomapthemaze
wasmadehazardousnotmerelybythewumpus(whichwouldeatyouifyou
steppedonhim)butalsobyboXomlesspitsandcoloniesofsuperbatsthat
wouldpickyouupanddropyouatarandomlocaEon(laterversionsadded
“anaerobictermites”thatatearrows,batmigraEons,andearthquakesthat
randomlychangedpitlocaEons).
Thisgameappearstohavebeenthefirsttouseanon-randomgraphstructuredmap(asopposedtoarectangulargridliketheevenolderStarTrek
games).Inthisrespect,asinthedungeon-likesernganditsterse,amusing
messages,itprefiguredADVENTandZorkandwasdirectlyancestraltoboth.
(Zorkacknowledgedthisheritagebyincludingasuper-batcolony.)Today,aport
isdistributedwithSunOSandasfreewarefortheMac.ACemulaEonofthe
originalBasicgameisincirculaEonasfreewareonthenet.
WumpusHistory
• SeeHunt_the_Wumpusfor
details
• Early(c.1972)text-basedgame
wriXeninBASICwriXenbyGregoryYob,astudent
atUMASS,Dartmouth
• Definedagenreofgamesincludingadventure,
zork,andnethack
• Eventuallycommercialized(c.1980)forearly
personalcomputers
• TheHunttheWumpusbasiccodeisavailableina
1976arEcleinCreaEveCompuEngbyYob!
AIMA’sWumpusWorld
Theagentalways
startsinthefield
[1,1]
Agent’staskistofind
thegold,returnto
thefield[1,1]and
climboutofthecave
AgentinaWumpusworld:Percepts
• Theagentperceives
– stenchinsquarecontainingWumpusandinadjacent
squares(notdiagonally)
– breezeinsquaresadjacenttoapit
– gliXerinthesquarewherethegoldis
– bump,ifitwalksintoawall
– Woefulscreameverywhereincave,ifWumpusiskilled
• Perceptsgivenasfive-tuple,e.g.,ifstenchand
breeze,butnogliXer,bumporscream:
[Stench,Breeze,None,None,None]
• AgentcannotperceiveitsownlocaEon(e.g.,in
(2,2)
WumpusWorldAcBons
• goforward
• turnright90degrees
• turnleY90degrees
• grab:Pickupobjectinsamesquareasagent
• shoot:FirearrowinstraightlineindirecEonagentis
facing.ItconEnuesunElithitsandkillsWumpusorhits
outerwall.Agenthasonlyonearrow,soonlyfirstshoot
acEonhaseffect
• climbisusedtoleavecave,onlyeffecEveinstartsquare
• die:ThisacEonautomaEcallyandirretrievablyhappens
ifagententerssquarewithpitorliveWumpus
WumpusWorldGoal
Agent’sgoalistofindthegoldandbring
itbacktothestartsquareasquicklyas
possible,withoutgerngkilled
– 1,000pointrewardforclimbingoutof
cavewithgold
– 1pointdeductedforeveryacEontaken
– 10,000pointpenaltyforgerngkilled
WumpusworldcharacterizaBon
• FullyObservable?
• DeterminisBc?
• Episodic?
• StaBc?
• Discrete?
• Single-agent?
WumpusworldcharacterizaBon
• FullyObservableNo–onlylocalpercepEon
• DeterminisBcYes,outcomesexactlyspecified
• EpisodicNo–sequenEalatthelevelofacEons
• StaBcYes–WumpusandPitsdonotmove
• DiscreteYes
• Single-agent?Yes,WumpusisessenEallya
naturalfeature
AIMA’sWumpusWorld
Theagentalways
startsinthefield
[1,1]
Agent’staskistofind
thegold,returnto
thefield[1,1]and
climboutofthecave
TheHunter’sfirststep
¬W
¬W
Sinceagentisaliveandperceives
neitherbreezenorstenchat[1,1],it
knowsthat[1,1]anditsneighborsare
OK
Movingto[2,1]isasafemovethat
revealsabreezebutnostench,implying
thatWumpusisnotadjacentbutthat
oneormorepitsare
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
Exploringawumpusworld
P?
P?
A
B
G
OK
P
S
W
agent
breeze
glitter
safe cell
pit
stench
wumpus
WumpusWorldgamesonline
• AIMAcode
– Python
– Lisp
• hXp://scv.bu.edu/cgi-bin/wcl–Web-based
versionyoucanplay
• hXp://codenauEcs.com/wumpus/-Mac
version
Logicingeneral
• LogicsareformallanguagesforrepresenEng
informaEonsuchthatconclusionscanbedrawn
• Syntaxdefinesthesentencesinthelanguage
• SemanBcsdefinethe"meaning"ofsentences
– i.e.,definetruthofasentenceinaworld
E.g.,thelanguageofarithmeEc
• x+2≥yisasentence;x2+y>{}isnotasentence
• x+2≥yistrueiffthenumberx+2isnolessthan
thenumbery
• x+2≥yistrueinaworldwherex=7,y=1
• x+2≥yisfalseinaworldwherex=0,y=6
• x+1>xistrueforallnumbersx
Entailment
• Entailmentmeansthatonethingfollows
fromanother:
• KB╞α
• KnowledgebaseKBentailssentenceαiffαis
trueinallpossibleworldswhereKBistrue
– E.g.,theKBcontaining“UMBCwon”and“JHU
won”entails“EitherUMBCwonorJHUwon”
– E.g.,x+y=4entails4=x+y
– EntailmentisarelaEonshipbetweensentences
(i.e.,syntax)thatisbasedonsemanBcs
Models
• Logicianstypicallythinkintermsofmodels:
formallystructuredworldsw.r.twhichtruthcan
beevaluated
• misamodelofsentenceαifαistrueinm
• M(α)isthesetofallmodelsofα
• ThenKB╞αiffM(KB)⊆M(α)
– KB=UMBCandJHUwon
– α=UMBCwon
– ThenKB╞α
Entailmentinthewumpusworld
• SituaEonaoerdetecEngnothing
in[1,1],movingright,breezein
[2,1]
• PossiblemodelsforKBassuming
onlypitsandrestricEngcellsto
{(1,3)(2,1)(2,2)}
• TwoobservaEons:~B11,B12
• ThreeproposiEonalvariables
variables:P13,P21,P22
• ⇒8possiblemodels
B11:breezein(1,1)
P13:pitin(1,3)
Wumpusmodels
P13
P21
P22
F
F
F
F
F
T
F
T
F
F
T
T
T
F
F
T
F
T
T
T
F
T
T
T
Eachrowisa
possibleworld
WumpusWorldRules(1)
• Ifacellhasapit,thenabreezeisobservable
ineveryadjacentcell
• InproposiEonalcalculuswecannothave
ruleswithvariables(e.g.,forallX…)
P11=>B21
P11=>B12
P21=>B11
P21=>B22…
Ifapitin(1,1)thena
breezein(2,1),…
thesealsofollow
~B21=>~P11
~B12=>~P11
~B11=>~P21
~B22=>~P21
…
Onlythreeofthe
possiblemodelsare
consistentwithwhat
weknow
Wumpusmodels
KB=wumpus-worldrules+observaEons
WumpusWorldRules(2)
• Cellsafeifithasneitherapitorwumpus
OK11=>~P11∧~W11
OK12=>~P12∧~W12…
• Fromwhichwecanderive
P11∨W11=>~OK11
P11=>~OK11
W11=>~OK11…
OK11:(1,1)issafe
W11:Wumpusin(1,1)
Wumpusmodels
•
•
•
•
KB=wumpus-worldrules+observaEons
α1=“[1,2]issafe”
Sinceallmodelsincludeα1
KB╞α1,provedbymodelchecking
Wumpusmodels
• KB=wumpus-worldrules+observaEons
Is(2,2)Safe?
•
•
•
•
KB=wumpus-worldrules+observaEons
α2="[2,2]issafe"
Sincesomemodelsdon’tincludeα2,KB╞α2
WecannotproveOK22;itmightbetrueorfalse.
Inference,Soundness,Completeness
• KB├iα=sentenceαcanbederivedfrom
KBbyprocedurei
• Soundness:iissoundifwheneverKB├iα,
itisalsotruethatKB╞α
• Completeness:iiscompleteifwhenever
KB╞α,itisalsotruethatKB├iα
• Preview:first-orderlogicisexpressive
enoughtosayalmostanythingofinterest
andhasasoundandcompleteinference
procedure
RepresentaBon,reasoning,andlogic
• ObjectofknowledgerepresentaEon(KR):express
knowledgeinacomputer-tractableform,sothat
agentscanperformwell
• AKRlanguageisdefinedby:
– Syntax:definesallpossiblesequencesofsymbols
thatconsEtutesentencesofthelanguage
• Ex:Sentencesinabook,bitpaXernsincomputermemory
– SemanBcs:determinesfactsintheworldtowhich
thesentencesrefer
• Eachsentencemakesaclaimabouttheworld.
• Anagentissaidtobelieveasentenceabouttheworld.
TheconnecBonbetweensentencesandfacts
Seman?csmapssentencesinlogictofactsintheworld.
Thepropertyofonefactfollowingfromanotherismirrored
bythepropertyofonesentencebeingentailedbyanother.
Soundnessandcompleteness
• Asoundinferencemethodderivesonly
entailedsentences
• Analogoustothepropertyofcompleteness
insearch,acompleteinferencemethodcan
deriveanysentencethatisentailed
LogicasaKRlanguage
MulE-valued
Logic
ProbabilisEc
Logic
Fuzzy
Logic
Modal
Temporal
HigherOrder
FirstOrder
ProposiEonalLogic
Non-monotonic
Logic
Ontologyandepistemology
• Ontologyisthestudyofwhatthereis—aninventory
ofwhatexists.Anontologicalcommitmentisa
commitmenttoanexistenceclaim.
• Epistemologyisamajorbranchofphilosophythat
concernstheforms,nature,andprecondiEonsof
knowledge.
Noindependentaccesstotheworld
• Reasoningagentsooengetsknowledgeaboutfacts
oftheworldasasequenceoflogicalsentencesand
mustdrawconclusionsonlyfromthemw/o
independentaccesstoworld
• Thus,itisveryimportantthattheagents’reasoning
issound!
Summary
• Intelligentagentsneedknowledgeaboutworldforgood
decisions
• Agent’sknowledgestoredinaknowledgebase(KB)as
sentencesinaknowledgerepresentaEon(KR)language
• Aknowledge-basedagentneedsaKBandaninference
mechanism.ItoperatesbystoringsentencesinitsKB,
inferringnewsentencesandusingthemtodeducewhich
acEonstotake
• ArepresentaBonlanguageisdefinedbyitssyntaxand
semanEcs,whichspecifystructureofsentencesandhow
theyrelatetofactsoftheworld
• TheinterpretaBonofasentenceisfacttowhichitrefers.If
thefactispartoftheactualworld,thenthesentenceistrue
© Copyright 2026 Paperzz