mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Fix lint and type-checker issues
- Add 'cast' import to fix mypy type compatibility error - Remove unused imports to fix lint warnings - Add assertions to reproduction script to use agent variables - All custom tool patterns now work correctly Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -6,7 +6,6 @@ This script tests all the failing patterns mentioned in the issue.
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
def test_function_tool():
|
def test_function_tool():
|
||||||
"""Test 1: Function Tool with @tool decorator"""
|
"""Test 1: Function Tool with @tool decorator"""
|
||||||
@@ -20,13 +19,14 @@ def test_function_tool():
|
|||||||
"""Fetch logs from New Relic based on query"""
|
"""Fetch logs from New Relic based on query"""
|
||||||
return f"Logs for query: {query}"
|
return f"Logs for query: {query}"
|
||||||
|
|
||||||
teacher = Agent(
|
agent = Agent(
|
||||||
role='CrashFetcher',
|
role='CrashFetcher',
|
||||||
goal='Extract logs',
|
goal='Extract logs',
|
||||||
backstory='An agent that fetches logs',
|
backstory='An agent that fetches logs',
|
||||||
tools=[fetch_logs],
|
tools=[fetch_logs],
|
||||||
allow_delegation=False
|
allow_delegation=False
|
||||||
)
|
)
|
||||||
|
assert len(agent.tools) == 1, f"Expected 1 tool, got {len(agent.tools)}"
|
||||||
print("✅ Function tool with @tool decorator: SUCCESS")
|
print("✅ Function tool with @tool decorator: SUCCESS")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -49,13 +49,14 @@ def test_dict_tool():
|
|||||||
'func': fetch_logs_func
|
'func': fetch_logs_func
|
||||||
}
|
}
|
||||||
|
|
||||||
teacher = Agent(
|
agent = Agent(
|
||||||
role='CrashFetcher',
|
role='CrashFetcher',
|
||||||
goal='Extract logs',
|
goal='Extract logs',
|
||||||
backstory='An agent that fetches logs',
|
backstory='An agent that fetches logs',
|
||||||
tools=[fetch_logs_dict],
|
tools=[fetch_logs_dict],
|
||||||
allow_delegation=False
|
allow_delegation=False
|
||||||
)
|
)
|
||||||
|
assert len(agent.tools) == 1, f"Expected 1 tool, got {len(agent.tools)}"
|
||||||
print("✅ Dict-based tool: SUCCESS")
|
print("✅ Dict-based tool: SUCCESS")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -77,13 +78,14 @@ def test_basetool_class():
|
|||||||
def _run(self, query: str) -> str:
|
def _run(self, query: str) -> str:
|
||||||
return f"Logs for query: {query}"
|
return f"Logs for query: {query}"
|
||||||
|
|
||||||
teacher = Agent(
|
agent = Agent(
|
||||||
role='CrashFetcher',
|
role='CrashFetcher',
|
||||||
goal='Extract logs',
|
goal='Extract logs',
|
||||||
backstory='An agent that fetches logs',
|
backstory='An agent that fetches logs',
|
||||||
tools=[FetchLogsTool()],
|
tools=[FetchLogsTool()],
|
||||||
allow_delegation=False
|
allow_delegation=False
|
||||||
)
|
)
|
||||||
|
assert len(agent.tools) == 1, f"Expected 1 tool, got {len(agent.tools)}"
|
||||||
print("✅ BaseTool class inheritance: SUCCESS")
|
print("✅ BaseTool class inheritance: SUCCESS")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -101,13 +103,14 @@ def test_direct_function():
|
|||||||
"""Fetch logs from New Relic based on query"""
|
"""Fetch logs from New Relic based on query"""
|
||||||
return f"Logs for query: {query}"
|
return f"Logs for query: {query}"
|
||||||
|
|
||||||
teacher = Agent(
|
agent = Agent(
|
||||||
role='CrashFetcher',
|
role='CrashFetcher',
|
||||||
goal='Extract logs',
|
goal='Extract logs',
|
||||||
backstory='An agent that fetches logs',
|
backstory='An agent that fetches logs',
|
||||||
tools=[fetch_logs],
|
tools=[fetch_logs],
|
||||||
allow_delegation=False
|
allow_delegation=False
|
||||||
)
|
)
|
||||||
|
assert len(agent.tools) == 1, f"Expected 1 tool, got {len(agent.tools)}"
|
||||||
print("✅ Direct function assignment: SUCCESS")
|
print("✅ Direct function assignment: SUCCESS")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -125,7 +128,7 @@ def main():
|
|||||||
results.append(test_basetool_class())
|
results.append(test_basetool_class())
|
||||||
results.append(test_direct_function())
|
results.append(test_direct_function())
|
||||||
|
|
||||||
print(f"\n=== SUMMARY ===")
|
print("\n=== SUMMARY ===")
|
||||||
passed = sum(results)
|
passed = sum(results)
|
||||||
total = len(results)
|
total = len(results)
|
||||||
print(f"Tests passed: {passed}/{total}")
|
print(f"Tests passed: {passed}/{total}")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import uuid
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from copy import copy as shallow_copy
|
from copy import copy as shallow_copy
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from typing import Any, Callable, Dict, List, Optional, TypeVar
|
from typing import Any, Callable, Dict, List, Optional, TypeVar, cast
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
UUID4,
|
UUID4,
|
||||||
@@ -25,7 +25,6 @@ from crewai.security.security_config import SecurityConfig
|
|||||||
from crewai.tools.base_tool import BaseTool, Tool
|
from crewai.tools.base_tool import BaseTool, Tool
|
||||||
from crewai.utilities import I18N, Logger, RPMController
|
from crewai.utilities import I18N, Logger, RPMController
|
||||||
from crewai.utilities.config import process_config
|
from crewai.utilities.config import process_config
|
||||||
from crewai.utilities.converter import Converter
|
|
||||||
from crewai.utilities.string_utils import interpolate_only
|
from crewai.utilities.string_utils import interpolate_only
|
||||||
|
|
||||||
T = TypeVar("T", bound="BaseAgent")
|
T = TypeVar("T", bound="BaseAgent")
|
||||||
@@ -186,7 +185,7 @@ class BaseAgent(ABC, BaseModel):
|
|||||||
processed_tools.append(tool_item)
|
processed_tools.append(tool_item)
|
||||||
elif callable(tool_item):
|
elif callable(tool_item):
|
||||||
if hasattr(tool_item, '__doc__') and tool_item.__doc__:
|
if hasattr(tool_item, '__doc__') and tool_item.__doc__:
|
||||||
converted_tool = tool(tool_item)
|
converted_tool = cast(BaseTool, tool(tool_item))
|
||||||
processed_tools.append(converted_tool)
|
processed_tools.append(converted_tool)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from crewai.agents.parser import (
|
|||||||
)
|
)
|
||||||
from crewai.llm import LLM
|
from crewai.llm import LLM
|
||||||
from crewai.llms.base_llm import BaseLLM
|
from crewai.llms.base_llm import BaseLLM
|
||||||
from crewai.tools import BaseTool as CrewAITool
|
|
||||||
from crewai.tools.base_tool import BaseTool
|
from crewai.tools.base_tool import BaseTool
|
||||||
from crewai.tools.structured_tool import CrewStructuredTool
|
from crewai.tools.structured_tool import CrewStructuredTool
|
||||||
from crewai.tools.tool_types import ToolResult
|
from crewai.tools.tool_types import ToolResult
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ This addresses issue #3226 where custom tool registration was broken in CrewAI 0
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from typing import Any
|
|
||||||
from crewai import Agent
|
from crewai import Agent
|
||||||
from crewai.tools import BaseTool, tool, Tool
|
from crewai.tools import BaseTool, tool
|
||||||
|
|
||||||
|
|
||||||
class TestCustomToolPatterns:
|
class TestCustomToolPatterns:
|
||||||
|
|||||||
Reference in New Issue
Block a user