Verification
Problem
Plugins cannot strip or transform messages before they reach the LLM. When a user attaches an image, the LLM errors out with "this model does not support image input".
The existing hooks have limitations:
Proposed Solution
Add pre_chat.messages.transform — a hook that fires before the LLM, receiving the full messages array and allowing plugins to transform them:
"pre_chat.messages.transform"?: (
input: {
sessionID: string
agent: string
model: Model
messages: { info: Message; parts: Part[] }[]
},
output: { messages: { info: Message; parts: Part[] }[] },
) => Promise<void>
Use Cases
- Image-to-text stripping: Scan for
FilePart with image: true, call a Vision server (Qwen2.5-VL-3B), replace with TextPart containing the description
- Vision plugin integration: Transform messages on-the-fly so the LLM always receives text-only input
- Pre-inference modification: Any plugin that needs to modify messages before the LLM
Backward Compatibility
experimental.chat.messages.transform is non-functional (empty input). Marked @deprecated and replaced by this new hook
- No breaking changes to existing hooks
Required Go Binary Change (separate PR)
The Go binary needs to:
- Register
pre_chat.messages.transform hooks from the plugin registry
- Call them with the messages array before invoking the LLM
- Collect
output.messages and pass the transformed array to the model
PR
SDK type changes: #25493
Verification
Problem
Plugins cannot strip or transform messages before they reach the LLM. When a user attaches an image, the LLM errors out with
"this model does not support image input".The existing hooks have limitations:
experimental.chat.messages.transformhasinput: {}— it never receives messages (system.transform fires after messages.transform — plugins can't coordinate system+message mutations #19960)message.parts.beforefor image handling but it is not implementedProposed Solution
Add
pre_chat.messages.transform— a hook that fires before the LLM, receiving the full messages array and allowing plugins to transform them:Use Cases
FilePartwithimage: true, call a Vision server (Qwen2.5-VL-3B), replace withTextPartcontaining the descriptionBackward Compatibility
experimental.chat.messages.transformis non-functional (empty input). Marked@deprecatedand replaced by this new hookRequired Go Binary Change (separate PR)
The Go binary needs to:
pre_chat.messages.transformhooks from the plugin registryoutput.messagesand pass the transformed array to the modelPR
SDK type changes: #25493