Skip to content

Load nested agent entrypoints with a dotted module name (CAN-289) - #81

Merged
nickhuo merged 1 commit into
mainfrom
nickhuo/can-289-entrypoint-relative-imports
Sep 10, 2026
Merged

nickhuo merged 1 commit into
mainfrom
nickhuo/can-289-entrypoint-relative-imports

Conversation

@nickhuo

@nickhuo nickhuo commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • _load_agent derived the module name passed to importlib.util.spec_from_file_location by only stripping .py from the entrypoint path (self.agent_file.replace(".py", "")), leaving directory separators intact for nested entrypoints (e.g. agents/aml_agent.py -> "agents/aml_agent").
  • A name with no dots leaves Python unable to establish __package__, so any package-relative import inside a nested entrypoint (e.g. from .prompts import PROMPT in agents/aml_agent.py, a sibling of agents/prompts.py) fails with attempted relative import with no known parent package at agent load — surfacing only as "No agent loaded" at serve time, not at validate or build.
  • Fix: convert path separators to dots before building the module name ("agents.aml_agent"), so __package__ resolves correctly. The file path passed to spec_from_file_location is unchanged — only the module-name string changes.
  • Split out of a branch that also touched unrelated deploy-path bugs (CAN-290/291) and a separate concurrent-dispatch fix (CAN-292, PR Fix concurrent cold-start race on shared agent instance (CAN-292) #80) so this can be reviewed and merged independently.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed loading of agents located in nested package directories.
    • Package-relative imports now work correctly when launching agents from entrypoints in nested folders.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 716b891d-da11-4e68-b45a-dd1426a1726f

📥 Commits

Reviewing files that changed from the base of the PR and between cdd03bc and 18879b7.

📒 Files selected for processing (1)
  • canyonos_core/controller/local_controller.py

📝 Walkthrough

Walkthrough

The local agent loader now converts nested agent file paths into dotted Python module names. This supports package-relative imports in nested agent entrypoints.

Changes

Agent module resolution

Layer / File(s) Summary
Nested module name derivation
canyonos_core/controller/local_controller.py
_load_agent replaces / and os.sep with dots while deriving the module name from the agent path.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: saaketh0

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nickhuo/can-289-entrypoint-relative-imports

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

_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 <noreply@anthropic.com>
@nickhuo
nickhuo force-pushed the nickhuo/can-289-entrypoint-relative-imports branch from fa08b0f to 18879b7 Compare September 9, 2026 22:38
@nickhuo
nickhuo marked this pull request as ready for review September 10, 2026 19:36
@nickhuo
nickhuo merged commit 052833c into main Sep 10, 2026
3 of 5 checks passed
@coderabbitai
coderabbitai Bot requested a review from Saaketh0 September 10, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants