llm_tool_firebase_ai library
Use llm_tool with Firebase AI Logic (firebase_ai).
final model = FirebaseAI.googleAI().generativeModel(
model: 'gemini-3.8-flash',
tools: [Tool.functionDeclarations(allTools.toFunctionDeclarations())],
);
final reply = await model.startChat().sendMessageWithTools(
Content.text('What is the weather in Kanpur?'),
allTools,
);
Classes
-
ToolDefinition<
T> - A tool an LLM can call: its name, description, JSON schema and code.
- ToolResult
- What happened when a tool was invoked, ready to send back to the model: a value on success, or an error written for the model to read.
Extensions
- ChatSessionToolCalling on ChatSession
- Runs tools in a chat, so you don't write the tool-call loop yourself.
- ToolDefinitionFirebaseAI on ToolDefinition
- Converts one tool to firebase_ai declarations.
- ToolDefinitionFormats on ToolDefinition
-
A tool in each provider's JSON format, to pass to that provider's SDK
(e.g. its
Tool.fromJson) or REST API. No SDK is needed. -
ToolListFirebaseAI
on Iterable<
ToolDefinition> -
Converts a list of tools, e.g. the generated
allTools. -
ToolListFormats
on Iterable<
ToolDefinition> -
The same formats for a list of tools, e.g. the generated
allTools, and running a model's call by the tool name it sent.
Functions
-
toFirebaseJsonSchema(
Map< String, Object?> schema) → JSONSchema -
Converts a JSON Schema map, as in ToolDefinition.parametersSchema, to
firebase_ai's
JSONSchema. -
toolResponses(
Iterable< FunctionResponse> responses) → Content -
Tool results to send back to Gemini:
chat.sendMessage(toolResponses(r)). -
toolSchemaSnapshot(
Iterable< ToolDefinition> tools) → String -
Everything the LLM sees of
tools, as stable, readable JSON, for a snapshot test that fails when a schema changes: -
validateArguments(
Map< String, Object?> schema, Map<String, Object?> args) → List<String> -
Checks
argsagainst a JSON Schemaschema. Returns a list of problems; an empty list means the arguments are valid. -
withoutAdditionalProperties(
Map< String, Object?> schema) → Map<String, Object?> -
A copy of
schemawithoutadditionalProperties, at every level.
Typedefs
-
ToolConfirmation
= FutureOr<
bool> Function(ToolDefinition tool, Map<String, Object?> args) -
Asks the user whether
toolmay run withargs. Returntrueto run it.
Exceptions / Errors
- ToolArgumentException
- Thrown when the AI sends arguments that don't match a tool's schema.