Replies: 8 comments 3 replies
-
I have opened the same issue in #110 and this issue is from pydantic version that crewai is using. The issue is also ongoing in langchain. |
Beta Was this translation helpful? Give feedback.
-
@Haripritamreddy you are right. Have you found any temporary solution for this? |
Beta Was this translation helpful? Give feedback.
-
Unlike langchain which can work with pydantic v1 and v2 crewai does not have this yet. I tried to install the oldest version of crewai 0.1.0 with pydantic 1.10.10 I get the error
So there is currently no way unless the next release of crewai adds pydantic v1 support or langchain should solve the issue. |
Beta Was this translation helpful? Give feedback.
-
@tkmerkel found a solution for it in the issue i opened. It has worked for me and it will work for you .
The explaination they gave is
|
Beta Was this translation helpful? Give feedback.
-
@joaomdmoura what do you think of this? I can revert to |
Beta Was this translation helpful? Give feedback.
-
i too have been futzing with a solution based on the @tkmerkel code, works but finicky at times - specially with arrays as you can see: def convert_tool_for_crewai(tool: BaseTool):
if tool.metadata and "crewai" in tool.metadata.keys() and tool.metadata["crewai"] == True:
return tool
elif tool.args_schema and len(tool.args) <= 1:
return tool
elif not tool.args_schema:
return tool
def parse_input_and_delegate(tool_input: Optional[str] = None) -> Any:
"""Parse the input and delegate to the function."""
# parse starting with first { and last }
tool_input = tool_input or "{}"
tool_input_input: Dict = {}
try:
tool_input_input = json.loads(tool_input[tool_input.find("{"):tool_input.rfind("}")+1])
#handle for arrays here :/
for k,v in tool_input_input.items():
if tool.args[k]["type"] == "array" and not isinstance(v,list):
tool_input_input[k] = [v]
except:
# trust the input, it might be positional...
tool_input_input = tool_input # type: ignore
#parse it!
parsed_input = tool._parse_input(tool_input_input)
tool_args, tool_kwargs = tool._to_args_and_kwargs(parsed_input)
observation = (
tool._run(*tool_args, run_manager=None, **tool_kwargs)
if signature(tool._run).parameters.get("run_manager")
else tool._run(*tool_args, **tool_kwargs)
)
return observation
# gen a prompt describing the fields expected
tool_args_desc = ""
for k,v in tool.args.items():
tool_args_desc += f"field: {k}"
if "type" in v.keys():
if v['type'] == "array":
tool_args_desc += f"\ntype: {v['type']} of {v['items']['type']}"
else:
tool_args_desc += f"\ntype: {v['type']}"
tool_args_desc += "\n\n"
# create the tool
crewai_tool = Tool.from_function(
func=parse_input_and_delegate,
name=f"{tool.name}_crewai",
description=tool.description,
args_schema=create_model(
f"{tool.name}_crewai_input",
tool_input=Field(
default="{}",
description=f"This MUST be a string representation of a dictionary containing the following fields:\n\n{tool_args_desc.strip()}"
)
),
return_direct=tool.return_direct,
metadata={
"crewai": True,
"original_tool": tool
}
)
return crewai_tool I found some tools (e.g. MS365, Gmail) would cause the large tool description to go beyond the 1000-ish char limit. Here im just splitting the tool description from the single args description. |
Beta Was this translation helpful? Give feedback.
-
I too have been tormented by the multi-parameter input of tools. I used to always concatenate multiple inputs with a special character, such as '#'. But now I have found a very effective method, and I hope it can help everyone.
|
Beta Was this translation helpful? Give feedback.
-
MVP |
Beta Was this translation helpful? Give feedback.
-
I am playing around with CrewAI with the goal of using it in our production app. I have done a basic setup where I am trying to setup an agent with multi-input tool.
When I am trying to run I am always getting following error:
Does CrewAI works well with Structured tools with multiple input parameter? What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions