Skip to content

[FEATURE] pre_chat.messages.transform hook for image-to-text stripping #25494

@n1flh31mur

Description

@n1flh31mur

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

  1. Image-to-text stripping: Scan for FilePart with image: true, call a Vision server (Qwen2.5-VL-3B), replace with TextPart containing the description
  2. Vision plugin integration: Transform messages on-the-fly so the LLM always receives text-only input
  3. 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:

  1. Register pre_chat.messages.transform hooks from the plugin registry
  2. Call them with the messages array before invoking the LLM
  3. Collect output.messages and pass the transformed array to the model

PR

SDK type changes: #25493

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions