-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Summary
The OpenHands CLI crashes with an XML parsing error when using Mistral models due to improper handling of function call syntax in the action confirmation dialog.
Problem
When using Mistral models, the CLI displays a confirmation dialog showing pending actions. However, the CLI attempts to display the raw function call syntax (e.g., <function=execute_bash>
) in an HTML context, which causes an XML parsing error because the syntax is not valid XML/HTML.
Root Cause
The CLI's agent_action.py
has not been properly adapted to work with the new agent-sdk ActionEvent structure. Specifically:
- The CLI tries to stringify
action.action
which can contain raw function call syntax - Even with
html.escape()
, the escaped content like<function=execute_bash>
is still problematic for XML parsing - The CLI should use proper ActionEvent fields like
action.tool_call.name
and handle the display more robustly
Impact
- CLI is completely unusable with Mistral models
- Users cannot interact with the agent when confirmation mode is enabled
- The error occurs before any actual work can be done
Error Details
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 75
The error occurs in openhands_cli/user_actions/agent_action.py
line 40-42 when trying to create an HTML object with the action content.
Steps to Reproduce
-
Set up OpenHands CLI with Mistral model:
# Install OpenHands CLI # Configure with Mistral model (e.g., mistral-small-24b-instruct-2501)
-
Start a conversation with confirmation mode enabled (default behavior):
openhands
-
Send any request that would trigger a function call:
> what files do you see in pwd?
-
Observe the crash:
- The agent generates a function call
- CLI attempts to show confirmation dialog
- XML parsing error occurs and CLI crashes
Expected Behavior
- CLI should display the confirmation dialog properly
- User should be able to confirm/reject the action
- No XML parsing errors should occur
Actual Behavior
- CLI crashes with XML parsing error
- User cannot proceed with the conversation
- Error traceback is displayed
Environment
- OpenHands CLI version: Latest (main branch)
- Model: Mistral (mistral-small-24b-instruct-2501)
- Platform: Any
- Agent-SDK integration: Using new agent-sdk structure
Additional Context
Error Log
Error: not well-formed (invalid token): line 1, column 75
Traceback (most recent call last):
File "openhands_cli/user_actions/agent_action.py", line 40, in ask_user_confirmation
File "prompt_toolkit/formatted_text/html.py", line 35, in __init__
File "xml/dom/minidom.py", line 2000, in parseString
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 75
Related
- Previous fix attempt in fix(cli): escape action content before passing to HTMLΒ #11333 added
html.escape()
but didn't fully resolve the issue - Issue is specific to models that generate function calls in the
<function=name>
format - CLI needs to be updated to properly handle agent-sdk ActionEvent structure
Suggested Solution
-
Update CLI to use proper ActionEvent fields:
- Use
action.tool_call.name
for tool name - Use
action.action.__class__.__name__
or similar for action display - Handle
action.action
being None properly
- Use
-
Improve HTML content sanitization:
- Don't try to display raw function call syntax in HTML
- Use plain text or better formatting for action content
-
Add error handling:
- Wrap HTML creation in try-catch
- Fall back to plain text display if HTML parsing fails
Files to modify
openhands-cli/openhands_cli/user_actions/agent_action.py