Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Fix usage of EnvVar class#320

Closed
blink1073 wants to merge 1 commit intocrewAIInc:mainfrom
blink1073:fix-unit-tests
Closed

Fix usage of EnvVar class#320
blink1073 wants to merge 1 commit intocrewAIInc:mainfrom
blink1073:fix-unit-tests

Conversation

@blink1073
Copy link
Contributor

I noticed while working on #319 that there was a regression due to the release of CrewAI 0.121.1, which affected imports in this repo.

Note that by modifying these files the pre-commit hook reformatted them.

@joaomdmoura
Copy link
Collaborator

Disclaimer: This review was made by a crew of AI Agents.

Code Review Comment for PR #320 - Fix usage of EnvVar class

Overview

This PR refactors the usage of the EnvVar class and includes significant improvements across four files. While the changes enhance some aspects of code quality, there are critical concerns regarding the import structure and overall organization that need to be addressed before merging.


Specific Code Improvements

  1. File: crewai_tools/tools/serper_dev_tool/serper_dev_tool.py

    • Issue: The EnvVar class import was shifted from crewai.tools to tests.utils, potentially breaking core functionality.
    • Recommendation: Return the EnvVar class to a more appropriate location in the main package:
      from crewai_tools.utils.env import EnvVar  # New suggested location
  2. File: generate_tool_specs.py

    • Issue: Long lines exceeding standard length and complex nested conditions.
    • Improvement: Simplify the schema extraction method. For instance, refactor the _schema_type_to_str method to:
      def _schema_type_to_str(self, schema: Dict) -> str:
          type_handlers = {
              "list": self._handle_list_type,
              "union": self._handle_union_type,
              "dict": self._handle_dict_type
          }
          schema_type = schema.get("type", "unknown")
          handler = type_handlers.get(schema_type)
          return handler(schema) if handler else schema_type
  3. File: tests/test_generate_tool_specs.py

    • Issue: Complex schema used in tests can be simplified.
    • Improvement: Use helper functions to reduce complexity and create parametrized test fixtures:
      @pytest.fixture(params=[
          ("str", "string_value"),
          ("int", 42),
          ("list", ["item"]),
      ])
      def type_test_cases(request):
          return {
              "type": request.param[0],
              "value": request.param[1]
          }
  4. File: tests/utils.py (New File)

    • Recommendation: It's vital to add documentation to the EnvVar class to clarify its intended use, such as:
      class EnvVar(BaseModel):
          """Environment variable configuration for tools."""
          ...

General Suggestions

  • Error Handling: Implement specific exceptions for tool configuration errors and maintain consistent error messaging throughout the codebase.
  • Type Hints: Enhance type hints all over the files, avoiding generic types wherever possible, to improve code clarity.
  • Documentation: Document all classes and methods thoroughly and provide usage examples where applicable.
  • Testing: Explore edge cases in schema parsing and include integration tests to ensure tool generation behaves as expected.
  • Code Organization: Reassess the import structure of crucial classes like EnvVar. They should reside appropriately within the main application scope, not test utilities.

Conclusion

While PR #320 brings valuable improvements and enhances the testing framework, the relocation of the EnvVar class into testing infrastructure raises significant concerns regarding production stability. It’s essential to address these issues before merging. Let's ensure that the core functionalities are clearly defined and separated from testing logic to maintain consistent reliability in the application.

@blink1073
Copy link
Contributor Author

This PR is no longer needed

@blink1073 blink1073 closed this Jul 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants