1. Classifier steps
  2. Classifier steps

A classifier step asks a decision model one or more questions about some text or JSON. The answer is a label, a probability or a score. There is no agent loop, no tools and no free text, so it is fast and the answer has a fixed shape.

import avalanche as ava


@ava.classifier_step(
    questions={
        "category": {
            "type": "choice",
            "instructions": "Which expense category fits this invoice?",
            "criteria": {
                "software": "Licenses, SaaS and cloud hosting.",
                "travel": "Flights, hotels and ground transport.",
                "other": "Anything else.",
            },
        },
        "urgent": {
            "type": "noul",
            "instructions": "Is payment due within 7 days?",
        },
    }
)
async def categorize(text: str, *, classifier: ava.Classifier) -> str:
    result = await classifier(state=text)
    return result.choices["category"].choice
Rendering diagram…

​
The step function

NameWhat it is
classifierSupplied by Avalanche. Call it with state=, the data to judge.
stateText, or any JSON value: a dict, a list.
resultOne answer per question, read by question name.
result = await classifier(state=text)

result.choices["category"].choice         # "software"
result.choices["category"].probabilities  # {"software": 0.91, "travel": 0.03, "other": 0.06}
result.nouls["urgent"].noul               # 0.12

Your code decides what to do with the numbers. A label is not an action.

if result.nouls["urgent"].noul >= 0.8:
    ...

​
Agent step or classifier step

Agent stepClassifier step
ProducesAnything a signature can describeA label, a probability or a score
Works byMany turns, tools, codeOne call
Use forReading, research, draftingRouting, flagging, scoring

​
Options

OptionWhat it sets
questionsThe default questions. They can also be passed on each call.
classifier, modelThe provider and its model.
timeoutSeconds allowed per request. Default 10.
input_modelA model that state is checked against before the request.
retries, on_uncertain, slugThe same as on a Python step.

​
In the UI

The classifier step's definition panel

Before a run: the provider, the model and the questions of a classifier step.

A classifier step after a run, with its call expanded

After a run: each call with its input, and the probability of every answer.