Skip to content

Commit

Permalink
Merge pull request #813 from trueagi-io/edit_listening_agent
Browse files Browse the repository at this point in the history
Edit listening agent
  • Loading branch information
Necr0x0Der authored Dec 16, 2024
2 parents b0b92c4 + b236879 commit b0f0a02
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions python/hyperon/exts/agents/agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def __init__(self, path=None, atoms={}, include_paths=None, code=None):
super().__init__(path, atoms, include_paths, code)
self.messages = Queue()
self.running = False
self._output = []
self._output = Queue()
self.lock = threading.RLock()
self.said = False

def start(self, *args):
if not args:
Expand All @@ -186,26 +187,42 @@ def start(self, *args):
st.start()

def message_processor(self, message, *args):
return []
yield None

def handle_event(self):
pass

def messages_processor(self, *args):
while self.running:
self.handle_event()
if not self.messages.empty():
m = self.messages.get()
self.clear_output()
with self.lock:
self._output = self.message_processor(m, *args)
m = self.messages.get()
self.said = False
for resp in self.message_processor(m, *args):
with self.lock:
self._output.put(resp)
return []

def stop(self):
self.running = False
return []

def input(self, msg):
self.messages.put(msg)
with self.lock:
self.messages.put(msg)
return []

def get_output(self):
return self._output
while not self._output.empty():
with self.lock:
self.said = True
yield self._output.get()

def clear_output(self):
with self.lock:
self._output = Queue()

@register_atoms(pass_metta=True)
def agent_atoms(metta):
Expand Down

0 comments on commit b0f0a02

Please sign in to comment.