Skip to content

feature: Support custom tool parsers #2917

Closed as not planned
Closed as not planned

Description

@shantur

AI SDK provides a capability to allow custom tool parsers documented - https://ai-sdk.dev/docs/ai-sdk-core/middleware#custom-tool-call-parser

Can this be implemented? Maybe atleast the @ai-sdk-tool/parser package. It offers three middlewares OOB

gemmaToolMiddleware: JSON tool calls inside markdown fences. Best for Gemma-like models.
morphXmlToolMiddleware: Plain XML tool calls. Good fit for GLM/GLM-like models.
hermesToolMiddleware: JSON payload wrapped in <tool_call> XML tags. Hermes/Llama-style prompts.

This will allow Opencode to be compatible with a lot of locally hosted models.

It can be an option to set a middleware as part of custom providers configuration for a model. Initially could be just one of these 3 above, maybe down the line a way of providing our own like plugins / custom tools.

Activity

  1. github-actions commented on Oct 2, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node commented on Oct 2, 2025

    @rekram1-node
    Contributor

    would need to look at it more but it sounds reasonable

  3. minpeter commented on Feb 11, 2026

    @minpeter

    I am the maintainer of the ai-sdk-tool-call-middleware project, and I am very willing to support this work.

    Thanks for the suggestion, @shantur

  4. okuyam2y commented on Apr 3, 2026

    @okuyam2y

    I have a working integration of @ai-sdk-tool/parser with OpenCode. Since upstream integration is still pending, I've published it as an experimental fork:

    https://github.com/okuyam2y/opencode-nofc

    It adds a toolParser option on provider/model config (hermes | hermes-strict | xml) that gates middleware injection plus the finish-reason/tag cleanup those parsers need. Also includes streaming tag filter, stream deduplication, and document extraction (PDF/DOCX/XLSX).

    This is experimental and tracks upstream dev branch. If you're hitting this issue with a gateway or provider that doesn't support native function calling, feel free to try it out.

  5. okuyam2y commented on Apr 3, 2026

    @okuyam2y

    One additional thing that may be worth documenting: reliability with custom tool parsers seems much more model-dependent than with native function calling.

    In our testing, higher-capability models such as GPT-5.4 and Claude Sonnet 4.5 were the first ones that were consistently reliable on multi-step review workflows, while lower-tier models often handled simple cases but degraded on longer runs.

    If this support lands, it would be helpful for the docs to note that users should validate parser behavior on a representative multi-step workflow before relying on it in production.

  6. github-actions commented on Jun 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions