def KB_AgentProgram(KB):
steps = itertools.count()<EOL>def program(percept):<EOL><INDENT>t = next(steps)<EOL>KB.tell(make_percept_sentence(percept, t))<EOL>action = KB.ask(make_action_query(t))<EOL>KB.tell(make_action_sentence(action, t))<EOL>return action<EOL><DEDENT>def make_percept_sentence(self, percept, t):<EOL><INDENT>return Expr("<STR_LIT>")(percept, t)<EOL><DEDENT>def make_action_query(self, t):<EOL><INDENT>return expr("<STR_LIT>" % t)<EOL><DEDENT>def make_action_sentence(self, action, t):<EOL><INDENT>return Expr("<STR_LIT>")(action[expr('<STR_LIT:action>')], t)<EOL><DEDENT>return program<EOL>
A generic logical knowledge-based agent program. [Fig. 7.1]