Skip to content

Build and run agents you can see, understand and trust.

fix(rag): resolve LOG_LEVEL before configuring the worker (#3131)

sxh9ff248d2ccff
diff --git a/src/agentscope/app/rag/index_worker/__main__.py b/src/agentscope/app/rag/index_worker/__main__.py
index 8addeddfc..05eb3b1a9 100644
--- a/src/agentscope/app/rag/index_worker/__main__.py
+++ b/src/agentscope/app/rag/index_worker/__main__.py
@@ -87,7 +87,7 @@ def main() -> None:
because backend selection is a deployment concern.
"""
logging.basicConfig(
- level=os.environ.get("LOG_LEVEL", "INFO"),
+ level=os.environ.get("LOG_LEVEL", "INFO").strip().upper() or "INFO",
format="%(asctime)s %(levelname)s %(name)s %(message)s",
)
bootstrap_path = os.environ.get("AGENTSCOPE_WORKER_BOOTSTRAP")
diff --git a/tests/index_worker_main_test.py b/tests/index_worker_main_test.py
new file mode 100644
index 000000000..80e977569
--- /dev/null
+++ b/tests/index_worker_main_test.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+"""Unit tests for the index worker entry point."""
+import logging
+import os
+import unittest
+from unittest.mock import patch
+
+from agentscope.app.rag.index_worker.__main__ import main
+
+
+class IndexWorkerMainTest(unittest.TestCase):
+ """Tests for the index worker entry point."""
+
+ def test_lowercase_log_level(self) -> None:
+ """A lowercase ``LOG_LEVEL`` configures logging instead of crashing."""
+ # basicConfig is a no-op while the root logger has handlers
+ handlers, level = logging.root.handlers[:], logging.root.level
+ logging.root.handlers.clear()
+ try:
+ with patch.dict(os.environ, {"LOG_LEVEL": "debug"}, clear=True):
+ with self.assertRaises(SystemExit) as ctx:
+ main()
+ self.assertListEqual(
+ [ctx.exception.code, logging.root.level],
+ [2, logging.DEBUG],
+ )
+ finally:
+ logging.root.handlers[:] = handlers
+ logging.root.setLevel(level)
+
+
+if __name__ == "__main__":
+ unittest.main()