Skip to content

[BUG] Tool repeated execution #3489

@Lucas8026

Description

@Lucas8026

Description

In crewai.tools.structured_tool, when the invoke function calls the tool, the code is as follows:
` def invoke(
self, input: Union[str, dict], config: Optional[dict] = None, **kwargs: Any
) -> Any:
"""Main method for tool execution."""
parsed_args = self._parse_args(input)

    if self.has_reached_max_usage_count():
        raise ToolUsageLimitExceeded(
            f"Tool '{self.name}' has reached its maximum usage limit of {self.max_usage_count}. You should not use the {self.name} tool again."
        )

    self._increment_usage_count()

    if inspect.iscoroutinefunction(self.func):
        result = asyncio.run(self.func(**parsed_args, **kwargs))
        return result

    try:
        result = self.func(**parsed_args, **kwargs)
    except Exception:
        raise

    result = self.func(**parsed_args, **kwargs)

    if asyncio.iscoroutine(result):
        return asyncio.run(result)

    return result`

In fact, self.func(**parsed_args, **kwargs) runs the tool twice, is this a bug?

Steps to Reproduce

N

Expected behavior

N

Screenshots/Code snippets

N

Operating System

Ubuntu 20.04

Python Version

3.10

crewAI Version

0.177.0

crewAI Tools Version

N

Virtual Environment

Conda

Evidence

N

Possible Solution

N

Additional context

N

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions