I use several tools to get the stock information.
But many time my agent fail to call my tool with correct paramters.
@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.
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.
@iam1492 I recommend you set up a custom tool by subclassing the BaseTool
class instead of using the @tool
decorator as follows:
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"
1 Like
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!
@iam1492 Please let me know if this solves the issue!
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)
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
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.
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.
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.
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.