Skip to content

Commit 122e0fd

Browse files
Add blocklist to Blackboard 'text_snapshot()' (#13)
* Tests fot Blackboard text_snapshot Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Add blocked keys to text_snapshot blackboard Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Print with proper method output Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Clean comments Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> * Review Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com> --------- Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent 7d34cb9 commit 122e0fd

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/vulcanai/console/console.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ def worker(user_input: str = "") -> None:
348348

349349
# Print the backboard state
350350
bb_ret = result.get("blackboard", None)
351-
bb_ret = str(bb_ret).replace("<", "'").replace(">", "'")
352-
self.logger.log_console(f"Output of plan: {bb_ret}")
351+
if bb_ret:
352+
bb_ret = bb_ret.text_snapshot().replace("<", "'").replace(">", "'")
353+
self.logger.log_console(f"Output of plan: {bb_ret}")
353354

354355
except KeyboardInterrupt:
355356
self.logger.log_msg("<yellow>Exiting...</yellow>")

src/vulcanai/console/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def _on_done(task: asyncio.Task) -> None:
216216
asyncio.get_running_loop()
217217
except RuntimeError:
218218
# No loop here → probably ROS thread. Bounce into Textual thread.
219-
# `console.app` is your Textual App instance.
220219
console.app.call_from_thread(_launcher)
221220
else:
222221
# We *are* in the loop → just launch directly.
@@ -289,7 +288,6 @@ def _get_suggestions(real_string_list_comp: list[str], string_comp: str) -> tupl
289288
return most_topic_similar, ret_list
290289

291290
if input_string not in real_string_list:
292-
# console.add_line(f"{tool_header_str} {string_name}: \"{input_string}\" does not exists")
293291
console.logger.log_tool(f'{string_name}: "{input_string}" does not exists', tool_name=tool_name)
294292

295293
# Get the suggestions list sorted by similitud value

src/vulcanai/core/executor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@
3333
class Blackboard(dict):
3434
"""Shared memory for passing outputs between steps."""
3535

36+
_default_blocked_keys = {"main_node", "console"}
37+
3638
def text_snapshot(self, keys: Optional[List[str]] = None) -> str:
3739
"""
3840
Return a string representing the blackboard.
3941
40-
:param keys: Optional list of keys to include. If None, include all.
42+
:param keys: Optional list of keys to include. If None, include all except default blocked keys.
4143
:return: A string representation of the blackboard entries.
4244
"""
4345
snapshot = {}
44-
keyset: Set[str] = set(keys) if keys is not None else set(self.keys())
46+
keyset: Set[str] = set(keys) if keys is not None else set(self.keys() - self._default_blocked_keys)
4547
filtered = {k: self.get(k) for k in keyset if k in self}
4648

4749
for k, v in filtered.items():

tests/unittest/test_executor.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,50 @@ def test_types_substitution_is_respected(self):
801801
self.assertEqual(bb["add"]["result"], 8.5)
802802
self.assertTrue(isinstance(bb["add"]["result"], float))
803803

804+
def test_default_blocked_keys_in_output(self):
805+
"""
806+
Test that default keys are blocked and not printed.
807+
"""
808+
executor_mod = importlib.import_module("vulcanai.core.executor")
809+
blackboard_class = executor_mod.Blackboard
810+
811+
test_bb = blackboard_class()
812+
813+
test_bb["speak"] = True
814+
test_bb["main_node"] = "This should not be printed"
815+
test_bb["console"] = "This should not be printed either"
816+
self.assertIn("speak", test_bb)
817+
self.assertIn("main_node", test_bb)
818+
self.assertIn("console", test_bb)
819+
string_output = test_bb.text_snapshot()
820+
self.assertIn("speak", string_output)
821+
self.assertNotIn("main_node", string_output)
822+
self.assertNotIn("console", string_output)
823+
824+
def test_text_snapshot_select_keys_when_given(self):
825+
"""
826+
Test that the text_snapshot method of the blackboard properly filters by the provided keys.
827+
"""
828+
executor_mod = importlib.import_module("vulcanai.core.executor")
829+
blackboard_class = executor_mod.Blackboard
830+
831+
test_bb = blackboard_class()
832+
833+
test_bb["speak"] = True
834+
test_bb["another_potential_tool"] = "Random text"
835+
test_bb["other_tool"] = "Whatever output"
836+
self.assertIn("speak", test_bb)
837+
self.assertIn("another_potential_tool", test_bb)
838+
self.assertIn("other_tool", test_bb)
839+
string_output = test_bb.text_snapshot(keys=["speak"])
840+
self.assertIn("speak", string_output)
841+
self.assertNotIn("another_potential_tool", string_output)
842+
self.assertNotIn("other_tool", string_output)
843+
string_output = test_bb.text_snapshot(keys=["other_tool", "another_potential_tool"])
844+
self.assertNotIn("speak", string_output)
845+
self.assertIn("another_potential_tool", string_output)
846+
self.assertIn("other_tool", string_output)
847+
804848

805849
if __name__ == "__main__":
806850
unittest.main()

0 commit comments

Comments
 (0)