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 edit tool, add runtime action #369

Closed kaavee315 closed 1 month ago

kaavee315 commented 1 month ago

PR Type

Enhancement, Tests


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
file.py
Adjust error message in `edit` function                                   

python/composio/tools/env/filemanager/file.py
  • Modified the edit function to return an empty error string instead of
    "No lint errors found".
  • +1/-1     
    agent.py
    Add arithmetic action and dynamic LLM selection                   

    python/swe/examples/crewai_agent/agent.py
  • Added calculate_operation action for basic arithmetic operations.
  • Introduced get_langchain_llm function to dynamically select LLM based
    on environment variables.
  • Updated agent initialization to use get_langchain_llm.
  • +60/-3   
    utils.py
    Update logs directory path in benchmark utility                   

    python/swe/swekit/benchmark/utils.py - Updated the `logs_dir` path in the `get_score` function call.
    +1/-1     
    agent.template
    Add arithmetic action to agent template                                   

    python/swe/swekit/scaffold/templates/crewai/agent.template
  • Added calculate_operation action for basic arithmetic operations.
  • Appended the new action to the tools list.
  • +16/-0   
    Tests
    test_workspace.py
    Update test_workspace with new repo and file paths             

    python/tests/test_tools/test_local/test_workspace.py
  • Updated repository name in test_workspace.
  • Modified file path in test_workspace.
  • Added additional logging for file scroll actions.
  • +9/-3     

    ๐Ÿ’ก 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 Reviewer Guide ๐Ÿ”

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

    Error Handling
    The function `calculate_operation` lacks error handling for division by zero, which could lead to runtime exceptions if `num2` is zero. Hardcoded Values
    The function `get_langchain_llm` uses hardcoded model names and URLs, which might not be flexible for configuration changes or environment differences. Possible Bug
    The function `get_langchain_llm` raises a `RuntimeError` if no API keys are found, but does not handle the scenario where keys are invalid or expired.
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add error handling for division by zero to enhance robustness ___ **Add error handling for division by zero in the calculate_operation function to
    prevent runtime exceptions.** [python/swe/examples/crewai_agent/agent.py [30-31]](https://github.com/ComposioHQ/composio/pull/369/files#diff-de26150a00e225aa6dbb949058c0c6517cc59c8619bef7bc4de99bf2bbe496f9R30-R31) ```diff if operation == "divide": + if num2 == 0: + raise ValueError("Cannot divide by zero") return num1 / num2 ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 10 Why: Adding error handling for division by zero is crucial to prevent runtime exceptions, making the code more robust and reliable.
    10
    Best practice
    Replace an empty string with None for the "error" key to clarify the absence of errors ___ **Instead of setting an empty string for the "error" key when there are no errors,
    consider using None or removing the key entirely to reduce ambiguity and improve
    data handling.** [python/composio/tools/env/filemanager/file.py [297]](https://github.com/ComposioHQ/composio/pull/369/files#diff-ecd2b2a6ab5d3a06e0d47e05b29f4e012f835d67af09070c6564e2ac4690ae03R297-R297) ```diff -"error": "", +"error": None, ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Using `None` instead of an empty string for the "error" key is a good practice as it clearly indicates the absence of an error, improving data handling and reducing ambiguity.
    8
    Reduce redundant logging to improve log clarity and usefulness ___ **Avoid logging the same action multiple times in a row without changes, as it can
    clutter the log output and reduce the usefulness of the logs.** [python/tests/test_tools/test_local/test_workspace.py [137-141]](https://github.com/ComposioHQ/composio/pull/369/files#diff-7d7164755338a08f2e4bfa1e6ba877d6c529b3b5580941e23ee43bf02ebe6c87R137-R141) ```diff -logger.info(f"output of scroll file 1: {output_scroll_file}") output_scroll_file = toolset.execute_action( action=Action.FILETOOL_SCROLL, params={}, ) -logger.info(f"output of scroll file 2: {output_scroll_file}") +logger.info(f"output of scroll file: {output_scroll_file}") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Reducing redundant logging is a good practice as it helps in maintaining clear and useful log outputs, but it is a minor improvement.
    6
    Maintainability
    Refactor the API client instantiation into separate helper functions to improve code readability and maintainability ___ **Refactor the get_langchain_llm function to separate concerns by creating helper
    functions for each API key check and instantiation logic.** [python/swe/examples/crewai_agent/agent.py [36-46]](https://github.com/ComposioHQ/composio/pull/369/files#diff-de26150a00e225aa6dbb949058c0c6517cc59c8619bef7bc4de99bf2bbe496f9R36-R46) ```diff +def get_anthropic_client(helicone_api_key): + print("Using Anthropic with Helicone") + return ChatAnthropic( + model_name="claude-3-5-sonnet-20240620", + anthropic_api_url="https://anthropic.helicone.ai/", + default_headers={ + "Helicone-Auth": f"Bearer {helicone_api_key}", + }, + ) +# Similar helper functions for OpenAI and AzureChatOpenAI if os.environ.get("ANTHROPIC_API_KEY"): - if helicone_api_key: - print("Using Anthropic with Helicone") - return ChatAnthropic( - model_name="claude-3-5-sonnet-20240620", - anthropic_api_url="https://anthropic.helicone.ai/", - default_headers={ - "Helicone-Auth": f"Bearer {helicone_api_key}", - }, - ) # type: ignore + return get_anthropic_client(helicone_api_key) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: While the suggestion improves code readability and maintainability, it is not critical. The current implementation is functional, but the refactor would make the code cleaner and easier to manage.
    7