# AnyDecisionModel

> A Swift package that returns typed probabilities, choices, and ordinal scores from language models, with local and API backends.

AnyDecisionModel is an open-source Swift package by mattt for getting typed decisions from language models: yes-or-no probabilities, choices among options, and scores on ordinal scales. Its API follows the model-and-session pattern of Apple's Foundation Models framework and AnyLanguageModel. The latest release listed is 0.7.0, under the Apache 2.0 license.

## What It Is

AnyDecisionModel is a Swift library for asking questions about a piece of text or JSON state and receiving structured answers instead of free text. A `DecisionSession` holds one immutable state, and each question is independent of the others. Binary questions return a `Double` probability. Choice questions return a `Choice` with a value, a probability for each option, and a confidence value. Score questions return a `Score` with the expected level, per-level probabilities, and a confidence value.

Choices can be defined by conforming an enum to `Choosable`, optionally with option descriptions that tell the model when to select each one. Options can also be supplied at run time. Several questions can be sent in one batch call, which also returns token usage and local diagnostics.

## Backends

Six backends are documented:

- MLX runs a small language model on Apple silicon and reads each decision from next-token probabilities in one forward pass.
- MLX decision heads run models with a trained decision head, such as Cloudflare's Clef.
- Core AI runs a Core AI model on macOS 27 and iOS 27.
- llama.cpp runs a GGUF model.
- Jev calls TypeSafe's Jev through the System One API, or any server implementing it.
- Ollama calls a System One model locally or in Ollama's cloud.

Without traits the package has no third-party dependencies and provides the core types plus the Jev and Ollama backends. The `MLX`, `CoreAI`, and `Llama` traits enable the local backends.

## Calibration and confidence

Local backends accept a `Calibration` that applies a temperature to all answers and a bias to binary answers. Local confidence is the normalized complement of the entropy of the answer probabilities, which measures how concentrated the distribution is rather than whether the answer is correct. The MLX backend offers rotation debiasing to reduce position bias in choices, and optional prefix caching. Diagnostics report the share of next-token probability that fell on the answer labels.

## Documented limitations

The README states that Jev and Ollama wire compatibility is tested against fixtures rather than live services, that calibration was fitted on two tasks with unknown transfer, and that typed output alone should not be relied on to resist injected instructions.

## Features
- Typed binary probabilities, choices, and ordinal scores
- Model-and-session API patterned on Apple's Foundation Models framework
- Choosable enums with option descriptions
- Batch decisions in a single call with usage and diagnostics
- Six backends: MLX, MLX decision heads, Core AI, llama.cpp, Jev, Ollama
- Rotation debiasing for choice position bias
- Optional prefix caching
- Configurable calibration with temperature and binary bias
- Entropy-based confidence values and allowed-answer mass diagnostics
- Text and JSON session states

## Integrations
MLX, Core AI, llama.cpp, Ollama, TypeSafe Jev, Cloudflare Clef, Hugging Face Hub, Swift Package Manager

## Platforms
MACOS, LINUX, IOS, API, DEVELOPER_SDK, CLI

## Pricing
Open Source

## Version
0.7.0

## Links
- Website: https://github.com/mattt/AnyDecisionModel
- Documentation: https://github.com/mattt/AnyDecisionModel
- Repository: https://github.com/mattt/AnyDecisionModel
- EveryDev.ai: https://www.everydev.ai/tools/anydecisionmodel
