Skip to content

feat(toolkits): add @dependencies_required and @api_keys_required decorators to toolkits#4056

Open
Mubin-A-Kader wants to merge 4 commits into
camel-ai:masterfrom
Mubin-A-Kader:feat/toolkits-add-dependency-decorators
Open

feat(toolkits): add @dependencies_required and @api_keys_required decorators to toolkits#4056
Mubin-A-Kader wants to merge 4 commits into
camel-ai:masterfrom
Mubin-A-Kader:feat/toolkits-add-dependency-decorators

Conversation

@Mubin-A-Kader

@Mubin-A-Kader Mubin-A-Kader commented May 18, 2026

Copy link
Copy Markdown

Closes #1043

Description

Adds @dependencies_required and @api_keys_required decorators to toolkits in camel.toolkits. Users now get a clear ImportError or ValueError immediately on instantiation or method call instead of a cryptic traceback when required packages or API keys are missing. Follows the same pattern as PR #3992 which did this for embeddings.

Changes

Toolkit Decorator Added
SymPyToolkit @dependencies_required('sympy')
NetworkXToolkit @dependencies_required('networkx')
Crawl4AIToolkit @dependencies_required('crawl4ai')
ExcelToolkit @dependencies_required('pandas', 'openpyxl') on __init__; @dependencies_required('tabulate', 'xls2xlsx') on extract_excel_content
GoogleScholarToolkit @dependencies_required('scholarly') on __init__; @dependencies_required('arxiv2text') on get_full_paper_content_by_link
RedditToolkit @dependencies_required('praw') + @api_keys_required for REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USER_AGENT; @dependencies_required('textblob') on perform_sentiment_analysis
WeatherToolkit @dependencies_required('pyowm') on get_weather_data
SlackToolkit @dependencies_required('slack_sdk') on __init__
OpenAPIToolkit @dependencies_required('prance') on parse_openapi_file
GmailToolkit @dependencies_required('googleapiclient', 'google_auth_oauthlib', 'google.auth', 'google.oauth2', 'dotenv') on _authenticate
EarthScienceToolkit @dependencies_required('numpy', 'rasterio') on __init__; @dependencies_required('scipy') on 6 scipy-using methods

Skipped: JinaRerankerToolkit — dual API/local mode makes a static decorator unsafe (API users would be blocked even though local-model deps aren't needed).

Added/extended test/toolkits/test_toolkits_decorators.py with 19 unit tests total following the same pattern as test/embeddings/test_embeddings_decorators.py from PR #3992. Two helpers (_only_missing, _all_available) isolate method-level decorator checks even when optional deps are absent from the test env.

What is the purpose of this pull request?

  • New Feature

Checklist

  • I have read and agree to the AI-Generated Code Policy
  • I have linked this PR to an issue
  • No new dependencies added to pyproject.toml
  • I have updated the tests accordingly
  • I have updated the documentation if needed
  • I have added examples if this is a new feature

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented May 18, 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: Pro

Run ID: 9a73b6d4-b6f6-46b0-9ba4-0e4863be441d

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@fengju0213

fengju0213 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

@Mubin-A-Kader Thanks for working on the toolkits decorator refactor.

There are still a few missing dependency checks in the files changed by this PR:

  • ExcelToolkit checks pandas and openpyxl, but extract_excel_content() also imports tabulate and xls2xlsx.
  • GoogleScholarToolkit checks scholarly, but get_full_paper_content_by_link() also imports arxiv2text.
  • RedditToolkit checks praw and the Reddit environment variables, but perform_sentiment_analysis() also imports textblob.

There are also several other toolkits whose optional dependencies or API keys are not covered in this PR, such as WeatherToolkit, SlackToolkit, JinaRerankerToolkit, OpenAPIToolkit, GmailToolkit, EarthScienceToolkit, etc. So I suggest either narrowing the PR description to say that this PR only handles these 6 toolkits, or continuing to add the missing decorators and tests.

@Mubin-A-Kader

Copy link
Copy Markdown
Author

@Mubin-A-Kader Thanks for working on the toolkits decorator refactor.

There are still a few missing dependency checks in the files changed by this PR:

  • ExcelToolkit checks pandas and openpyxl, but extract_excel_content() also imports tabulate and xls2xlsx.
  • GoogleScholarToolkit checks scholarly, but get_full_paper_content_by_link() also imports arxiv2text.
  • RedditToolkit checks praw and the Reddit environment variables, but perform_sentiment_analysis() also imports textblob.

There are also several other toolkits whose optional dependencies or API keys are not covered in this PR, such as WeatherToolkit, SlackToolkit, JinaRerankerToolkit, OpenAPIToolkit, GmailToolkit, EarthScienceToolkit, etc. So I suggest either narrowing the PR description to say that this PR only handles these 6 toolkits, or continuing to add the missing decorators and tests.

Thanks @fengju0213 ..
Will add missing checks (tabulate, xls2xlsx, arxiv2text, textblob) and extend to
WeatherToolkit, SlackToolkit, JinaRerankerToolkit, OpenAPIToolkit, GmailToolkit,
EarthScienceToolkit in this PR.
Pushing updates shortly..

Phase 1 — fill gaps flagged in review on PR camel-ai#4056:
- excel_toolkit.extract_excel_content: add tabulate, xls2xlsx
- google_scholar_toolkit.get_full_paper_content_by_link: add arxiv2text
- reddit_toolkit.perform_sentiment_analysis: add textblob

Phase 2 — extend to additional toolkits:
- weather_toolkit.get_weather_data: pyowm
- slack_toolkit.__init__: slack_sdk
- open_api_toolkit.parse_openapi_file: prance
- gmail_toolkit._authenticate: googleapiclient, google_auth_oauthlib,
  google.auth, google.oauth2, dotenv
- earth_science_toolkit.__init__: numpy, rasterio
- earth_science_toolkit scipy methods (6): scipy

Skipped JinaRerankerToolkit (dual API/local mode makes a static
decorator unsafe).

Tests: 11 new cases in test_toolkits_decorators.py plus two helpers
(_only_missing for isolated method-level checks, _all_available for
bypassing __init__ decorators when optional deps are absent in the
test env).
@Mubin-A-Kader

Mubin-A-Kader commented May 26, 2026

Copy link
Copy Markdown
Author

Hi @fengju0213 ,

Updated PR per review feedback.

  • Phase 1 — added missing checks: tabulate/xls2xlsx (excel), arxiv2text (google_scholar), textblob (reddit).

  • Phase 2 — extended to WeatherToolkit, SlackToolkit, OpenAPIToolkit, GmailToolkit, EarthScienceToolkit. Skipped
    JinaRerankerToolkit (dual API/local mode makes a static decorator unsafe).

  • 11 new tests added, all 19 in the file pass:

image

@Mubin-A-Kader

Copy link
Copy Markdown
Author

Hi @fengju0213

Could you please review this changes

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.

[Feature Request] Refactor to use api_keys_required and dependencies_required decorators

2 participants