tool_schema_generator 1.1.0
tool_schema_generator: ^1.1.0 copied to clipboard
Generate provider-compatible LLM tool schemas and dispatchers from annotated Dart functions.
Example usage of tool_schema_generator #
This example demonstrates how to use the tool_schema_generator package to automatically generate provider-compatible LLM tool schemas for your Dart functions.
The sample covers:
- primitive, enum, list, map, and nested-class parameters
- provider selection with
@Tool(formats: [...]) - generated
toolRegistrydispatch handlers - the generated schema output produced by the new parser/spec/emitter architecture
Setup #
- Add
tool_schema_generatorto yourdependencies. - Add
build_runnerto yourdev_dependencies.
dependencies:
tool_schema_generator: ^1.0.0
dev_dependencies:
build_runner: ^2.4.0
Running the generator #
After adding your @Tool() annotations, run the build runner to generate the .g.dart file:
dart run build_runner build
Check out lib/tools.dart in this example to see how the annotations are used.
The checked-in lib/tools.g.dart file shows the generated registry and schema
maps.
To try strict schemas, add strict: true to one of the @Tool() annotations:
@Tool(strict: true)
void findNearbyPlaces(GeoLocation location) {}
Strict tools close object schemas with additionalProperties: false, require
all visible properties, render nullable fields as JSON Schema type unions, and
emit strict provider flags where supported.