mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
fix: raise ValueError for missing required arguments
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -186,22 +186,24 @@ class ToolUsage:
|
|||||||
)
|
)
|
||||||
self.task.increment_delegations(coworker)
|
self.task.increment_delegations(coworker)
|
||||||
|
|
||||||
if calling.arguments:
|
if not calling.arguments:
|
||||||
try:
|
raise ValueError("Tool arguments cannot be empty")
|
||||||
acceptable_args = tool.args_schema.model_json_schema()[
|
|
||||||
"properties"
|
try:
|
||||||
].keys() # type: ignore
|
acceptable_args = tool.args_schema.model_json_schema()[
|
||||||
arguments = {
|
"properties"
|
||||||
k: v
|
].keys() # type: ignore
|
||||||
for k, v in calling.arguments.items()
|
arguments = {
|
||||||
if k in acceptable_args
|
k: v
|
||||||
}
|
for k, v in calling.arguments.items()
|
||||||
result = tool.invoke(input=arguments)
|
if k in acceptable_args
|
||||||
except Exception:
|
}
|
||||||
arguments = calling.arguments
|
result = tool.invoke(input=arguments)
|
||||||
result = tool.invoke(input=arguments)
|
except Exception as e:
|
||||||
else:
|
if isinstance(e, TypeError) and "missing 1 required positional argument" in str(e):
|
||||||
result = tool.invoke(input={})
|
raise ValueError("Required arguments missing for tool")
|
||||||
|
arguments = calling.arguments
|
||||||
|
result = tool.invoke(input=arguments)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.on_tool_error(tool=tool, tool_calling=calling, e=e)
|
self.on_tool_error(tool=tool, tool_calling=calling, e=e)
|
||||||
self._run_attempts += 1
|
self._run_attempts += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user