Skip to content

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

Draft
nickhuo wants to merge 1 commit into
mainfrom
nickhuo/can-289-entrypoint-relative-imports
Draft

Load nested agent entrypoints with a dotted module name (CAN-289)#81
nickhuo wants to merge 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.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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
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