feat(rig-derive): replace hand-rolled schema with schemars in #[rig_tool] (#1576)
- fix(rig-derive): default required to all parameters when not specified
Previously, omitting
required(...)from#[rig_tool]produced an emptyrequiredarray in the JSON Schema, making all parameters optional. This silently breaks strict function calling (e.g. OpenAI) where all params are typically required.Now all parameters are required by default. Explicit
required(...)still works as an override for tools with truly optional params.
- feat(rig-derive): replace hand-rolled schema with schemars in #[rig_tool]
Replace get_json_type() with schemars::JsonSchema derivation on the generated params struct. Schema is now produced via schema_for!() at runtime — the same pattern AgentToolArgs already uses.
Key changes:
- Derive JsonSchema on params struct, use schema_for!() in definition()
- Extract doc comments from functions and parameters for descriptions
- Auto-add #[serde(default)] on Option fields
- Strip #[doc] attrs from fn params before re-emitting (compiler rejects them)
- Re-export schemars from rig-core as rig::schemars
Breaking: i32 now produces “type”: “integer” (was “number”).
Tests: 23 pass covering doc comments, Option, enums, HashMap, nested structs, Vec, async, visibility, required defaults.
- fix(openai): ensure properties key exists on object schemas in sanitizer
OpenAI rejects object schemas without a “properties” key (400: “object schema missing properties”), even for zero-parameter tools. Anthropic accepts bare {“type”: “object”} without properties.
Add the missing-properties injection to openai::sanitize_schema, which also covers Azure since it delegates to the same function.
fix(rig-derive): satisfy clippy in schemars tests
fix(rig-derive): preserve explicit empty required list
Co-authored-by: stephen stephen.korzen@gmail.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
📑 Docs • 🌐 Website • 🤝 Contribute • ✍🏽 Blogs
✨ If you would like to help spread the word about Rig, please consider starring the repo!
Table of contents
What is Rig?
Rig is a Rust library for building scalable, modular, and ergonomic LLM-powered applications.
More information about this crate can be found in the official and crate API reference documentation.
Features
Who is using Rig?
Below is a non-exhaustive list of companies and people who are using Rig:
proteinpaint, a genomics visualisation tool.rigfor simplifying LLM calls and implementing the model picker.For a full list, check out our ECOSYSTEM.md file.
Are you also using Rig? Open an issue to have your name added!
Get Started
Use the root
rigfacade when you want feature-gated access to companion crates, or userig-coredirectly when you only need the core provider abstractions.Simple example
Note using
#[tokio::main]requires you enable tokio’smacrosandrt-multi-threadfeatures or justfullto enable all features (cargo add tokio --features macros,rt-multi-thread).You can find more examples in each crate’s
examplesdirectory (for example,examples). Provider-specific integration coverage lives undertests/providers, with cassette-backed tests that replay offline by default and live-only tests kept separate when real provider APIs are still required. Seetests/README.mdfor test target, replay, record, and cassette safety commands. More detailed use case walkthroughs are regularly published on our Dev.to Blog and added to Rig’s official documentation at docs.rig.rs.Supported Integrations
The root
rigfacade exposes companion crates behind one feature per integration:rig-bedrockbedrockrig::bedrockrig-s3vectorss3vectorsrig::s3vectorsrig-vectorizevectorizerig::vectorizerig-fastembedfastembedrig::fastembedrig-gemini-grpcgemini-grpcrig::gemini_grpcrig-vertexaivertexairig::vertexairig-helixdbhelixdbrig::helixdbrig-lancedblancedbrig::lancedbrig-memorymemoryrig::memoryrig-milvusmilvusrig::milvusrig-mongodbmongodbrig::mongodbrig-neo4jneo4jrig::neo4jrig-postgrespostgresrig::postgresrig-qdrantqdrantrig::qdrantrig-scylladbscylladbrig::scylladbrig-sqlitesqliterig::sqliterig-surrealdbsurrealdbrig::surrealdbrig::memoryis available without thememoryfeature; it contains the core conversation memory traits and in-memory backend re-exported fromrig-core. Enablingfeatures = ["memory"]adds reusable history-shaping policy types from therig-memorycompanion crate to the same module.We also have some other associated crates that have additional functionality you may find helpful when using Rig:
rig-onchain-kit- the Rig Onchain Kit. Intended to make interactions between Solana/EVM and Rig much easier to implement.