Skip to content

Conversation

@otchlan
Copy link

@otchlan otchlan commented Dec 23, 2025

Problem

Fixes #486

The ChatMessageInput interface did not allow the tool role, even though this role was defined in ChatMessageRoleData and is necessary for proper tool calling workflows.

This prevented users from:

  • Importing/exporting chat histories with tool calls
  • Continuing conversations after tool execution
  • Building agents that use tools locally

Solution

Changed ChatMessageInput to use ChatMessageRoleData type instead of hardcoded union type:

  • Updated role field to use ChatMessageRoleData
  • Updated chatMessageInputSchema to use chatMessageRoleDataSchema

Testing

Created a reproduction test that verifies Chat.from() now accepts messages with role: "tool":

const chat = Chat.from([
  { role: "user", content: "Can you search for something?" },
  { role: "assistant", content: "Sure, I'll search for that." },
  { role: "tool", content: "Search results: ..." }  // ✅ Now works!
]);

Changes

  • packages/lms-client/src/ChatInput.ts: Updated interface and schema

@github-actions
Copy link

github-actions bot commented Dec 23, 2025


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 104 to 124
return {
role: role ?? "user",
content: parts,
};
} as ChatMessageData;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Tool role converted to wrong content shape

Allowing ChatMessageRoleData in ChatMessageInput means callers can now pass { role: "tool", content: "..." }, but chatMessageInputToChatMessageData still always builds text/file parts and then forcibly casts the result to ChatMessageData here. Per ChatHistoryData.ts (lines 139‑157) tool messages must contain toolCallResult parts, so a tool message created through Chat.from now produces an invalid ChatMessageData object. Any downstream validation with chatMessageDataSchema (e.g., when cloning a ChatMessage) or the LLM request path will throw or drop the tool result because the expected toolCallResult part is missing.

Useful? React with 👍 / 👎.

- Changed ChatMessageInput.role type from hardcoded union to ChatMessageRoleData
- Updated chatMessageInputSchema to use chatMessageRoleDataSchema
- Fixes issue lmstudio-ai#486: ChatMessageInput does not allow 'tool' role
@otchlan otchlan force-pushed the fix/chatmessageinput-tool-role branch from cf17f0e to d1d7f6d Compare December 24, 2025 19:47
Copy link
Author

@otchlan otchlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the CLA Document and I hereby sign the CLA

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.

ChatMessageInput does not allow "tool" role

1 participant