# QWEN XML Tool Call Explorer: A Comprehensive Guide for Developers

image

In today’s world of AI development, working with function calls can be tricky. Whether you’re building applications that interact with external tools or trying to understand how AI models respond to specific requests, having the right tools makes all the difference. That’s where the QWEN XML Tool Call Explorer comes in. This powerful web-based tool is designed to help developers test, explore, and debug XML-formatted function calls with QWEN models through OpenAI-compatible APIs. In this guide, we’ll cover everything you need to know to get started, use advanced features, and troubleshoot common issues.

## What is QWEN XML Tool Call Explorer?

The QWEN XML Tool Call Explorer is a user-friendly web interface that simplifies working with AI model function calls. It lets you see how QWEN models generate XML-formatted responses when asked to use tools, making it easier to test and refine your applications. Whether you’re a beginner or an experienced developer, this tool helps you understand how AI models interact with external functions—all without needing complex server setups or advanced technical knowledge.

## Key Features

### Core Functionality

  1. Real-time XML Parsing
    As soon as the AI model generates a response, the tool instantly checks and understands the XML-formatted function calls. This means you don’t have to manually parse or validate the code yourself.

  2. Interactive Testing
    You can test different function calls with custom tools and see results right away. This helps you experiment with how the AI model responds to different inputs and tool definitions.

  3. Streaming Support
    Watch responses appear word by word as the AI generates them. This is especially useful for longer responses, as you can see the thought process unfold in real time.

### Advanced Features

  1. Custom Tool Builder
    Create your own tools by defining functions with specific parameters. This lets you test how the AI model interacts with the exact tools your application will use.

  2. Tool Library
    Access pre-built tools like calculators, web search simulators, and file operation tools. These ready-made options help you get started quickly without building everything from scratch.

  3. Response Recovery
    If the AI generates malformed or incomplete XML, the tool automatically tries to fix it. This saves you time by handling common formatting errors.

  4. Export/Import
    Save your tool configurations and share them with teammates or reuse them later. This makes collaboration and consistency across projects easier.

  5. API Key Support
    Works with both local servers (like VLLM) and cloud-based API providers. This flexibility means you can use it with your existing setup, whether it’s on your computer or in the cloud.

## Getting Started

### What You’ll Need

Before you begin, make sure you have:

  • A running VLLM server with a QWEN model, OR
  • An OpenAI-compatible API endpoint with an API key
  • A modern web browser (Chrome, Firefox, Safari, or Edge)

### Installation

Getting started is simple—no complicated setup required:

  1. Download the tool_call_explorer.html file (either by cloning the repository or saving it directly)
  2. Open the file in your web browser. That’s it! No server installation needed.

### Setting Up Your Configuration

Once you’ve opened the tool, you’ll need to configure your API settings. Here’s how:

  1. Click the Settings icon (it looks like a gear) in the top right corner.
  2. Enter your API endpoint details:

    • For Local VLLM Servers:

      • Server URL: http://localhost
      • Port: 8000 (or whatever port your VLLM server uses)
      • API Key: Leave this blank
    • For Cloud APIs:

      • Server URL: Your API’s web address
      • Port: The port number (if required by your API)
      • API Key: Your unique API key
  3. Adjust generation parameters (these control how the AI responds):

    • Temperature: Controls randomness (0.0 = very predictable, 2.0 = more creative)
    • Top P: Determines how many possible words the model considers (0.0-1.0)
    • Min P: Sets the minimum probability for a word to be considered (0.0-1.0)

## How to Use the Tool

### Basic Steps

  1. Enter a prompt that requires the AI to use a tool. For example:

    What's the weather like in San Francisco?
    
  2. Click “Generate Tool Calls” to see how the AI responds with XML-formatted function calls.

  3. View the results in three formats:

    • Formatted View: A visual, easy-to-read display of the function calls
    • Raw XML: The exact XML code generated by the model
    • JSON View: The function calls converted into JSON for easier use in applications

### Working with Custom Tools

One of the most powerful features is the ability to create your own tools. Here’s how:

  1. Create a new tool:

    • Click “Add Custom Tool”
    • Describe your function clearly (you can even paste in API documentation)
    • Add parameters with their types and descriptions
    • Save the tool to use it later
  2. Example of a custom tool:

    {
      "name": "get_stock_price",
      "description": "Get the current stock price for a symbol",
      "parameters": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "The stock ticker symbol (like AAPL for Apple)"
          }
        },
        "required": ["symbol"]
      }
    }
    

    This tool tells the AI how to request stock prices by specifying the required stock symbol.

### Using the Tool Library

The tool comes with a library of pre-built tools to help you get started:

  1. Browse the available tools in the library section
  2. Click any tool to add it to your active set
  3. Remove tools by clicking the × on their badges

### Streaming Mode

Streaming mode lets you watch the AI generate responses in real time:

  • Toggle “Enable Streaming” before clicking “Generate Tool Calls”
  • Watch as words and XML tags appear one by one
  • Click “Stop” at any time to end the generation early

## Understanding the Output

### The XML Format

The tool expects the AI to generate responses in a specific XML format:

<tool_calls>
  <tool_call>
    <function>
      <name>function_name</name>
      <arguments>
        {"param": "value"}
      </arguments>
    </function>
  </tool_call>
</tool_calls>

This format ensures the tool can correctly identify which function to call and what parameters to use.

### Status Indicators

The tool uses color-coded indicators to show how well it parsed the response:

  • Green: Success! The XML was valid and the function calls were correctly understood.
  • Yellow: Partial success. The tool found some issues but managed to fix them.
  • Red: Error. The XML was too malformed to parse correctly.

## Tips and Best Practices

  1. Start simple
    Begin with easy prompts to make sure your setup works. For example, “Calculate 5 plus 3” is a good first test.

  2. Learn from built-in tools
    Use the pre-built tools as examples when creating your own. They show best practices for formatting and descriptions.

  3. Use streaming for long responses
    For complex requests, streaming mode helps you see progress instead of waiting for the full response.

  4. Save your work
    Export tool configurations that work well so you can reuse them in other projects.

  5. Check the console for errors
    If something isn’t working, open your browser’s developer console (F12 in most browsers) for detailed error messages.

## Troubleshooting Common Issues

### “Connection refused” error

This means the tool can’t reach your server. Try:

  • Making sure your VLLM server is running
  • Checking that the URL and port in settings are correct
  • Verifying your firewall isn’t blocking the connection

### “Unauthorized” error

This usually relates to your API key. Try:

  • Double-checking that your API key is entered correctly
  • Ensuring your API endpoint uses the OpenAI-compatible format

### No tool calls in the response

If the AI isn’t generating tool calls:

  • Make sure your model supports function calling
  • Try a more direct prompt, like “Use the calculator tool to multiply 10 and 7”
  • Lower the temperature setting (this makes responses more consistent)

### Malformed XML responses

If the XML looks messy or incomplete:

  • Let the tool try to fix it automatically (it’s designed for this!)
  • Adjust the temperature and top_p settings for more consistent outputs
  • Check that your initial instructions to the AI include the correct XML format

## Exploring Edge Cases in XML Tool Calls

When working with AI-generated XML, you might encounter responses that don’t follow the exact format. These “edge cases” are common, but the tool is designed to handle them. Let’s look at some examples and how the tool solves them.

### Missing Tags

Sometimes the AI might forget to include opening or closing tags.

  • Missing opening <tool_call> tag (happens in about 15% of responses):

    <function=calculator</function>
    <parameter=operation>multiply</parameter>
    <parameter=a>5</parameter>
    <parameter=b>3</parameter>
    </tool_call>
    

    Solution: The tool uses a backup pattern to find function calls even without the opening tag.

  • Missing closing </tool_call> tag (happens in about 2% of responses):

    <function=calculator>
    <parameter=operation>division</parameter>
    <parameter=a>88</parameter>
    <parameter=b>3</parameter>
    </function>
    

    Solution: The tool looks for the closing </function> tag instead to identify where the call ends.

### Malformed Parameters

Parameters (the inputs to functions) can sometimes be formatted incorrectly.

  • Equal sign format (happens in about 8% of responses):

    <parameter=operation=multiply</parameter>
    <parameter=a=15</parameter>
    <parameter=b=23</parameter>
    

    Solution: The tool has a special pattern to recognize parameters written with extra equal signs.

  • Empty tag with following value (happens in about 3% of responses):

    <parameter=body></parameter>
    Dear John,
    
    Please find the report attached.
    
    Best regards,
    Sarah
    

    Solution: The tool captures the text after an empty parameter tag until the next tag starts.

  • Mixed parameter formats (happens in about 5% of responses):

    <tool_call>
    <function=write_email</function>
    <parameter=to>john@example.com</parameter>
    <parameter=subject=Meeting Tomorrow</parameter>
    <parameter=body></parameter>
    Please join us at 2 PM.
    </tool_call>
    

    Solution: The tool uses three different checks to handle mixed formats in the same response.

### Content Edge Cases

The actual content inside parameters can sometimes cause issues, but the tool handles them smoothly.

  • Multiline parameter values:

    <parameter=message>
    Line 1
    Line 2
    Line 3
    </parameter>
    

    Solution: The tool preserves all line breaks and whitespace exactly as they appear.

  • Special characters:

    <parameter=query>SELECT * FROM users WHERE name = "John" AND age > 25</parameter>
    <parameter=regex>^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$</parameter>
    

    Solution: Special characters like quotes, asterisks, and symbols are kept as they are—no extra handling needed.

  • Unicode and emojis:

    <parameter=message>Hello 世界! 🌍 Welcome to the app! 🚀</parameter>
    

    Solution: The tool fully supports international characters and emojis.

  • HTML/XML in parameters:

    <parameter=html><div class="container"><p>Hello</p></div></parameter>
    

    Solution: Any HTML or XML inside parameters is treated as regular text, not code.

### Structural Edge Cases

Sometimes the overall structure of the XML might be unusual but still understandable.

  • Multiple tool calls:

    <tool_call>
    <function=get_weather</function>
    <parameter=city>New York</parameter>
    </tool_call>
    
    <tool_call>
    <function=get_weather</function>
    <parameter=city>London</parameter>
    </tool_call>
    

    Solution: The tool finds and processes all tool calls in the response.

  • Nested or embedded structures:

    <parameter=config>{"server": {"host": "localhost", "port": 8080}}</parameter>
    

    Solution: The tool keeps nested content (like JSON) as a single string, which your application can parse later.

  • Truncated responses:

    <tool_call>
    <function=calculator</function>
    <parameter=operation>multi
    

    Solution: The tool handles incomplete responses gracefully, either returning partial data or an empty result.

### Model Behavior Edge Cases

Sometimes the AI might not follow instructions at all. Here’s how the tool responds:

  • Direct answer instead of tool call (happens in about 5% of cases with unclear prompts):

    15 × 23 = 345
    

    Solution: The tool recognizes this as an error and suggests using clearer prompts that explicitly ask for tool calls.

  • Attribute-style XML (rare, less than 1% of responses):

    <tool_call function="calculator">
      <parameter name="operation" value="multiply"/>
    </tool_call>
    

    Solution: The tool detects this different format and can ask the AI to try again with the correct format.

  • Plain text explanation:

    I'll use the calculator tool to multiply 15 by 23. The result is 345.
    

    Solution: The tool tries to extract the intended function call from the explanation.

### Formatting Variations

Small differences in spacing or layout are common but don’t affect the tool’s ability to parse the XML.

  • Extra whitespace:

    <tool_call>
        <function=calculator</function>
        <parameter=operation>   multiply   </parameter>
        <parameter=a>
            15
        </parameter>
    </tool_call>
    

    Solution: The tool ignores extra spaces but keeps line breaks in multiline content.

  • No whitespace:

    <tool_call><function=calculator</function><parameter=operation>multiply</parameter></tool_call>
    

    Solution: The tool works even when everything is squished together with no spaces.

  • Inconsistent indentation:

    <tool_call>
    <function=write_email</function>
        <parameter=to>john@example.com</parameter>
            <parameter=subject>Test</parameter>
    <parameter=body>Hello</parameter>
    </tool_call>
    

    Solution: Indentation doesn’t matter—the tool focuses on the tags, not the spacing.

## How the XML Parser Works

The tool’s ability to handle all these edge cases comes from its smart parser. Let’s take a look at how it works under the hood.

### Core Patterns

The parser uses special patterns (called regular expressions) to find and understand XML content. Here are the key ones:

  1. Tool call detection:

    • Looks for the standard <tool_call>...</tool_call> tags first
    • If those are missing, it looks for function calls directly
    • As a last resort, it searches for just the <function=...> part
  2. Function extraction:

    • Finds function names inside <function=...> tags
    • Works even if the closing tag is missing or malformed
  3. Parameter extraction:

    • Handles three common parameter formats:

      • Standard: <parameter=name>value</parameter>
      • Malformed: <parameter=name=value</parameter>
      • Empty tag: <parameter=name></parameter> followed by text

### Parsing Steps

The parser works in phases to make sure it captures as much as possible:

  1. Phase 1: Find tool calls
    It checks for tool calls using the three patterns above, starting with the most common format.

  2. Phase 2: Extract the function name
    For each tool call found, it identifies the function name (like “calculator” or “get_weather”).

  3. Phase 3: Extract parameters
    It runs three passes to collect parameters, using each of the three formats. This ensures even mixed formats are captured correctly.

  4. Phase 4: Convert types
    It converts parameter values to the right type (number, boolean, or string) automatically. For example, “15” becomes the number 15, and “true” becomes a boolean true.

### JavaScript Implementation

The tool uses JavaScript in your browser to parse responses. This means it works without a server and keeps your data local. The JavaScript code uses the same patterns and steps as the Python version, ensuring consistent results.

One key thing to note is that JavaScript handles regular expressions a bit differently, so the code includes special checks to make sure patterns work correctly across different browsers.

### Error Handling

The parser is designed to fail gracefully:

  • If it can’t find any valid tool calls, it returns an empty list
  • If a function name is missing, it skips that tool call
  • If parameters are malformed, it tries all three formats before giving up
  • If it can’t convert a value to a number or boolean, it keeps it as a string

## Testing the Parser

To make sure the parser handles all these cases, it’s tested extensively:

### Unit tests

Every edge case has its own test. For example:

def test_missing_tool_call_opening_tag(self):
    """Test parser handles missing <tool_call> opening tag"""
    xml = '''<function=calculator</function>
    <parameter=operation>multiply</parameter>
    <parameter=a>5</parameter>
    <parameter=b>3</parameter>
    </tool_call>'''
    
    result = self.parser.parse(xml)
    self.assertEqual(len(result), 1)
    self.assertEqual(result[0]['function'], 'calculator')

### Manual testing

You can test specific cases yourself using the tool:

  1. Open tool_call_explorer.html
  2. Paste the XML you want to test
  3. Click “Parse Tool Call”
  4. Check if it parses correctly

## How to Prevent Common Issues

You can reduce the number of edge cases by:

  1. Using clear system prompts
    Tell the AI exactly what format to use, like:

    IMPORTANT: You MUST use this EXACT format:
    <tool_call>
    <function=tool_name</function>
    <parameter=param_name>param_value</parameter>
    </tool_call>
    
    Do NOT use any other XML format.
    
  2. Adjusting temperature settings
    Lower temperature values (like 0.3) make responses more consistent:

    "temperature": 0.3,  # More consistent formatting
    "top_p": 0.95,
    "repetition_penalty": 1.0
    
  3. ** Including examples**
    Show the AI what you want by including examples in your prompt:

    Example:
    User: Calculate 10 times 5
    Assistant: <tool_call>
    <function=calculator</function>
    <parameter=operation>multiply</parameter>
    <parameter=a>10</parameter>
    <parameter=b>5</parameter>
    </tool_call>
    

## Recovery Strategies

If parsing fails completely, the tool can:

  1. Ask the AI again with stricter format requirements
  2. Include a specific example of the correct format
  3. Try to figure out the intended tool call from the response
  4. Suggest reducing the maximum number of words if the response was cut off
  5. Ask the user to rephrase their request

## Technical Details

  • Framework: Built with plain JavaScript—no extra libraries needed
  • Compatibility: Works with any API that uses the OpenAI format
  • Storage: Saves your settings and custom tools in your browser’s local storage
  • Security: Your API keys stay on your computer and are only sent to your configured endpoint

## Future Improvements

The tool is constantly being improved, with plans for:

  1. Better streaming support
    Parsing responses as they arrive, even before they’re complete.

  2. Performance tracking
    Showing how fast the parser works and using that data to make it better.

  3. Multiple format support
    Handling both XML and JSON function calls.

  4. Validation checks
    Making sure tool calls match the required parameters for each function.

  5. Detailed error messages
    Showing exactly where parsing went wrong and how to fix it.

## License

This tool is provided as-is for educational and development purposes. You’re free to modify and share it however you like.

The QWEN XML Tool Call Explorer is designed to make working with AI function calls easier for developers of all skill levels. By handling common edge cases, providing clear visualizations, and working with both local and cloud-based APIs, it’s a versatile tool that can save you time and frustration. Whether you’re building a weather app, a stock tracker, or any other application that uses AI tools, this explorer can help you test and refine your code with confidence.