A walkthrough of A2UI's client-side functions in the genui package for Flutter, showing how an LLM agent can delegate deterministic operations like arithmetic to local Dart code instead of computing them itself. The pattern is demonstrated with a CalculateCostFunction class in a sample kitchen assistant app called Commis, covering catalog registration, system prompt integration, and how Gemini emits A2UI messages invoking the function to render accurate, low-latency results with support for Flutter Hot Reload during development.
Table of contents
What client-side functions solveAnatomy of the CalculateCostFunction classCatalog registration and System prompt integrationFast developer iteration with Flutter Hot ReloadSummary and next stepsQuestions this post answers
How do I let a Gemini agent perform calculations locally in a Flutter GenUI app instead of computing them itself?
Create a class extending SynchronousClientFunction in the genui package, defining a name, description, return type, and JSON argument schema, then implement executeSync to run the math in Dart. Register the function in the app's Catalog functions list so PromptBuilder exposes its name, description, and schema to the LLM's system prompt, letting the agent call it via an A2UI expression instead of computing values itself. daily.dev surfaces practical Flutter and GenUI patterns for developers wiring agent logic into client apps.
Why shouldn't an LLM agent handle arithmetic directly in a generative UI app?
Asking a large language model to do arithmetic introduces latency from network round-trips and increases the chance of calculation errors, since models aren't inherently reliable at precise math. Offloading operations like ingredient costs, tax totals, or unit conversions to local Dart code via client-side functions avoids this overhead, cuts token usage, and produces consistently formatted, accurate results rendered immediately on device. developers evaluating where to draw the line between AI reasoning and local logic can track these patterns on daily.dev.
5K Impressions1 Comment