OpenProgram Docs

Next-step decision

from openprogram import Agent, decision

class ExampleAgent(Agent):
    method_options = {'route_message': {'tool': True}}

    def route_message(self, msg: str) -> str:
        return decision.make("Pick one way to handle this message.", {
            "analyze":  analyze_sentiment,        # a function
            "fallback": fallback_reply,           # a function
            "done":     "CONVERSATION_OVER",      # a value
        })

The model picks a function: it runs with parsed and injected arguments and its return value comes back. The model picks a value: that value comes back. The decision is the branch; there is no if.

Work first, decide last

from openprogram import Agent, agent

class ExampleAgent(Agent):
    method_options = {'handle_ticket': {'tool': True}}

    def handle_ticket(self, ticket: str) -> dict:
        """Read the ticket, look things up, then decide which flow to route to."""
        return agent(
            f"Handle this ticket: {ticket}",
            toolset="default",          # before: research with tools, run commands
            choices={                   # closing: the return must be one of these
                "refund":    issue_refund,
                "escalate":  escalate_to_human,
                "close":     {"status": "closed"},
            },
        )
decision.make(prompt, options)agent(prompt, choices=options)
Model doesOnly picksA full turn with reasoning and tools from tools or toolset; its final reply must be one {"call": ...} JSON
PromptYour prompt and the menu; your prompt must ask for a pickMenu and DECISION_FINISH_INSTRUCTION spliced in
Retriesmax_retries, default 1, 0 disablesFixed at one

Without choices, agent returns the reply text. Inside an Agent method both use the enclosing call's Runtime. Outside any Agent call pass runtime=; decision.make otherwise raises RuntimeError. Code: openprogram/runtime/agent/decision.py.

Versus native tool calls

Native tool callNext-step decision
Options reach the model byThe protocol's tools fieldText menu in the prompt
Pick expressed asStructured ToolCallJSON in the reply body
Parsed byProvider and agent loopdecision.py
An option can be a valueNoYes, typically done or escalate
NeedsProvider tool usePlain text

One Agent method can serve both as a native tool and as an option. Also weigh whether every decision and retry should be a traceable DAG node.

Options

KindWhen pickedSchema from
FunctionRuns it, returns its return valueFunction signature
ValueReturns the fixed valueNone
SchemaModel fills the schema; returns {"decision": name, **fields}The schema you declare
decision.make("...", {
    "retry":     retry_fn,                            # function option
    "skip":      "SKIPPED",                           # value option
    "abort":     (AbortSignal(), "pick when stuck"),  # value option + description
    "emit_plan": ("Produce a plan.", {                # schema option: ("description", schema)
        "steps": [{"action": str, "target": str}],
        "rationale": str,
    }),
})

Dict form: {name: handler}. List form: a callable, (callable, "description"), "name", ("name", "description") or ("name", "description", schema); a function's name is its __name__.

Schema notation

Written asMeans
field: str (any Python type)Scalar of that type
field: "description"Described str scalar
field: [subschema]List of exactly one item template; [str, int] raises TypeError
field: {subfield: ...}Nested object, needing at least one key outside the meta-spec set
field: {"type": T, "description": ..., "options": [...]}Meta-spec. A dict whose keys all fall in {type, description, options, fields, items} is read this way.

Tuples are reserved in handler position: a literal 2-tuple value is misread as (value, "description"). To always return one structure, use a single-option decision.make or exec(response_format=...).

Internal steps
  1. render_options emits each option's signature name(param: type, ...), description, per-parameter detail with options, and a one-line Call: JSON example with native placeholders (0, false, [], {}, "<str>") and nested shape. Only source="llm" parameters show.
  2. Model call. decision.make sends runtime.exec(prompt + menu); exec(choices=) splices the menu into its turn.
  3. parse_args checks the reply as in the table below and returns (chosen, kwargs): the function, or the name string.
  4. Retry on _ParseError: the previous reply, the reason and the re-rendered menu go back through runtime.exec, recorded in the DAG like any model call. When exhausted: DecisionError, with the last error kind, message and head of the reply. It subclasses ValueError; there is no built-in fallback.
  5. resolve_decision runs chosen(**kwargs), or looks up the value; a value option with a schema returns {"decision": name, **kwargs}.
parse_args stepBehaviour
extract_actionFinds the JSON with a call key (aliases action, function, tool) in a JSON code block or bare text
Unknown name_ParseError("unknown_call")
_validate_fieldChecks type (str/int/float/bool/list/dict; bool is not int, float accepts int), enum and nesting
Function optionssource="context" parameters come from the context dict, runtime-class parameters are injected, unknown fields dropped, required ones checked
Value and schema optionsEvery declared field required, others dropped
Last updated · 2026-11-25