flutter_ai_tools 0.1.4
flutter_ai_tools: ^0.1.4 copied to clipboard
Provider-neutral tool calling for flutter_ai: declare tools with executors, run tool calls into results, and expose web search as a tool. Pure Dart.
flutter_ai_tools
Provider-neutral tool calling for flutter_ai — declare a ToolSpec, register it, and let the agent loop run it. Pure Dart, with a web-search adapter included.
Family: flutter_ai ·
core · client · elements ·
mcp · voice
Recipes · Migrating from the Vercel AI SDK
Provider-neutral tool calling for the flutter_ai family.
Pure Dart, no Flutter dependency.
What it does #
ToolSpec— declare a tool (name, description, JSON-Schema parameters) and an optional client-side executor.ToolRegistry— collect tools, hand theirdefinitionsto a provider, andrunaToolCallPartinto aToolResultPart. Unknown tools and thrown executors become error results, never crashes.- Web search —
webSearchTool(adapter)turns anyWebSearchAdapter(Tavily, Brave, SerpAPI, custom) into a callable tool returningSearchResults.
Usage #
final tools = ToolRegistry([
ToolSpec(
name: 'get_weather',
description: 'Get the weather for a city',
parametersSchema: const {
'type': 'object',
'properties': {'city': {'type': 'string'}},
'required': ['city'],
},
execute: (args) => weatherApi.fetch(args['city']! as String),
),
]);
// Advertise to a provider:
controller.setTools(tools.definitions);
// Fulfill a call the model made:
final result = await tools.run(toolCallPart); // -> ToolResultPart
Web search #
final tools = ToolRegistry([webSearchTool(MyTavilyAdapter())]);
class MyTavilyAdapter implements WebSearchAdapter {
@override
Future<List<SearchResult>> search(String query, {int? maxResults}) async {
// call your search backend, map hits into SearchResult
}
}
Status #
Published on pub.dev (see the CHANGELOG); depends on flutter_ai_core.
See example/.
☕ Support this project #
If flutter_ai saves you time, buy me a coffee ☕ — it keeps the whole family maintained.
