Skip to content

Executor calling CustomTool with no parameter needed insists to call the tool with a parameter coming from nowhere #7685

@jeromemassot

Description

System Info

langchain==0.0.232
Google Colab

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

def get_current_oil_price():
    ticker_data = yf.Ticker("CL=F")
    recent = ticker_data.history(period='1d')
    return {"price": recent.iloc[0]["Close"], "currency": ticker_data.info["currency"]}
def get_oil_price_performance(days):
    past_date = datetime.today() - timedelta(days=int(days))
    ticker_data = yf.Ticker("CL=F")
    history = ticker_data.history(start=past_date)
    old_price = history.iloc[0]["Close"]
    current_price = history.iloc[-1]["Close"]
    return {"percent_change": ((current_price - old_price) / old_price) * 100}
class CurrentOilPriceTool(BaseTool):
    name = "get_oil_price"
    description = "Get the current oil price. No parameter needed from input"


    def _run(self):
        price_response = get_current_oil_price()
        return price_response


    def _arun(self):
        raise NotImplementedError("get_oil_price does not support async")
class CurrentOilPerformanceTool(BaseTool):
    name = "get_oil_performance"
    description = "Get the current oil price evolution over a given number of days. Enter the number of days."


    def _run(self, days):
        performance_response = get_oil_price_performance(days)
        return performance_response


    def _arun(self):
        raise NotImplementedError("get_oil_performance does not support async") 
llm = ChatOpenAI(model="gpt-3.5-turbo-0613", temperature=0)

tools = [CurrentOilPriceTool(), CurrentOilPerformanceTool()]

agent = initialize_agent(
    tools=tools,
    llm=llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True
)

agent.run("What is the oil price?")

Expected behavior

> Entering new AgentExecutor chain...

Invoking: `get_oil_price`

But instead, the executor insists on adding a parameter to the tool function !!!

> Entering new AgentExecutor chain...

Invoking: `get_oil_price` with `USD`

provoking an obvious error:

TypeError: CurrentOilPriceTool._run() takes 1 positional argument but 2 were given

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions