Skip to content

fix(llm-script): make shuffle tool-friendly for OpenAI-style JSON (HA LLM integrations) - #131

Open
beralt85 wants to merge 1 commit into
music-assistant:mainfrom
beralt85:fix/llm-script-shuffle-string-tool-args
Open

fix(llm-script): make shuffle tool-friendly for OpenAI-style JSON (HA LLM integrations)#131
beralt85 wants to merge 1 commit into
music-assistant:mainfrom
beralt85:fix/llm-script-shuffle-string-tool-args

Conversation

@beralt85

Copy link
Copy Markdown

Summary

Updates the LLM Script for Music Assistant blueprint so the shuffle script field works reliably when an LLM calls it via OpenAI-style function/tool JSON (e.g. Custom Conversation + LiteLLM + a local OpenAI-compatible server such as vLLM).

Context

My goal was to have complete local voice control, without relying on external providers. Since the official LLM integrations do not allow the specification of a custom (local) OpenAI compatible endpoint, I was trying to use this script with this project: https://github.com/michelle-avery/custom-conversation .

While the LLM generated a valid tool call .json (as specified by the script), the parsing of the boolean variable failed

{"media_type": "artist",
 "artist": "Pink Floyd",
 "album": "",
 "media_id": "Pink Floyd",
 "media_description": "Pink Floyd",
 "shuffle": false}

Changing this to a string and then adding the additional parsing as in this PR, resolved the problem.

Setup was vLLM backend running this model https://huggingface.co/btbtyler09/Qwen3-Coder-30B-A3B-Instruct-gptq-4bit.

More Details


Problem

Some Home Assistant LLM integrations (in particular: https://github.com/michelle-avery/custom-conversation) parse tool arguments against the script’s field schema. With shuffle defined as a boolean selector, tool calls that include JSON booleans (e.g. "shuffle": false) can fail with “Failed to parse tool arguments” even when the JSON is valid. The model output was observed streaming correctly; the failure happened when mapping arguments to the script fields.


Solution

  • Change fields.shuffle from boolean to text so string values from tool JSON are accepted.
  • Normalize the field to a real boolean in the script variables step (same idea as the previous | bool(false)), including support for common string forms ("true", "1", "yes", "on").
  • Document in the blueprint description and in the default shuffle prompt that JSON tool calls should use the strings "true" / "false" when needed for compatibility.
  • Bump the internal script version to 20260416 so instances can tell the blueprint changed.

Testing

  • Imported updated blueprint and created/updated a script from it.
  • Ran the script from Developer tools → Actions (or the script Run UI) with:
    • shuffle: false (boolean)
    • shuffle: "false" (string)
    • shuffle off / not set as appropriate
  • Confirmed playback and media_player.shuffle_set behavior.
  • (Optional) Re-tested voice path with Custom Conversation + local LLM.

Backward compatibility

  • Automations or YAML that pass shuffle: true / shuffle: false as booleans should still work; the template treats native booleans like before and applies | bool at the end.
  • The UI for shuffle changes from a toggle to a text field

…ibilityfix(llm-script): text shuffle field + bool() for LLM tool JSON compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant