repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Mirrored from https://github.com/yingqi-z20/Agent-libOS
stars
latest
clone command
git clone gitlawb://did:key:z6MkqRzA...RfoM/yingqi-z20-Agen...git clone gitlawb://did:key:z6MkqRzA.../yingqi-z20-Agen...d98dd2c9IPC1d ago| #1 | from __future__ import annotations |
| #2 | |
| #3 | import unittest |
| #4 | |
| #5 | from agent_libos.llm.tool_protocol import tool_call_to_action |
| #6 | |
| #7 | |
| #8 | class ToolProtocolTests(unittest.TestCase): |
| #9 | def test_tool_name_wins_over_action_argument(self) -> None: |
| #10 | action = tool_call_to_action( |
| #11 | { |
| #12 | "name": "read_directory", |
| #13 | "arguments": '{"action": "delete_directory", "path": "."}', |
| #14 | } |
| #15 | ) |
| #16 | |
| #17 | self.assertEqual(action, {"action": "read_directory", "path": "."}) |
| #18 | |
| #19 | def test_empty_tool_name_can_use_fallback_action_argument(self) -> None: |
| #20 | action = tool_call_to_action( |
| #21 | { |
| #22 | "name": "", |
| #23 | "arguments": '{"action": "read_directory", "path": "."}', |
| #24 | } |
| #25 | ) |
| #26 | |
| #27 | self.assertEqual(action, {"action": "read_directory", "path": "."}) |
| #28 | |
| #29 | def test_empty_tool_name_without_fallback_is_rejected(self) -> None: |
| #30 | with self.assertRaises(ValueError): |
| #31 | tool_call_to_action({"name": "", "arguments": '{"path": "."}'}) |
| #32 | |
| #33 | def test_falsey_non_object_arguments_are_rejected(self) -> None: |
| #34 | for arguments in ([], 0, False): |
| #35 | with self.subTest(arguments=arguments): |
| #36 | with self.assertRaises(ValueError): |
| #37 | tool_call_to_action({"name": "read_directory", "arguments": arguments}) |
| #38 | |
| #39 | def test_none_or_empty_arguments_default_to_empty_object(self) -> None: |
| #40 | self.assertEqual(tool_call_to_action({"name": "get_current_time", "arguments": None}), {"action": "get_current_time"}) |
| #41 | self.assertEqual(tool_call_to_action({"name": "get_current_time", "arguments": ""}), {"action": "get_current_time"}) |
| #42 | |
| #43 | |
| #44 | if __name__ == "__main__": |
| #45 | unittest.main() |
| #46 |