Skip to content

fix(utils,datagen): make advertised __all__ names importable - #4403

Open
jayfeng7 wants to merge 1 commit into
camel-ai:masterfrom
jayfeng7:fix/all-exports-unimportable
Open

jayfeng7 wants to merge 1 commit into
camel-ai:masterfrom
jayfeng7:fix/all-exports-unimportable

Conversation

@jayfeng7

Copy link
Copy Markdown

Closes #4402

Description

Two names advertised in submodule __all__ lists could not be resolved at import time:/n/n- camel.datagen.evol_instruct.__all__ advertised MathEvolInstructTemplates (defined in templates.py) without importing it — from camel.datagen.evol_instruct import * raised AttributeError, direct import raised ImportError.

  • camel.utils.__all__ advertised generate_prompt_for_structured_output (defined in utils/commons.py) without including it in the from .commons import (...) block — direct import raised ImportError.

__all__ is a runtime contract (star imports resolve every entry with getattr), so both failures hit callers directly. Confirmed on camel-ai==0.2.90 from PyPI.

This PR adds the two missing imports and extends test/test_all_exports.py — which previously pinned only the root package — with star-import resolution checks for both submodules, so the same regression class cannot silently return.

Note: the phantom DescriptionVideoPromptTemplateDict entry in camel.prompts.__all__ is intentionally not touched here, as it is already covered by #3810.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Verification

Red (before, camel-ai==0.2.90 PyPI wheel, Python 3.11.8):

>>> from camel.utils import generate_prompt_for_structured_output
ImportError: cannot import name 'generate_prompt_for_structured_output' from 'camel.utils'
>>> from camel.datagen.evol_instruct import *
AttributeError: module 'camel.datagen.evol_instruct' has no attribute 'MathEvolInstructTemplates'

Green (this branch, installed into the same environment):

>>> from camel.utils import generate_prompt_for_structured_output   # OK
>>> from camel.datagen.evol_instruct import *                        # OK, MathEvolInstructTemplates resolves
>>> pytest test/test_all_exports.py -v
4 passed

The two new tests cover both submodules; the two pre-existing tests in the file keep passing.

Checklist

  • I have read and agree to the AI-Generated Code Policy (required)
  • I have linked this PR to an issue (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and run uv lock — no dependency changes
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed — no docs impact
  • I have added examples if this is a new feature — not applicable

AI assistance disclosure

Tool(s) used: AI coding assistant (agentic coding session).

How you used it: The assistant located the two defects via a static __all__ audit, produced the two import additions and the regression tests, and ran the red/green verification shown above against the PyPI wheel. I have read and understand every line of the change, reproduced both failures independently, and take full responsibility for the diff.

camel.utils.__all__ advertised generate_prompt_for_structured_output
without importing it from .commons, and
camel.datagen.evol_instruct.__all__ advertised
MathEvolInstructTemplates without importing it from .templates; both
raise at import time (ImportError on direct import, AttributeError on
star import, since star imports resolve __all__ entries with getattr).

Add the two missing imports and extend test/test_all_exports.py (which
previously pinned only the root package) with star-import resolution
checks for both submodules.

AI assistance disclosure: diagnosis, patch and regression tests were
produced with an AI coding assistant; the author reviewed and verified
every line and reproduced the failures on camel-ai==0.2.90 from PyPI.
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb555d25-fa66-41c3-91ef-dc30396ebc3a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@jayfeng7

Copy link
Copy Markdown
Author

Convenience note for whoever reviews this, because the check list reads worse than the diff.

All 6 red checks on this head are structural to fork PRs and cannot be turned green from the author side. I confirmed this from the job logs and annotations rather than guessing:

5 × pytest_* — fail during collection, before any test of this diff runs. Every one exits 2 with ValueError: Missing or empty required API keys in environment variables: OPENAI_API_KEY (and openai.OpenAIError: Missing credentials in the MCP server case). The five modules are test/agents/test_chat_agent.py, test/agents/test_knowledge_agent.py, test/agents/test_role_playing.py, test/services/test_agent_mcp_server.py, test/toolkits/test_function_tool_decorator.py. Repository secrets are not exposed to pull_request runs from a fork, so these jobs cannot pass on jayfeng7:... no matter what the diff contains — and none of those files is touched here (this PR only changes camel/utils/... and camel/datagen/... plus one test file).

1 × add-labels — Unhandled error: HttpError: Resource not accessible by integration. The workflow writes labels with the run's GITHUB_TOKEN, which is read-only on a fork head.

So the signal that actually describes this change is the 7 green checks; the 6 red ones are the environment. If there is a preferred way to get a real pytest signal on a fork head — a label that unlocks secrets, a re-run from the base repo, or a specific module you want exercised — point me at it and I will do that instead of asking you to read around the noise.

For the record, the diff is two import lines plus a test: camel/datagen/evol_instruct/__init__.py lists MathEvolInstructTemplates in __all__ without importing it, and camel/utils/__init__.py lists generate_prompt_for_structured_output without importing it. from camel.utils import * walks __all__ with getattr, so both names raised AttributeError on a star import while the package advertised them as public. The fix adds the two missing imports and a test that asserts every __all__ entry resolves under import *.

This branch has not been deployed

No deployments
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.

__all__ advertises two unimportable names: camel.datagen.evol_instruct.MathEvolInstructTemplates and camel.utils.generate_prompt_for_structured_output

1 participant