ComposioHQ / composio

Composio equip's your AI agents & LLMs with 100+ high-quality integrations via function calling
https://docs.composio.dev
Other
7.47k stars 2.33k forks source link

fix: In prompt and key access in event dict #365

Closed apneduniya closed 1 month ago

apneduniya commented 1 month ago

PR Type

Enhancement, Documentation


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
8 files
__init__.py
Add Reddit tool to available tools list                                   

python/composio/tools/local/__init__.py
  • Added import for Reddit tool.
  • Included Reddit in the list of available tools.
  • +2/-0     
    __init__.py
    Initialize Reddit tool module                                                       

    python/composio/tools/local/reddit/__init__.py - Added import statement for `Reddit` class.
    +1/-0     
    __init__.py
    Initialize Reddit actions module                                                 

    python/composio/tools/local/reddit/actions/__init__.py - Added import statements for `Filter` and `Comment` actions.
    +2/-0     
    comment.py
    Implement Reddit comment action                                                   

    python/composio/tools/local/reddit/actions/comment.py
  • Defined CommentToolRequest and CommentToolResponse models.
  • Implemented Comment action to post comments on Reddit.
  • Included error handling for missing environment variables.
  • +84/-0   
    filter.py
    Implement Reddit filter action                                                     

    python/composio/tools/local/reddit/actions/filter.py
  • Defined FilterToolRequest and FilterToolResponse models.
  • Implemented Filter action to search and filter Reddit posts.
  • Included error handling for missing environment variables.
  • +85/-0   
    tool.py
    Define Reddit tool class with actions                                       

    python/composio/tools/local/reddit/tool.py - Defined `Reddit` tool class with `Filter` and `Comment` actions.
    +18/-0   
    agents.py
    Enhance Slack calendar agent with dotenv and updated system message

    python/examples/slack_calendar_agent/agents.py
  • Added import and loading of environment variables using dotenv.
  • Updated system message content for calendar integration agent.
  • +27/-18 
    main.py
    Enhance Slack calendar agent main script with dotenv         

    python/examples/slack_calendar_agent/main.py
  • Added import and loading of environment variables using dotenv.
  • Fixed event payload key access in event_handler.
  • +6/-3     
    Documentation
    5 files
    main.py
    Add example script for Reddit agent                                           

    python/examples/reddit_agent/main.py
  • Created example script to demonstrate Reddit agent using
    ComposioToolSet.
  • Defined tasks for filtering and commenting on Reddit posts.
  • +56/-0   
    setup.sh
    Add setup script for Reddit agent                                               

    python/examples/reddit_agent/setup.sh
  • Added setup script to create virtual environment and install
    dependencies.
  • Included instructions to copy .env.example to .env.
  • +31/-0   
    .env.example
    Add example environment variables file for Reddit agent   

    python/examples/reddit_agent/.env.example - Added example environment variables for Reddit and Google API.
    +12/-0   
    README.md
    Add README for Reddit agent example                                           

    python/examples/reddit_agent/README.md - Added README with instructions to run Reddit agent example.
    +32/-0   
    requirements.txt
    Add requirements file for Reddit agent                                     

    python/examples/reddit_agent/requirements.txt - Added requirements file listing necessary dependencies.
    +4/-0     

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Error Handling
    The method `execute` in the `Comment` class does not handle the case where the Reddit API call fails. It's recommended to add error handling around the `post.reply(request_data.message)` call to manage potential API failures gracefully. Error Handling
    The method `execute` in the `Filter` class lacks error handling for the Reddit API call within the loop that fetches posts. Consider adding try-except blocks to handle exceptions that may occur during the API calls.
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Maintainability
    Refactor repeated environment variable checks into a method ___ **Refactor the repeated code for environment variable checks into a separate method to
    improve code maintainability and reduce redundancy.** [python/composio/tools/local/reddit/actions/comment.py [38-46]](https://github.com/ComposioHQ/composio/pull/365/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R38-R46) ```diff -client_id = os.getenv("CLIENT_ID") -if client_id is None: - self.logger.error("CLIENT_ID environment variable not set") - raise ValueError("CLIENT_ID environment variable not set") -client_secret = os.getenv("CLIENT_SECRET") -if client_secret is None: - self.logger.error("CLIENT_SECRET environment variable not set") - raise ValueError("CLIENT_SECRET environment variable not set") +def check_env_var(var_name): + var_value = os.getenv(var_name) + if var_value is None: + self.logger.error(f"{var_name} environment variable not set") + raise ValueError(f"{var_name} environment variable not set") + return var_value +client_id = check_env_var("CLIENT_ID") +client_secret = check_env_var("CLIENT_SECRET") + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: This suggestion improves code maintainability by reducing redundancy and centralizing the environment variable checks into a single method, making the code cleaner and easier to maintain.
    8
    Best practice
    Use a more specific exception for missing environment variables ___ **Use a more specific exception instead of the generic ValueError for missing
    environment variables to provide clearer error handling.** [python/composio/tools/local/reddit/actions/comment.py [40-41]](https://github.com/ComposioHQ/composio/pull/365/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R40-R41) ```diff if client_id is None: self.logger.error("CLIENT_ID environment variable not set") - raise ValueError("CLIENT_ID environment variable not set") + raise EnvironmentError("CLIENT_ID environment variable not set") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Using a more specific exception like `EnvironmentError` provides clearer error handling and makes the code more readable and easier to debug.
    7
    Enhancement
    Use decouple for managing environment variables more effectively ___ **Instead of manually checking each environment variable, consider using a library
    like decouple to manage them, which can provide default values and raise informative
    errors automatically.** [python/composio/tools/local/reddit/actions/comment.py [38-41]](https://github.com/ComposioHQ/composio/pull/365/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R38-R41) ```diff -client_id = os.getenv("CLIENT_ID") -if client_id is None: - self.logger.error("CLIENT_ID environment variable not set") - raise ValueError("CLIENT_ID environment variable not set") +from decouple import config +client_id = config("CLIENT_ID", cast=str) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: The suggestion to use the `decouple` library can enhance the management of environment variables by providing default values and more informative errors, but it introduces an additional dependency which may not be necessary for this context.
    6