gemini_agent_tools 0.0.3 copy "gemini_agent_tools: ^0.0.3" to clipboard
gemini_agent_tools: ^0.0.3 copied to clipboard

Code generation for tools sections of Gemini REST API.

gemini_agent_tools #

Note: This package was developed for use alongside a University final year project, though it was published to make it easier for me to use as well as as an exercies in publishing.

gemini_agent_tools is a Dart/Flutter package that enables automatic code generation for Gemini-style agent tool declarations to be used in with the REST api, specifically the function declaration format specified here.

It allows you to define tools as annotated Dart classes, and a custom build_runner generator produces the correct API-ready JSON schemas automatically.

This eliminates manual boilerplate, keeps tool definitions type-safe, and ensures your agent functions remain in sync with your code.


🚀 Features #

  • 🔧 Annotate classes to define agent tools

  • ⚙️ Build-runner code generator creates *.tools.g.dart output

  • 📐 Auto-generates:

    • tool names
    • descriptions
    • JSON schema parameters and their types*
    • property ordering
    • required fields
  • 🐍 Converts camelCase → snake_case automatically

* Only String, bool and int types currently supported.


📥 Installation #

Add the package:

dart pub add gemini_agent_tools

And the dev dependency for build_runner:

dart pub add --dev build_runner

🧩 Usage #

1. Annotate a class with @Tool #

import 'package:gemini_agent_tools/tool_annotation.dart';

@Tool(
  name: "save",
  description: "Stores information to agent memory",
  requiredFields: ["agentNotes"],
)
class SaveTool {
  final String agentNotes;

  SaveTool(this.agentNotes);
}

The annotation fields:

Field Type Description
name String The tool's function name
description String Human-readable description
requiredFields (optional) List<String> Marks parameters as required

Parameters are generated from class fields automatically.


2. Run the generator #

dart run build_runner build

This will produce a file:

save_tool.tools.g.dart

3. Generated Output Example #

const Map saveToolAsMap = {
  "name": "save",
  "description": "Stores information to agent memory",
  "parameters": {
    "type": "object",
    "properties": {
      "agent_notes": {"type": "string"}
    },
    "propertyOrdering": ["agent_notes"],
    "required": ["agent_notes"]
  }
};

This object is ready to pass directly into a Gemini REST API functionDeclarations list.

0
likes
50
points
26
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Code generation for tools sections of Gemini REST API.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

analyzer, build, flutter, source_gen

More

Packages that depend on gemini_agent_tools