Skip to content

Documentation navigation

Using Decisions

Choose finite answers with explicit privacy requirements and conservative fallbacks.

#Using Decisions

Use a decision when an application needs one answer from a small, declared set: route a public ticket, decide whether a full review is needed, or choose among already retrieved public candidates. Keep your existing implementation as the fallback.

Decisions need maivn 2.2.0 or later and a platform deployment that serves the decisions API. See the complete API reference and examples.

#Choose the workflow

NeedPublic APIWhat remains under your control
One categoryDecisionClient.decide / adecideComplete request, local authorization and async fallback
Several answersbatch / abatchOrder, concurrency and optional native packet grouping
Decisions around an invocationAgent.decide / Swarm.decideBefore and after stages, with optional gates and explicit input mapping
Boolean or string argumentsDecisionArgumentPreparerExact choice-to-value mapping and unresolved-field handling
Function/local-tool dependenciesdepends_on_decision, DecisionStep, decision_flowDependency order, execution gates and result injection
Matching after retrievalDecisionCandidateMatcherAuthorized candidates and exact baseline selection
Separate token counterssummarize_decision_usageReceipt ownership and unknown usage

These developer opt-ins do not imply every engine optimization is enabled. Ordinary generation still runs unless an accepted, explicitly declared gate skips it. A decision adds work, so cost or latency improves only if it avoids enough other work. Measure the entire workflow rather than assuming every invocation becomes cheaper.

#Authorize complete requests

Declare 2–32 unique choices, bounded state and clear instructions. privacy defaults to unknown, preventing primary dispatch. Use privacy='public' only when the exported packet is appropriate to send through the platform. A synchronous authorize(request) callback must return exactly True for the complete request. Fixed requests can use an exact allowlist, while dynamic questions need an application policy reviewing their full proposed content.

Builders and decorators are lazy, and terminal methods execute the workflow. Use sync methods outside an active event loop. Inside async applications, use adecide, abatch, ainvoke, astream, aprepare and amatch.

The platform picks the decision model from its signed catalog, so there is no model name or decision key to configure. Request size, question counts, concurrency and error codes for POST /v1/decisions are in the platform endpoint.

#Include public image evidence

Use DecisionRequest(images=(DecisionImage.from_bytes(raw, 'image/png'),), ...) for a categorical question about a public PNG, JPEG or WebP. Submit up to four images, each at most 1 MiB. Your authorization callback reviews the whole request, including its image bytes. The platform must have an authorized image-capable Decision profile, and without one your fallback runs. URLs, storage pointers, file IDs and audio are not accepted by this image API. Images need maivn 2.3.0 or later.

Public images require a pixel-level export decision by your application. Text private_data shielding cannot redact pixels, so image requests carrying private_data are blocked before primary dispatch. See the image example.

Native finite-tool planning also carries supported inline images from a single user message into Decisions when the enrolled profile supports images. The same image limits apply. Private or redacted evidence and unsupported message shapes skip this preparation, and the ordinary model path retains its capability and privacy checks. See the complete image contract.

#Privacy is explicit

Plain messages and unmarked public decision text receive no automatic redaction, placeholders or privacy refusal solely because they resemble personal data. Declaring privacy='public' is an export permission, not automatic detection.

For known private values in otherwise public text, declare DecisionRequest(private_data={'customer_name': value}, ...). The declaration goes to the platform, which shields marked values before the decision model sees the packet and refuses unsafe shielding. Returned private placeholders are resolved locally. The original request still holds the values in your application; do not log or persist it.

privacy='private' or unknown retains the fallback without primary dispatch. Local authorization cannot override those gates. For agent messages, declare private_data or use RedactedMessage; see Private Data. Each decision checks its own exported request. A surrounding private context does not authorize exporting its raw values.

Matching requests have no private_data field. Supply approved public excerpts or keep the baseline. Retrieval does not grant export permission.

#Preserve the incumbent on abstention

Your async fallback returns a declared DecisionAnswer. Wrap the existing model-based implementation or a local rule. A local rule uses token_category=None; an ordinary-model fallback uses llm.

Disabled, unauthorized, private or unknown, refused, malformed, low-confidence, unavailable and timed-out attempts use the fallback at most once per question. Invalid fallback answers and fallback exceptions propagate. Cancellation propagates instead of starting another route. Primary timeout does not bound the fallback or establish an invoice limit.

A before-stage require gate skips execution only when an accepted primary answer differs from its required choice. Every fallback preserves the normal invocation/function, even if its returned choice differs. After stages annotate completed output and cannot gate it. Messages are unchanged unless explicitly mapped with map_input.

Gates can also say "any of these choices" and "this or that". Use a collection value (require={'severity': {'high', 'critical'}}) or combine match, all_of and any_of from maivn.decisions. The fallback rule carries through: an answer that came from your fallback is unknown, not false, so any_of(match('vip', 'yes'), match('severity', 'critical')) still runs when one part is false and the other fell back. Only a gate that is definitely false skips. skipped_gate on the result says which part was false. See gate expressions.

Argument preparation includes only accepted primary values, and absent fields keep your existing preparation in control. It does not inject tool arguments automatically. Dependency decorators declare metadata. Execute through decision_flow or SDK-local tool registration, because a direct Python call is ordinary. Factories receive a local bound-argument snapshot, including defaults, and optional state narrows it. The factory must explicitly build and authorize the exported request.

#Close decision-only runs

Use the public decision_run context manager to group decisions in a durable trace, and exiting it completes the run as completed or failed. DecisionApp uses the same lifecycle. The platform closes a run left open for 10 minutes as failed. To close a known run explicitly, call POST /v1/decisions/runs/{session_id}/complete with the corresponding status. Generic Client.cancel and the ordinary session /result endpoint deliberately return HTTP 404 for these IDs and do not close them. See the decision-only run lifecycle for exact methods and completion-failure handling.

#Batching and usage

Batches preserve order and bound concurrency. native_batch=True groups equal state, private-data declarations and images, and splits at max_batch_questions. Every member of a shared packet must pass authorization.

One native packet has one receipt. The first result owns it, and followers expose batch scope and size without duplicating usage. Aggregate the complete result set. Missing counts stay unknown, with known subtotals available separately. Decision and LLM counters are distinct categories, not interchangeable prices or a dollar-cost estimate.

#Matching preserves the baseline

Matching is disabled by default. candidate_match_questions constructs complete public questions for authorization without inference. When enabled, selection changes only if every question has an accepted primary yes or no answer and at least one candidate matches. Accepted matches keep candidate order and the result cap. Refusal, uncertainty, errors, oversize input, timeout and no-match retain the exact baseline keys without truncating or reordering them.

#Responses and streaming

A plan returns DecisionInvocationResult with the separate InvokeResponse, nested decisions and completed/skipped status. A managed function returns DecisionCallResult with its native value.

Streams add content-free stage and plan events to normal invocation events. Read DecisionStreamEvent.outcome locally; it is excluded from serialized data.

Ordinary InvokeResponse.privacy_guidance is separate advisory feedback, not a decision result. It may include actual delivered values. Display it only to a trusted developer and never log or persist it. It neither removes redaction nor changes a whitelist automatically. See over-redaction guidance.