# Why is my agent sometimes call tool with wrong parameter?

**URL:** <https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313>\
**Category:** CrewAI Community Support\
**Tags:** tools\_issues\
**Created:** [March 2, 2025, 2:31pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313 "2025-03-02T14:31:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 2, 2025, 2:31pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/1 "2025-03-02T14:31:34Z")

</div>

I use several tools to get the stock information.  
But many time my agent fail to call my tool with correct paramters.

```python
@tool("Stock Info")
def stock_info(ticker: str):
    """
    Useful to get stock infomation.(e.g. market cap, beta, 52-week high, 52-week low, etc.)
    
    Input paramter:
    - ticker(type:str): The ticker of a company.
    """
    ticker = yf.Ticker(ticker)
    return ticker.info

```

The tool is very simple tool with only one string paramter.  
But my agent trying to use the tool with wrong parameter again and again.

```auto
Tool Used: Stock Info
  
Tool input: [{"ticker": "VST"}, {"tool_code": "Stock Info", "tool_input": {"ticker": "VST"}}]
  
Message: Thought:Okay, let's start by getting the stock information for Vistra Corp (VST) using the 'Stock Info' tool to get some initial parameters. Action: Stock Info Action Input: {"ticker": "VST"}
  
tool_code
{"tool_code": "Stock Info", "tool_input": {"ticker": "VST"}}
  
Observation: Error: the Action Input is not a valid key, value dictionary.
  
Error: the Action Input is not a valid key, value dictionary.

```

I’m not sure why the agent use tool input with  
[{“ticker”: “VST”}, {“tool\_code”: “Stock Info”, “tool\_input”: {“ticker”: “VST”}}]  
correct parameter is just {“ticker”:“VST”}  
This happening often for me.  
How can I make my agent always use correct parameters to a specified tool?  
Thanks.

---

<div class="post-metadata">

**Author:** ![rokbenko](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rokbenko/32/492_2.png) [@rokbenko](https://community.crewai.com/u/rokbenko)\
**Post date:** [March 3, 2025, 10:09am UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/2 "2025-03-03T10:09:36Z")

</div>

@iam1492 I recommend you set up a custom tool by [subclassing the `BaseTool` class](https://docs.crewai.com/how-to/create-custom-tools#subclassing-basetool) instead of [using the `@tool` decorator](https://docs.crewai.com/how-to/create-custom-tools#using-the-tool-decorator) as follows:

```auto
from typing import Type
from crewai.tools import BaseTool
from pydantic import BaseModel, Field

class MyToolInput(BaseModel):
    """Input schema for MyCustomTool."""
    argument: str = Field(..., description="Description of the argument.")

class MyCustomTool(BaseTool):
    name: str = "Name of my tool"
    description: str = "What this tool does. It's vital for effective utilization."
    args_schema: Type[BaseModel] = MyToolInput

    def _run(self, argument: str) -> str:
        # Your tool's logic here
        return "Tool's result"

```

---

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 3, 2025, 11:27am UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/3 "2025-03-03T11:27:24Z")

</div>

Hi rokbenko.  
I modify one of my tool with subclassing the BaseTool class.  
If this work well, I will modify all the tool in same way!  
Thanks!

---

<div class="post-metadata">

**Author:** ![rokbenko](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rokbenko/32/492_2.png) [@rokbenko](https://community.crewai.com/u/rokbenko)\
**Post date:** [March 3, 2025, 11:33am UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/4 "2025-03-03T11:33:30Z")

</div>

@iam1492 Please let me know if this solves the issue!

---

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 3, 2025, 11:01pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/5 "2025-03-03T23:01:05Z")

</div>

I found another solution with seperate llm and function\_calling\_llm with different model.  
I use gemini 2.0 for llm but change to use ollama/hengwen/watt-tool-8B:latest for my function\_calling\_llm.  
You can find out function calling benchmark here: [Berkeley Function Calling Leaderboard V3 (aka Berkeley Tool Calling Leaderboard V3)](https://gorilla.cs.berkeley.edu/leaderboard.html)

ollama/hengwen/watt-tool-8B is quite small llm so that I can run this model locally but have strong function.

And also this model works great without failing any function call.  
Thanks

---

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 5, 2025, 1:10am UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/6 "2025-03-05T01:10:31Z")

</div>

After doing some effort but still no help with function calling.

- Using different llm for function calling(tool) help better tool usage, but still have same issue.
- Change @tool decorator with subclassing the BaseTool is not working.  
Strange thing is one of my agent make this error much more than other agents but I don’t know what is problem. I will comment here when I find any solution.

---

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 6, 2025, 7:36am UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/7 "2025-03-06T07:36:24Z")

</div>

Here I report my bug 🙂

> <https://github.com/crewAIInc/crewAI/issues/2288>
>
> \### Description
> 
> My agent use simple tool which has only one parameter with wron…g way.
> for example:
> \`\`\`python
> @tool
> def stock\_info(ticker: str):
> """Useful to get stock infomation.(e.g. market cap, beta, 52-week high, 52-week low, etc.)
>     
> Args:
> ticker: The ticker of a company. str
> """
> ticker = yf.Ticker(ticker)
> return ticker.info
> \`\`\`
> \*\*This tool's input should be\*\* : {"ticker": "VST"}
> 
> But sometimes \*\*input become\*\*: \[{"ticker": "VST"}, {"tool\_code": "Stock Info", "tool\_input": {"ticker": "VST"}}\]
> 
> Full message from step callback is as follow:
> \`
> Tool Used: Stock Info
>   
> Tool input: \[{"ticker": "VST"}, {"tool\_code": "Stock Info", "tool\_input": {"ticker": "VST"}}\]
>   
> Message: Thought:Okay, let's start by getting the stock information for Vistra Corp (VST) using the 'Stock Info' tool to get some initial parameters. Action: Stock Info Action Input: {"ticker": "VST"}
>   
> tool\_code
> {"tool\_code": "Stock Info", "tool\_input": {"ticker": "VST"}}
>   
> Observation: Error: the Action Input is not a valid key, value dictionary.
> \`
> 
> 
> \### Steps to Reproduce
> 
> 1. Use tool with agent
> 
> \### Expected behavior
> 
> Agent use tool with correct way.
> 
> \### Screenshots/Code snippets
> 
> \`\`\`python
> @tool
> def stock\_info(ticker: str):
> """Useful to get stock infomation.(e.g. market cap, beta, 52-week high, 52-week low, etc.)
>     
> Args:
> ticker: The ticker of a company. str
> """
> ticker = yf.Ticker(ticker)
> return ticker.info
> \`\`\`
> 
> \`\`\`python
> @agent
> def quantitative\_analyst\_2(self) -\> Agent:
> return Agent(
> config=self.agents\_config\['quantitative\_analyst\_2'\],
> llm=self.get\_llm(),
> verbose=True,
> tools=\[
> stock\_info\_tool,
> macro\_economic\_data,
> basic\_financials\_from\_finnhub,
> financial\_statements\_from\_polygon,
> wacc\_calculator\_tool,
> expectations\_investing,
> #websiteSearchTool,
> #scrape\_tool,
> \],
> step\_callback=lambda step: self.step\_callback(step, "Quantitative Analyst 2")
> )
> \`\`\`
> 
> My quantative agent use 6~7 tools to calculate stock value.
> \`\`\`yaml
> quantitative\_analyst\_task:
> description: \>
> Calculate the Expectations Investing Result of the {company}'s stock.
> Use the provided tools to gather the key financial data which is used to calculate the WACC and Expectations Investing Result.:
> - Obtain the specific macroeconomic data with the Macro Economic Data tool.
> - Obtain the {company}'s info data with the Stock Info tool.
> - Obtain the {company}'s basic financial data with Basic Financials From Finnhub tool.
> - Obtain the {company}'s financial statement with Financial Statements From Polygon tool.
> - Obtain the WACC value with WACC Calculator tool. (Use correct input parameter which is calculated from the former data)
> After obtaning data, using the former data, use Expectations Investing tool with the data.(Use correct input parameter which is calculated from the former data)
> You can also use both WebsiteSearchTool and scrape website tool to get the data from web.(Do not try to read the pdf content from website with scrape website tool as it can exceed maximun token limit)
> 
> IMPORTANT
> - Before using the WACC Calculator and Expectations Investing tool, use other provided tool to get enough data.
> - When performing calculations, all monetary amounts must be converted to dollars before computation. For example, '50 million dollars' should be input as 50000000, and '4b dollars' should be input as 4000000000.
> - Use recent data from financial statements. If the latest financial data is unavailable, you can use the previous year's data for the calculation(and specify the reason).
> - Do not judge the result of Expectations Investing tool(it can be SELL, BUY or HOLD), only judge whether the parameters of the tool used in the calculation are accurate.
> 
> expected\_output: \>
> The result of the Expectations Investing.
> 
> \[Must Contains\]
> - Key matrics of result which is given by Expectations Investing tool.
> - Explain the source of the input data.
> - \[VERY IMPORTANT\] Explain the accuracy of calculated input paramter.
> - \[VERY IMPORTANT\] Ensure to specify the reliability of the result data.
>     
> \[OUTPUT FORMAT\]
> The final report MUST use Markdown format for optimal readability.
>   
> agent: quantitative\_analyst
> \`\`\`
> 
> 
> \### Operating System
> 
> Ubuntu 20.04
> 
> \### Python Version
> 
> 3.10
> 
> \### crewAI Version
> 
> 0.102.0
> 
> \### crewAI Tools Version
> 
> 0.33.0
> 
> \### Virtual Environment
> 
> Venv
> 
> \### Evidence
> 
> Different message from agent but same bug:
> \---
> 
> Tool Used: Macro Economic Data
> 
> Tool input: \[{}, {"tool\_code": "Macro Economic Data", "tool\_code\_kwargs": {}}\]
> 
> Message: {"No args required."} is not valid.
> 
> Thought:My apologies, I made a mistake in the Action Input. The \`Macro Economic Data\` tool doesn't require any input arguments, so I should just call it without any input. Let me try that again.
> Action: Macro Economic Data
> Action Input: {}
> 
> {"tool\_code": "Macro Economic Data", "tool\_code\_kwargs": {}}
> 
> Observation: Error: the Action Input is not a valid key, value dictionary.
> 
> Error: the Action Input is not a valid key, value dictionary.
> 
> \### Possible Solution
> 
> I have no idea, but possibly crewai agent try to follow Langchain style function calling in some reason. 
> 
> \### Additional context
> 
> My quantitative analyst agent make this bug more than others. Other agents use less number of tools. I'm not sure this has any relationship with this bug.

---

<div class="post-metadata">

**Author:** ![tonykipkemboi](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tonykipkemboi/32/4070_2.png) [@tonykipkemboi](https://community.crewai.com/u/tonykipkemboi)\
**Post date:** [March 6, 2025, 8:39pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/8 "2025-03-06T20:39:41Z")

</div>

> [@iam1492](#):
>
> Berkeley Function Calling Leaderboard V3 (aka Berkeley Tool Calling Leaderboard V3)

Can you share your full code in repo so we can clone and help troubleshoot this for you?

Also, I’ve personally noticed that most small OSS models struggle quite a bit with tool calling even if they’re high on the leaderboard. Sometimes they get it right sometimes they don’t; non-deterministic.

---

<div class="post-metadata">

**Author:** ![iam1492](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/iam1492/32/2845_2.png) [@iam1492](https://community.crewai.com/u/iam1492)\
**Post date:** [March 6, 2025, 9:30pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/9 "2025-03-06T21:30:10Z")

</div>

Hello 🙂  
My repo is currently private repository.  
I use gemini-2.0 pro exp model for testing my project.  
And I understanding llms sometimes confusing about using function call(tool).  
What I found was:  
More error occurs when I use more tool for one agent.  
When I reducing tools which is provided to my agent, the agent do the mistake less.  
I think this error can be disappears when model become stable later and Devins(AI coder) workaround may help until then.

---

<div class="post-metadata">

**Author:** ![vasanthraj\_devaraju](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/vasanthraj_devaraju/32/2891_2.png) [@vasanthraj\_devaraju](https://community.crewai.com/u/vasanthraj_devaraju)\
**Post date:** [March 7, 2025, 3:55pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/10 "2025-03-07T15:55:31Z")

</div>

I too observed the same, especially when we have scenario which involves more than 2 tools I’m getting this issue.

More Over I couldn’t able to understand on @Tool Decorators, and I fall back to use Subclassing the Base Tool, it didn’t help much. will look out this thread to find the solution.

---

<div class="post-metadata">

**Author:** ![tonykipkemboi](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tonykipkemboi/32/4070_2.png) [@tonykipkemboi](https://community.crewai.com/u/tonykipkemboi)\
**Post date:** [April 11, 2025, 3:24pm UTC](https://community.crewai.com/t/why-is-my-agent-sometimes-call-tool-with-wrong-parameter/4313/11 "2025-04-11T15:24:39Z")

</div>

one thing to try is to make sure for the tasks, make sure you mention which tool to use for which tasks so the agent knows which tool to use based on the task otherwise it will try to figure it out from the naming semantics which is not accurate all the time depending on how it is defined.
