crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
20.95k stars 2.9k forks source link

[BREAKING CHANGE] Are breaking tools by upgrading versions #366

Closed rrfaria closed 2 months ago

rrfaria commented 7 months ago

Hi @joaomdmoura,

First thank you for sharing this amazing tool, it helps a lot to create my agents.

Suggestion:

I noticed that you're currently not using Semantic Versioning in your project. This can lead to some issues down the road, such as breaking changes and compatibility problems.

Semantic Versioning is a great way to control versions and make sure that your users always have a smooth experience. It's a simple and easy-to-use system that will help you avoid a lot of headaches in the future. Semantic Versioning Specification

Issue

I was using version:

crewai==0.11.2

it was working very well with tools returning a dataframe as output

But now I upgraded to version

crewai==0.22.5
crewai-tools==0.0.12

Note: I tried other versions after 0.11 like 0.14

Tool code:

import traceback
from typing import Type
import pandas as pd
import yfinance as yf
from crewai_tools import BaseTool
from pydantic.v1 import BaseConfig, BaseModel, Field
from datetime import datetime, timedelta
from tools.current_date import DateTools

BaseConfig.arbitrary_types_allowed = True

class MarketDataToolInput(BaseModel):
    """Input for MarketDataTool."""
    ticker: str = Field(..., description="ticker or symbol for stock.")
    start_date: str = Field('2023-01-01', description="which can be from 2023-01-01")
    end_date: str = Field('2024-02-27', description="which can be from 2024-02-27 but keep this date updated")

class MarketDataTool(BaseTool):
    name: str = "Get historical market data"
    description: str = """
        Get historical market data for Brazilian stocks
        action input example:
         {"ticker": "PETR4.SA", "start_date": "2023-01-01", "end_date": "2024-02-27"}
        ALWAYS update ticker and end_date!
        It is necessary to pass the symbol/ticker, the start_date, which can be from 2023-01-01 to tomorrow's date (use tomorrow date) in the end_date.
        And output returns market data dataframe.
    """
    args_schema: Type[BaseModel] = MarketDataToolInput

    def _run(self, ticker: str, start_date: str, end_date: str) -> pd.DataFrame:
        """Gets historical market data for a specific symbol. In case of Brazilian shares, the ticker uses .SA
            You MUST follow the example below as input updating all values, first update symbol/ticker,
            sencond is start date and last one is tomorrow date(update last value to tomorrow date):
            {"ticker": "PETR4.SA", "start_date": "2023-01-01", "end_date": "2024-02-27"}
            It is necessary to pass the symbol/ticker, the start_date, which can be from 2023-01-01 to tomorrow's date (use tomorrow date) in the end_date.
            And output returns market data.
            Don't forget to analyse other indicator to get right analyses.
        """
        try:

            symbol = ticker

            print(f'searching for {symbol} in: {start_date} to {end_date}')
            symbol = symbol.strip().replace('\n', '')
            start_date = start_date.strip().replace('\n', '')
            # prevent model to pass wrong date
            TOMORROW = datetime.today() + timedelta(days=1)
            TOMORROW = TOMORROW.strftime("%Y-%m-%d")
            data = yf.download(symbol, start=start_date, end=TOMORROW)
            # print(data)
            if not data.empty:
                return data
            else:
                raise ValueError("no market data.")
        except Exception as e:
            print('Error trying to obtain marketData')
            print(traceback.format_exc())
            return 'marketData failed'

Now my tool starts to broke when it access the chain to retrive data.

I notice if it is called first time it works working-tool

but if another agent call again this error happen:

  File "envs\stocks\lib\site-packages\gradio\queueing.py", line 495, in call_prediction
    output = await route_utils.call_process_api(
  File "envs\stocks\lib\site-packages\gradio\route_utils.py", line 233, in call_process_api
    output = await app.get_blocks().process_api(
  File "envs\stocks\lib\site-packages\gradio\blocks.py", line 1608, in process_api
    result = await self.call_function(
  File "envs\stocks\lib\site-packages\gradio\blocks.py", line 1176, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "envs\stocks\lib\site-packages\anyio\to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "envs\stocks\lib\site-packages\anyio\_backends\_asyncio.py", line 2144, in run_sync_in_worker_thread
    return await future
  File "envs\stocks\lib\site-packages\anyio\_backends\_asyncio.py", line 851, in run
    result = context.run(func, *args)
  File "envs\stocks\lib\site-packages\gradio\utils.py", line 689, in wrapper
    response = f(*args, **kwargs)
  File "E:\AI\llm\stock_analysis\ui.py", line 80, in cli_interface
    result = financial_crew.run()
  File "E:\AI\llm\stock_analysis\ui.py", line 64, in run
    result = crew.kickoff()
  File "envs\stocks\lib\site-packages\crewai\crew.py", line 204, in kickoff
    result = self._run_sequential_process()
  File "envs\stocks\lib\site-packages\crewai\crew.py", line 240, in _run_sequential_process
    output = task.execute(context=task_output)
  File "envs\stocks\lib\site-packages\crewai\task.py", line 148, in execute
    result = self._execute(
  File "envs\stocks\lib\site-packages\crewai\task.py", line 157, in _execute
    result = agent.execute_task(
  File "envs\stocks\lib\site-packages\crewai\agent.py", line 193, in execute_task
    result = self.agent_executor.invoke(
  File "envs\stocks\lib\site-packages\langchain\chains\base.py", line 163, in invoke
    raise e
  File "envs\stocks\lib\site-packages\langchain\chains\base.py", line 153, in invoke
    self._call(inputs, run_manager=run_manager)
  File "envs\stocks\lib\site-packages\crewai\agents\executor.py", line 64, in _call
    next_step_output = self._take_next_step(
  File "envs\stocks\lib\site-packages\langchain\agents\agent.py", line 1138, in _take_next_step
    [
  File "envs\stocks\lib\site-packages\langchain\agents\agent.py", line 1138, in <listcomp>
    [
  File "envs\stocks\lib\site-packages\crewai\agents\executor.py", line 199, in _iter_next_step
    observation = tool_usage.use(tool_calling, agent_action.log)
  File "envs\stocks\lib\site-packages\crewai\tools\tool_usage.py", line 88, in use
    return f"{self._use(tool_string=tool_string, tool=tool, calling=calling)}"
  File "envs\stocks\lib\site-packages\crewai\tools\tool_usage.py", line 116, in _use
    if not result:
  File "envs\stocks\lib\site-packages\pandas\core\generic.py", line 1576, in __nonzero__
    raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 5 days with no activity.