Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions hud/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,13 @@ def find_reward(result: MCPToolResult) -> float:
if isinstance(content, types.TextContent):
try:
json_content = json.loads(content.text)
for key, value in json_content.items():
if key in accept_keys:
return value
except json.JSONDecodeError:
pass
continue
if not isinstance(json_content, dict):
continue
for key, value in json_content.items():
if key in accept_keys:
return value

logger.error("Couldn't parse reward from result: %s", str(result.structuredContent))
return 0.0
Expand All @@ -963,9 +965,11 @@ def find_content(result: MCPToolResult) -> str | None:
if isinstance(content, types.TextContent):
try:
json_content = json.loads(content.text)
for key, value in json_content.items():
if key in accept_keys:
return value
except json.JSONDecodeError:
pass
continue
if not isinstance(json_content, dict):
continue
for key, value in json_content.items():
if key in accept_keys:
return value
return ""
18 changes: 9 additions & 9 deletions hud/shared/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,19 @@ def from_httpx_error(cls, error: httpx.HTTPStatusError, context: str = "") -> Se

# Try to get detailed error info from JSON if available
response_json = None
message = f"Request failed with status {status_code}"
try:
response_json = response.json()
parsed = response.json()
except Exception:
parsed = None
if isinstance(parsed, dict):
response_json = parsed
detail = response_json.get("detail")
if detail:
message = f"Request failed: {detail}"
else:
# If no detail field but we have JSON, include a summary
message = f"Request failed with status {status_code}"
if len(response_json) <= 5: # If it's a small object, include it in the message
message += f" - JSON response: {response_json}"
except Exception:
# Fallback to simple message if JSON parsing fails
message = f"Request failed with status {status_code}"
elif len(response_json) <= 5:
# Small object — include it in the message
message += f" - JSON response: {response_json}"

# Add context if provided
if context:
Expand Down