Skip to main content

decision-gateway

Scaffolding to work with decision models: it diverts traffic to different models by name and keeps a decision log that serves both as a cache and as data to export and query in offline analysis of decisions.

The gateway sits underneath TypeSafe's Python SDK (typesafe-sdk). Code keeps using the SDK's own client, but its requests pass through the gateway, which

  • routes each model name to its configuration: endpoint, key, model id and other customizable constraints;
  • records decisions: every request and every response, with arbitrary application-side labels;
  • answers locally: a single forward pass makes decision models effectively deterministic, so their answers can be cached on the application side.

Install

pip install decision-gateway

Use

from typesafe_sdk import Noul

from decision_gateway import Gateway, SQLiteStore, config, labels

gateway = Gateway(config.load("models.toml"), SQLiteStore("evals.sqlite"), labels={"project": "evals"})
eval_set = ["I was charged twice for my subscription.", "How do I change my password?"]

with gateway.client("jev") as client:  # a typesafe_sdk.TypeSafeClient; gateway.async_client() for async
    for item, text in enumerate(eval_set):
        with labels(item=item):
            response = client.system_one(
                state=text,
                questions={"refund": Noul(instructions="Is the customer asking for money back?")},
            )
        response.nouls["refund"].noul

Decision Log Labels

Labels are arbitrary data attached to a request and used to query the decision log. They can be set in three places:

  • the gateway's: Gateway(..., labels={"project": "evals"}), on every request;
  • labels(...) around the call, as a context manager or as a decorator on a sync or async function: @labels(study="demo");
  • label_headers(...) passed with the call: client.system_one(..., extra_headers=label_headers(item=17)).

labels(...) follows await, asyncio tasks and asyncio.to_thread, but not calls made in a ThreadPoolExecutor or run_in_executor, which don't carry context variables. Use label_headers(...) there: it goes with the request, and the gateway removes it before anything is sent.

Decision Store

The decision store keeps:

  • observations: every response received, with what was sent, where, the response as received, the model and provider it reports, when, and the cost. Responses a model's requirements did not accept are kept too.
  • requests: every request made through the gateway: when, labels, model name, which observation answered it, whether it came from the store, and whether it was accepted.

A request is answered from the store when there is an observation for the same request (the body as sent, to the same endpoint) that the model's requirements accept.

Currently, SQLiteStore is the only implementation of Store; it is useful for single-task exploration or demos.

Model Configuration

The available models are defined in models.toml: how the client for each is configured (endpoint, key, model id, provider pin) and which answers each accepts. models.example.toml describes every field and the built-ins, with examples; copy it to start.

License

Apache-2.0

Metadata

Release files for decision-gateway 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decision-gateway 0.0.1
File Size Uploaded
decision_gateway-0.0.1.tar.gz 30.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for decision-gateway 0.0.1
File Interpreter ABI Platform
decision_gateway-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 56.6 kB

Release files / decision_gateway-0.0.1.tar.gz

Download URL decision_gateway-0.0.1.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1777ef35643993cc67fb5a400a08cb460c6d3c9c852829849a27cd465df30559
BLAKE2b-256 checksum
How to use checksums
4cbda254cc6a355de8ff6d85b2bf8e7f706c0553984fa453da856cb52f30804a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / decision_gateway-0.0.1-py3-none-any.whl

Download URL decision_gateway-0.0.1-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e36b5323ab648f5d924d2e34f95e96b0a2fb8e78b78c2c03313ebd8de8cdbd6
BLAKE2b-256 checksum
How to use checksums
e2771f47b478f1588d073ba932447306e328afa8fc8d4d6c6cf39b781404dc4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page