From 18879b7258264b34ca4eae4d689d1db568c57218 Mon Sep 17 00:00:00 2001 From: Nick Huo Date: Wed, 9 Sep 2026 14:54:12 -0700 Subject: [PATCH] Load nested agent entrypoints with a dotted module name _load_agent derived the module name for spec_from_file_location by stripping .py from the entrypoint path, leaving directory separators intact (e.g. "agents/aml_agent"). Without dots, Python can't establish __package__, so any relative import inside a nested entrypoint (e.g. `from .prompts import PROMPT`) fails with "attempted relative import with no known parent package" at agent load, surfacing as "No agent loaded" at serve time. Convert path separators to dots so __package__ resolves correctly and sibling relative imports work. Co-Authored-By: Claude Sonnet 5 --- canyonos_core/controller/local_controller.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/canyonos_core/controller/local_controller.py b/canyonos_core/controller/local_controller.py index a3406c2..f2d85dd 100644 --- a/canyonos_core/controller/local_controller.py +++ b/canyonos_core/controller/local_controller.py @@ -194,7 +194,12 @@ def _load_agent(self): ) return None - agent_module_name = self.agent_file.replace(".py", "") + # Use a dotted module name (e.g. "agents.aml_agent", not "agents/aml_agent") + # so importlib derives __package__ correctly and package-relative imports + # inside nested entrypoints (e.g. `from .prompts import PROMPT`) resolve. + agent_module_name = ( + self.agent_file.replace(".py", "").replace(os.sep, ".").replace("/", ".") + ) # We assume the agent file is in the same directory as the local controller (e.g. copied by Docker) # or in the current working directory.