A Magic 8 Ball That Makes Decisions


Sometimes you want an AI model to write an essay. Sometimes you just want it to pick an option.

A Magic 8 Ball displaying "Outlook good", connected to a terminal asking "Will my demo work?" with branching decision paths

I wanted to try Microsoft-Decision-1.1, a model available in Microsoft Foundry that does the second thing. Naturally, I chose a business-critical use case: a Magic 8 Ball.

Type a yes-or-no question into a terminal, send it to the model, and get back a fortune. No web framework, no agent, no tools. Just Python and a slightly over-engineered replacement for shaking a plastic ball.

For context, I work for Microsoft. This is a small experiment, not a benchmark, and definitely not a new method of predicting the future.

Decisions, not paragraphs

With a generative model, I could ask:

You are a Magic 8 Ball. Answer my question with one of these phrases…

That would be a perfectly reasonable way to build this. Modern generative models can also produce structured output, so returning something an application can parse isn’t unique to a decision model.

The interesting difference is what the model is designed to do. Decision 1.1 doesn’t write a free-form response or an explanation. You give it some state, ask a typed question, and describe the criteria. It returns a structured decision.

There are three question types:

Type What it answers Example
choice Which option fits? Which team should handle this ticket?
noul How likely is this condition to be true? Does this message promise a refund?
score Where does this sit on an ordered scale? How severe is this incident?

For my 8 Ball, I use choice. The user supplies the state, and the possible decisions are eight familiar answers, from “It is certain” to “Very doubtful”.

Each choice has a description explaining when it fits. In a less frivolous application, these might be queue names, document categories, or the names of tools. I’ve used eight responses to keep the example small, rather than reproducing the toy’s full set.

Calling the model

I already had Decision 1.1 deployed in Foundry. If you’re following along, deploy Microsoft-Decision-1.1 from the model catalogue, then copy the resource endpoint, deployment name, and API key.

The endpoint is worth noting. This isn’t a chat completions request:

POST <resource-endpoint>/providers/microsoft/v1/systemone

Here’s the whole application, using only the Python standard library. Save it as eightball.py:

import json
import os
import sys
import urllib.error
import urllib.request


ANSWERS = {
    "It is certain.": "An unequivocal yes.",
    "Outlook good.": "Likely yes, with a positive outlook.",
    "Signs point to yes.": "Tentatively yes, based on the available signs.",
    "Reply hazy, try again.": "The question is unclear or lacks enough context.",
    "Cannot predict now.": "The outcome is unknowable or depends on future events.",
    "Don't count on it.": "Probably not.",
    "My reply is no.": "A clear no.",
    "Very doubtful.": "Extremely unlikely.",
}


def ask(question, endpoint, deployment, api_key):
    body = {
        "model": deployment,
        "state": question,
        "questions": {
            "fortune": {
                "type": "choice",
                "instructions": (
                    "You are a playful Magic 8 Ball. Choose the most fitting "
                    "answer to the user's yes-or-no question. This is only "
                    "entertainment, not a real prediction."
                ),
                "criteria": ANSWERS,
            }
        },
    }
    request = urllib.request.Request(
        endpoint.rstrip("/") + "/providers/microsoft/v1/systemone",
        data=json.dumps(body).encode("utf-8"),
        headers={"Content-Type": "application/json", "api-key": api_key},
        method="POST",
    )
    try:
        with urllib.request.urlopen(request, timeout=60) as response:
            payload = json.load(response)
    except urllib.error.HTTPError as exc:
        raise RuntimeError(f"Decision API returned HTTP {exc.code}.") from exc
    except (urllib.error.URLError, TimeoutError) as exc:
        raise RuntimeError("Could not reach the Decision API.") from exc
    except (ValueError, UnicodeDecodeError) as exc:
        raise RuntimeError("Decision API returned invalid JSON.") from exc

    try:
        answer = payload["answers"]["fortune"]
        choice = answer["choice"]
        if answer["type"] != "choice" or choice not in ANSWERS:
            raise ValueError
    except (KeyError, TypeError, ValueError) as exc:
        raise RuntimeError("Decision API returned an unexpected answer.") from exc
    return choice


def main():
    names = ("AZURE_ENDPOINT", "DEPLOYMENT_NAME", "AZURE_API_KEY")
    config = [os.environ.get(name, "").strip() for name in names]
    missing = [name for name, value in zip(names, config) if not value]
    if missing:
        print("Set these environment variables: " + ", ".join(missing), file=sys.stderr)
        return 1

    try:
        while True:
            if sys.stdin.isatty():
                print("Ask a yes/no question (Ctrl-D to exit): ", end="", file=sys.stderr, flush=True)
            line = sys.stdin.readline()
            if not line:
                return 0
            question = line.strip()
            if question:
                print(ask(question, *config), flush=True)
    except RuntimeError as exc:
        print(f"Error: {exc}", file=sys.stderr)
        return 1
    except KeyboardInterrupt:
        return 0


if __name__ == "__main__":
    sys.exit(main())

fortune is my name for the question, so the answer comes back under that same name. The model field is the deployment name, which can differ from the model’s catalogue name.

The keys in ANSWERS are the choices; the values describe when each choice fits. The script checks that the returned answer is one of those choices before printing it.

You can also download the script. It needs Python 3.10 or later, but no packages to install.

export AZURE_ENDPOINT="https://YOUR-RESOURCE.services.ai.azure.com"
export DEPLOYMENT_NAME="YOUR-DEPLOYMENT-NAME"
export AZURE_API_KEY="YOUR-API-KEY"

python3 eightball.py

Use the resource’s base endpoint, not a project URL or an OpenAI URL. The API key is convenient for this local experiment; keep it out of source control. Foundry also supports Microsoft Entra ID authentication, which I’d use rather than distributing keys in a deployed application.

The live test for this project was reassuring:

Question: Will this Magic 8 Ball demo work?
Answer:   Outlook good.

An excellent result, although perhaps not independent verification.

The console accepts another question after each answer. Ctrl-D exits. Answers go to STDOUT, while prompts and errors go to STDERR, so piping works too:

printf 'Will my demo work?\n' | python3 eightball.py

Unlike the plastic version, the app isn’t choosing randomly. It’s asking the model which answer fits the question. Repeating a question may produce the same result. It also has no access to the future, however confidently the terminal says otherwise.

Why use a specialised model?

For an actual Magic 8 Ball, I wouldn’t. A random choice would be cheaper, faster, work offline, and arguably be more faithful to the original.

But replace the fortunes with useful categories and the pattern becomes interesting.

Imagine deciding whether a support request belongs with billing, engineering, or account support. Or choosing whether a task needs a larger model. You need a small decision, potentially on every request, not a paragraph explaining the history of customer service.

That’s where latency and cost start to matter. A routing step sits in front of the work the user actually wants done. If the router is slow or expensive, it can eat into the benefit of routing in the first place.

Decision 1.1 is designed for that role. The launch write-up describes an inference engine optimised for decisions rather than generating text token by token. Microsoft reports more than twice the speed of the first Decision model. That’s a published comparison, not something I’ve measured with this 8 Ball; actual latency still depends on the request, deployment, and network.

The published Foundry Global Standard price, as of November 2026, is $0.042 per million input tokens, with output tokens free. At that rate, a hypothetical 1,000-input-token request costs $0.000042, or about $0.042 for a thousand such requests. That includes all the input, not just the user’s sentence: instructions and criteria count too. Data Zone pricing differs, and prices can change, so check the current rates for your deployment.

Cheap enough to consider for lots of small decisions, then. Not a reason to replace an if statement with a network call.

A fixed answer isn’t necessarily a correct answer

The useful constraint is that the application defines the available choices. That makes integration straightforward, but it doesn’t make the judgement infallible.

A choice response also includes probabilities for the options. I’ve ignored those for the toy, but in a real router I’d evaluate them against labelled examples and use a threshold to decide when to escalate to a person or a more capable model. A probability isn’t a guarantee, and a model choosing “Cannot predict now” isn’t a substitute for application-level safeguards.

I’d also use ordinary code wherever a deterministic rule does the job. A decision model is more interesting when the input is messy language or context that would be awkward to capture in a growing pile of rules. If the task needs an explanation, research, or open-ended writing, a generative model remains the more natural fit.

That’s what I like about this example: underneath the silly interface is a small, useful building block. Sometimes the AI part of an application doesn’t need to be a conversation. It just needs to choose what happens next.

Will all my future architecture decisions be made by this script?

Very doubtful.