fix: tool request validation crash on non-canonical field names
keyboardstaff committed
Apr 22, 2026 at 22:01 UTC
14f5185cff6a493d6d66b36fd34e36db6e70bc6a
1 file changed
+8
-3
agent.py
+8
-3
@@ -875,7 +875,10 @@ class Agent:
875
# Only validate when extraction produced an object; None means no JSON tool
876
# block was found — the misformat warning path below handles that.
877
if tool_request is not None:
878
- await self.validate_tool_request(tool_request)
878
+ try:
879
+ await self.validate_tool_request(tool_request)
880
+ except ValueError:
881
+ tool_request = None # treat structural validation errors as misformat
882
883
if tool_request is not None:
884
raw_tool_name = tool_request.get("tool_name", tool_request.get("tool","")) # Get the raw tool name
@@ -976,9 +979,11 @@ class Agent:
979
async def validate_tool_request(self, tool_request: Any):
980
if not isinstance(tool_request, dict):
981
raise ValueError("Tool request must be a dictionary")
979
- if not tool_request.get("tool_name") or not isinstance(tool_request.get("tool_name"), str):
982
+ tool_name = tool_request.get("tool_name") or tool_request.get("tool")
983
+ if not tool_name or not isinstance(tool_name, str):
984
raise ValueError("Tool request must have a tool_name (type string) field")
981
- if "tool_args" not in tool_request or not isinstance(tool_request.get("tool_args"), dict):
985
+ tool_args = tool_request.get("tool_args", tool_request.get("args"))
986
+ if tool_args is None or not isinstance(tool_args, dict):
987
raise ValueError("Tool request must have a tool_args (type dictionary) field")
988
989