Skip to content

feat(core): support valibot and other schema libraries via xsschema, not just zod #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

baseballyama
Copy link
Contributor

related: #143

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

We can use only zod.

What is the new behavior?

We can use valibot and other schema libraries also.

Notes for reviewers

This PR is the first step to support schema libraries other than zod in voltagent.
I plan to split the work by package, adding support for schema libraries like valibot to each package one by one.
Finally, I will update the documentation in the last PR.
This PR is not complete yet, but I would like to confirm if the direction of these changes is correct, so I am opening it as a WIP PR.

Copy link

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: 0d3cfe1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@voltagent/core Minor
@voltagent/anthropic-ai Major
@voltagent/google-ai Patch
@voltagent/groq-ai Patch
@voltagent/langfuse-exporter Major
@voltagent/postgres Patch
@voltagent/sdk Patch
@voltagent/supabase Major
@voltagent/vercel-ai-exporter Patch
@voltagent/vercel-ai Major
@voltagent/voice Patch
@voltagent/xsai Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@baseballyama baseballyama force-pushed the feat/valibot branch 4 times, most recently from 4fffe9e to a98cdd5 Compare May 27, 2025 10:40
@omeraplak
Copy link
Member

Hey @baseballyama , thanks a lot for the contribution! There are a few conflicts. Would you like to resolve them, or should I take care of it? Just let me know!

@baseballyama
Copy link
Contributor Author

@omeraplak Thank you for the reminder. I plan to come back to this PR tomorrow and will rebase it then!

@tbashiyy
Copy link

tbashiyy commented Jun 2, 2025

@baseballyama
[just ask]
Is it difficult to use @standard-schema/spec directly instead of using xsschema ?

https://github.com/standard-schema/standard-schema/tree/main/packages/spec#how-do-i-accept-standard-schemas-in-my-library

@baseballyama
Copy link
Contributor Author

baseballyama commented Jun 2, 2025

I’m currently studying both xsschema and voltagent at the same time, making incremental changes while maintaining compatibility. While it may end up that way in the end, I’m not sure yet. That’s one of the reasons why this PR is still a work in progress.

I have other priorities at the moment, but I plan to come back to this PR right after that.

@kwaa
Copy link
Contributor

kwaa commented Jun 2, 2025

[just ask] Is it difficult to use @standard-schema/spec directly instead of using xsschema ?

I also recommend using @standard-schema/spec directly if only types are needed.

The main feature of xsSchema is the toJsonSchema function, which converts any supported schema to JSON schema.

https://xsai.js.org/docs/packages-top/xsschema#tojsonschema

@baseballyama
Copy link
Contributor Author

@kwaa I’m back to working on this PR. Since VoltAgent converts schemas like zod/valibot to JSON Schema for LLM providers, I’m convinced that xsschema is necessary. I’m currently trying to use toJsonSchema, but since VoltAgent doesn’t know the validation library in advance, I’m not sure how to call initToJsonSchemaSyncVendor. Do you have any ideas? Is the only option to have users specify the schema library name? Or should I use property names like zodSchema or valibotSchema instead of just schema so that the library can be identified?

@kwaa
Copy link
Contributor

kwaa commented Jun 7, 2025

@kwaa I’m back to working on this PR. Since VoltAgent converts schemas like zod/valibot to JSON Schema for LLM providers, I’m convinced that xsschema is necessary. I’m currently trying to use toJsonSchema, but since VoltAgent doesn’t know the validation library in advance, I’m not sure how to call initToJsonSchemaSyncVendor. Do you have any ideas? Is the only option to have users specify the schema library name? Or should I use property names like zodSchema or valibotSchema instead of just schema so that the library can be identified?

You only need to use asynchronous methods. only synchronous methods need init

@baseballyama
Copy link
Contributor Author

baseballyama commented Jun 7, 2025

I need to call toJsonSchemaSync within an existing synchronous method.
I’m wondering if I have no choice but to introduce breaking changes.

e.g.

toTool(tool: BaseTool): AnthropicTool {
return {
name: tool.name,
description: tool.description,
input_schema: zodToJsonSchema(tool.parameters),
};
}

@baseballyama
Copy link
Contributor Author

I found this issue. It seems we might have to implement things manually for each validation library.

modelcontextprotocol/typescript-sdk#164 (comment)

@baseballyama
Copy link
Contributor Author

Currently, @modelcontextprotocol/sdk only supports zod, so I’ve hit a roadblock. I’ve posted an idea to support standard schemas in @modelcontextprotocol/sdk. I’d appreciate it if you could share your thoughts on this from the VoltAgent team’s perspective as well.

modelcontextprotocol/typescript-sdk#164 (comment)

@omeraplak
Copy link
Member

Currently, @modelcontextprotocol/sdk only supports zod, so I’ve hit a roadblock. I’ve posted an idea to support standard schemas in @modelcontextprotocol/sdk. I’d appreciate it if you could share your thoughts on this from the VoltAgent team’s perspective as well.

modelcontextprotocol/typescript-sdk#164 (comment)

Ah, that’s a tough blocker. Thanks for flagging it. I agree, this might take some time to land on the MCP side. Appreciate you pushing this forward

@kwaa
Copy link
Contributor

kwaa commented Jun 7, 2025

btw, I also wrote the "xs" version of the MCP SDK: https://github.com/moeru-ai/xsmcp
It is based on xsSchema instead of Zod. (However, only Streamable HTTP is supported now.)

@kwaa
Copy link
Contributor

kwaa commented Jun 7, 2025

I need to call toJsonSchemaSync within an existing synchronous method. I’m wondering if I have no choice but to introduce breaking changes.

You can get the vendor name from schema['~standard'].vendor - but it still requires an asynchronous init in one place.

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.

4 participants