Skip to content

feat(plugin): add pre_chat.messages.transform hook for image stripping#25493

Open
n1flh31mur wants to merge 2 commits intoanomalyco:devfrom
n1flh31mur:feature/pre-chat-messages-transform
Open

feat(plugin): add pre_chat.messages.transform hook for image stripping#25493
n1flh31mur wants to merge 2 commits intoanomalyco:devfrom
n1flh31mur:feature/pre-chat-messages-transform

Conversation

@n1flh31mur
Copy link
Copy Markdown

@n1flh31mur n1flh31mur commented May 2, 2026

Issue for this PR

Closes #25494

Type of change

  • New feature
  • Bug fix
  • Refactor / code improvement
  • Documentation

What does this PR do?

The SDK defines a pre_chat.messages.transform hook type that fires before the LLM is invoked, allowing plugins to inspect and transform the messages array. Currently this type is declared in the SDK but the Go binary does not dispatch it — the PR adds the type so plugins can register a handler.

The hook receives the full messages array (sessionID, agent, model, messages with parts) and lets plugins return a transformed array. A plugin can scan for FilePart objects with image: true, call a Vision server to get a text description, and replace each image part with a TextPart containing that description.

This enables vision/image support without modifying the Go binary — once the binary starts dispatching this hook, plugins like noctem-swarm-vision can strip images on-the-fly.

The existing experimental.chat.messages.transform hook is marked @deprecated because it has empty input (input: {}) and never receives messages.

How did you verify your code works?

  • Verified the TypeScript types compile correctly (the file is a type declaration, no runtime code)
  • Confirmed the hook signature follows the same pattern as existing hooks like chat.params and tool.execute.before
  • Tested that the deprecated marker on experimental.chat.messages.transform is syntactically valid

Screenshots / recordings

N/A — type-only change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add a new hook type that fires BEFORE the LLM is invoked, allowing
plugins to inspect and transform the messages array. This enables:

- Image-to-text stripping (replace FilePart with text descriptions)
- Vision plugin integration (add Qwen2.5-VL-3B descriptions)
- Pre-inference message modification

The existing experimental.chat.messages.transform had empty input
and was non-functional. Mark it as deprecated.

Changes:
- Add pre_chat.messages.transform hook with full messages input
- Mark experimental.chat.messages.transform as @deprecated
- Document the hook's purpose and usage pattern
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 2, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

…vocation

Add the runtime dispatch of pre_chat.messages.transform in the main
prompt processing pipeline. This fires after system prompt assembly
but before tool resolution and the LLM API call.

Also fixes the existing experimental.chat.messages.transform call
to pass proper input context (sessionID, agent, model, messages)
instead of an empty object.

This is the companion to PR anomalyco#25493 which adds the SDK type
definitions. Without this dispatch, the hook type exists but
is never called at runtime.
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.

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

1 participant