Skip to content

Documentation navigation

Decision Gate Examples

Runnable examples of OR, any-of and nested decision gates on agents and managed functions.

#Decision Gate Examples

These examples extend the decision examples and reuse its decisions client and baseline fallback. They need maivn 3.1.0 or later. Run them in the same script after the first block there.

#Any of several choices

Python
from maivn import Agent
from maivn.decisions import DecisionChoice, DecisionRequest

severity = DecisionRequest(
    name='severity',
    state='Public status page: checkout errors for some EU customers since 09:10.',
    instructions='How severe is this incident?',
    privacy='public',
    choices=(
        DecisionChoice(key='low', description='Cosmetic or single-user'),
        DecisionChoice(key='high', description='A feature is degraded'),
        DecisionChoice(key='critical', description='Revenue or data at risk'),
    ),
)

plan = Agent(name='Incident writer').decide(
    'triage', client=decisions, questions={'severity': severity},
    require={'severity': {'high', 'critical'}},
)
outcome = plan.invoke('Draft the customer status update.')
print(outcome.status, outcome.skipped_by, outcome.skipped_gate)

A mapping value that is a set, list or tuple accepts any of those choices. Each value must be a declared choice, or decide raises ValueError before any call.

#This or that, nested

Python
from maivn.decisions import all_of, any_of, match

vip = DecisionRequest(
    name='vip',
    state='Public status page: checkout errors for some EU customers since 09:10.',
    instructions='Does this affect an enterprise-plan customer?',
    privacy='public',
    choices=(
        DecisionChoice(key='yes', description='An enterprise customer is affected'),
        DecisionChoice(key='no', description='No enterprise customer is affected'),
    ),
)

gate = any_of(match('severity', {'high', 'critical'}), match('vip', 'yes'))
plan = Agent(name='Incident writer').decide(
    'triage', client=decisions,
    questions={'severity': severity, 'vip': vip},
    require=gate,
)
outcome = plan.invoke('Draft the customer status update.')
if outcome.status == 'skipped':
    print('No update needed:', outcome.skipped_gate)

The update is skipped only when the platform confidently answers low and no. If either answer came from your fallback, that part is unknown and the agent still runs. Wrap the gate in all_of(match(...), gate) to add a required condition; skipped_gate then names the part that failed.

#The same gate on a managed function

Python
from maivn.decisions import DecisionResults, DecisionStep, decision_flow, depends_on_decision


@depends_on_decision(
    client=decisions,
    decisions=[DecisionStep('triage', questions={'severity': severity, 'vip': vip}, require=gate)],
    arg_name='decision_results',
)
def page_on_call(summary: str, decision_results: DecisionResults) -> str:
    return summary


call = decision_flow(page_on_call).invoke({'summary': 'Checkout errors in the EU'})
print(call.status, call.skipped_by, call.skipped_gate)

The reference lists the full rules.