mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Fix critical import error and type-checker issues
- Fix ToolUsageErrorException import in tool_utils.py (renamed to ToolUsageError) - Add proper type guards for fingerprint attribute access - Fix CacheHandler.read() argument type conversion - Resolve variable redefinition conflicts in _use method - All type-checker errors now resolved (mypy passes) - Import test passes successfully - Core MCP tool output functionality verified working Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from textwrap import dedent
|
|||||||
from typing import TYPE_CHECKING, Any, Union
|
from typing import TYPE_CHECKING, Any, Union
|
||||||
|
|
||||||
import json5
|
import json5
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json # type: ignore
|
||||||
|
|
||||||
from crewai.agents.tools_handler import ToolsHandler
|
from crewai.agents.tools_handler import ToolsHandler
|
||||||
from crewai.events.event_bus import crewai_event_bus
|
from crewai.events.event_bus import crewai_event_bus
|
||||||
@@ -174,7 +174,7 @@ class ToolUsage:
|
|||||||
"agent": self.agent,
|
"agent": self.agent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.agent.fingerprint:
|
if hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
|
||||||
event_data.update(self.agent.fingerprint)
|
event_data.update(self.agent.fingerprint)
|
||||||
if self.task:
|
if self.task:
|
||||||
event_data["task_name"] = self.task.name or self.task.description
|
event_data["task_name"] = self.task.name or self.task.description
|
||||||
@@ -183,13 +183,14 @@ class ToolUsage:
|
|||||||
|
|
||||||
started_at = time.time()
|
started_at = time.time()
|
||||||
from_cache = False
|
from_cache = False
|
||||||
result = None # type: ignore
|
|
||||||
|
|
||||||
if self.tools_handler and self.tools_handler.cache:
|
if self.tools_handler and self.tools_handler.cache:
|
||||||
result = self.tools_handler.cache.read(
|
cache_result = self.tools_handler.cache.read(
|
||||||
tool=calling.tool_name, input=calling.arguments
|
tool=calling.tool_name, input=str(calling.arguments)
|
||||||
) # type: ignore
|
)
|
||||||
from_cache = result is not None
|
from_cache = cache_result is not None
|
||||||
|
if cache_result is not None:
|
||||||
|
result = cache_result
|
||||||
|
|
||||||
available_tool = next(
|
available_tool = next(
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
from typing import Any, Dict, List, Optional
|
from typing import Any
|
||||||
|
|
||||||
from crewai.agents.parser import AgentAction
|
from crewai.agents.parser import AgentAction
|
||||||
from crewai.security import Fingerprint
|
from crewai.security import Fingerprint
|
||||||
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
|
||||||
from crewai.tools.tool_usage import ToolUsage, ToolUsageErrorException
|
from crewai.tools.tool_usage import ToolUsage, ToolUsageError
|
||||||
from crewai.utilities.i18n import I18N
|
from crewai.utilities.i18n import I18N
|
||||||
|
|
||||||
|
|
||||||
def execute_tool_and_check_finality(
|
def execute_tool_and_check_finality(
|
||||||
agent_action: AgentAction,
|
agent_action: AgentAction,
|
||||||
tools: List[CrewStructuredTool],
|
tools: list[CrewStructuredTool],
|
||||||
i18n: I18N,
|
i18n: I18N,
|
||||||
agent_key: Optional[str] = None,
|
agent_key: str | None = None,
|
||||||
agent_role: Optional[str] = None,
|
agent_role: str | None = None,
|
||||||
tools_handler: Optional[Any] = None,
|
tools_handler: Any | None = None,
|
||||||
task: Optional[Any] = None,
|
task: Any | None = None,
|
||||||
agent: Optional[Any] = None,
|
agent: Any | None = None,
|
||||||
function_calling_llm: Optional[Any] = None,
|
function_calling_llm: Any | None = None,
|
||||||
fingerprint_context: Optional[Dict[str, str]] = None,
|
fingerprint_context: dict[str, str] | None = None,
|
||||||
) -> ToolResult:
|
) -> ToolResult:
|
||||||
"""Execute a tool and check if the result should be treated as a final answer.
|
"""Execute a tool and check if the result should be treated as a final answer.
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ def execute_tool_and_check_finality(
|
|||||||
fingerprint_obj = Fingerprint.from_dict(fingerprint_context)
|
fingerprint_obj = Fingerprint.from_dict(fingerprint_context)
|
||||||
agent.set_fingerprint(fingerprint_obj)
|
agent.set_fingerprint(fingerprint_obj)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"Failed to set fingerprint: {e}")
|
raise ValueError(f"Failed to set fingerprint: {e}") from e
|
||||||
|
|
||||||
# Create tool usage instance
|
# Create tool usage instance
|
||||||
tool_usage = ToolUsage(
|
tool_usage = ToolUsage(
|
||||||
@@ -65,7 +65,7 @@ def execute_tool_and_check_finality(
|
|||||||
# Parse tool calling
|
# Parse tool calling
|
||||||
tool_calling = tool_usage.parse_tool_calling(agent_action.text)
|
tool_calling = tool_usage.parse_tool_calling(agent_action.text)
|
||||||
|
|
||||||
if isinstance(tool_calling, ToolUsageErrorException):
|
if isinstance(tool_calling, ToolUsageError):
|
||||||
return ToolResult(tool_calling.message, False)
|
return ToolResult(tool_calling.message, False)
|
||||||
|
|
||||||
# Check if tool name matches
|
# Check if tool name matches
|
||||||
|
|||||||
Reference in New Issue
Block a user