DecisionModel asks typed questions about a state and gets calibrated probabilities back, with no generated text to parse. This example uses Google’s gemini-decision-1 to decide what to do with a customer’s return request, then checks an attached photo.
Setup
gemini-decision goes to Gemini’s Decisions API. There is no google-genai dependency, since the client calls the HTTP API directly.
The example
How it works
- One request, four questions.
run()sends the request and all four questions together. Each question is answered on its own against the same state, so adding a question does not change the other answers. - Structured state. The state is a dict, which is sent to Gemini as JSON text. Instructions can name its fields by key path, as
within_windowdoes withorder.age_days. - Three question types.
choicepicks one option,scorerates the state against ordered levels, andnoulreturns the probability that a statement is true. - Yes/no descriptions. The
trueandfalsecriteria onis_damagedsay what each side means.DecisionModelrenames them to the keys Gemini expects. - Thresholds in code. The request is approved automatically only when the resolution is confident and both policy checks pass. Everything else goes to a person.
- Media. A list of content blocks passes through to Gemini unchanged, so the second call sends a text block and a base64 image. The same shape works for audio, video and PDFs.
- Cost.
calculate_cost()prices the tokens of both requests. Gemini bills input tokens only.
Output
The values depend on the model. The shape is:Yes/no probabilities from Gemini fall between 0.01 and 0.99, so a threshold above 0.99 never matches.
Switching provider
The questions and answers have the same shape for every provider, so the text part of this example runs on another decision model by changing the name:Related
DecisionModel reference
Every provider, method and question type
Source
The example file in the swarms repo