Skip to main content
You’ll build a small program that asks a model a question, reads the answer safely, switches which model is asked, and scopes that choice to one block of code. Every model here is inference("mock", ...) — an offline stand-in, not a default ask() falls back to — so none of it needs an API key.

1. Ask something

A Model is a value, and model NAME = inference("mock", name?, response_template:) names one — model is required here, not optional; a plain weather_bot = inference(...) is a syntax error. This one needs no network and no API key — good for learning, and for tests. set delegation = <model> picks which model ask(...) talks to.
Run it:
{prompt} in the template is replaced with whatever you pass to ask(...).

2. Read the answer safely

ask(...) never returns a plain string — it returns an Answer, with .value, .confidence, and .source. You must write .value to get the text out; there’s no implicit unwrapping, on purpose. That’s the whole point: a model’s output stays visibly different from a fact your code computed itself.
inference("mock", ...) always reports 0.5 confidence, since it’s a deterministic stand-in, not a real judgment. A real provider (see Model, Ask & Answer) reports nil instead of faking a number.

3. Switch which model answers

set delegation can be reassigned as many times as you like. ask(...) always uses whichever model is currently delegated to:

4. Scope a model choice to one block

session is a scope, not a separate actor — set delegation inside one only affects that block. Once the block ends, delegation reverts to whatever it was outside:
The second print is back to outer_model — the session’s own delegation never leaked out.

What you built

  • model NAME = inference("mock", ...) — an offline Model, for learning and tests (model is required)
  • set delegation = <model> — pick which model ask(...) uses
  • ask(prompt)Answer.value/.confidence/.source, no implicit unwrapping
  • session — a scope for trying a different model without affecting the rest of the program

Next

Safe Actions

Next tutorial — permissions and side effects that can’t happen by accident.

Model, Ask & Answer

The full reference — real providers, labeled arguments, capability gating.

Let a model choose a tool

The next step past a plain ask() call — needs a real model.

Which keyword do I want?

def vs tool vs action vs agent, decided in one glance.