From 91273b556b8f540eb1a4de652c727665b7b2b2af Mon Sep 17 00:00:00 2001 From: Hiepler Date: Fri, 20 Mar 2026 10:46:40 +0100 Subject: [PATCH 1/2] Fix tool calling implementation to match LLM framework API --- llm_grok.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/llm_grok.py b/llm_grok.py index d9ede60..0f748dc 100644 --- a/llm_grok.py +++ b/llm_grok.py @@ -143,18 +143,18 @@ def build_messages(self, prompt, conversation): messages.append( {"role": "system", "content": prev_response.prompt.system} ) - messages.append( - {"role": "user", "content": prev_response.prompt.prompt} - ) - # Add tool_results after user message if present + # Add tool_results before user message (they belong to the previous turn) if prev_response.prompt.tool_results: for tool_result in prev_response.prompt.tool_results: messages.append({ "role": "tool", "tool_call_id": tool_result.tool_call_id, - "content": tool_result.content, + "content": tool_result.output, }) - + messages.append( + {"role": "user", "content": prev_response.prompt.prompt} + ) + # Add assistant response with tool_calls if present tool_calls = prev_response.tool_calls() content = prev_response.text() @@ -164,24 +164,24 @@ def build_messages(self, prompt, conversation): if tool_calls: assistant_message["tool_calls"] = [ { - "id": tc.id, + "id": tc.tool_call_id, "type": "function", "function": { "name": tc.name, - "arguments": tc.arguments, + "arguments": json.dumps(tc.arguments), }, } for tc in tool_calls ] messages.append(assistant_message) - # Add tool_results before final user message if present + # Add tool_results before final user message (they belong to the previous turn) if prompt.tool_results: for tool_result in prompt.tool_results: messages.append({ "role": "tool", "tool_call_id": tool_result.tool_call_id, - "content": tool_result.content, + "content": tool_result.output, }) messages.append({"role": "user", "content": prompt.prompt}) @@ -346,7 +346,7 @@ def execute(self, prompt, stream, response, conversation, key=None): "function": { "name": tool.name, "description": tool.description, - "parameters": tool.parameters, + "parameters": tool.input_schema, }, } for tool in prompt.tools @@ -420,9 +420,9 @@ def execute(self, prompt, stream, response, conversation, key=None): if tc["id"] and tc["function"]["name"]: response.add_tool_call( llm.ToolCall( - id=tc["id"], + tool_call_id=tc["id"], name=tc["function"]["name"], - arguments=tc["function"]["arguments"], + arguments=json.loads(tc["function"]["arguments"]), ) ) else: @@ -444,9 +444,9 @@ def execute(self, prompt, stream, response, conversation, key=None): for tool_call_data in message["tool_calls"]: response.add_tool_call( llm.ToolCall( - id=tool_call_data["id"], + tool_call_id=tool_call_data["id"], name=tool_call_data["function"]["name"], - arguments=tool_call_data["function"]["arguments"], + arguments=json.loads(tool_call_data["function"]["arguments"]), ) ) if "content" in message: From 0f1ab51668b23626c2b18346fc7997e27be4afea Mon Sep 17 00:00:00 2001 From: Hiepler Date: Fri, 20 Mar 2026 10:48:08 +0100 Subject: [PATCH 2/2] change version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a0a6201..1df128a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "llm-grok" -version = "1.4.1" +version = "1.4.2" description = "LLM plugin providing access to Grok models using the xAI API" readme = "README.md" authors = [{name = "Benedikt Hiepler"}]