INNER CODE UNIT · Python
_load_module
omnirexflora-labs/omnicoreagent · src/omnicoreagent/serve/cli.py:62
def _load_module(path: str):
"""
Load an agent module from a Python file.
The file should define an `agent` variable or an `create_agent()` function.
"""
file_path = Path(path).resolve()
if not file_path.exists():
raise click.ClickException(f"Agent file not found: {path}")
# Load the module
spec = importlib.util.spec_from_file_location("agent_module", file_path)
if spec is None or spec.loader is None:
raise click.ClickException(f"Failed to load module from: {path}")
module = importlib.util.module_from_spec(spec)
sys.modules["agent_module"] = module