Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit listening agent #813

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading