AI intents

An ai:intent block declares a call with a schema: a name, typed inputs, one output, a prompt, and optionally a fallback. It is checked like a function and called like one.

This build has no model provider. An intent call answers its fallback: value, and an intent with no fallback is a runtime error. Everything else on this page is what the language does today; the provider behind the same block is future work, and the site does not claim otherwise.

The block

classify.md
---
midad: "0.1"
module: intent
permissions:
  ai: true
---

```ai:intent
name: classify
input: text: string
output: string
prompt: "Is this a question? {{ text }}"
fallback: "unknown"
```

```exec
print(classify("hello"));
```
output
unknown

name is the function the program calls. input is a comma-separated list of name: type parameters, output one scalar type, prompt the text the model would receive, and fallback the value the call answers when there is no model to ask.

The grant

ai: true is the grant, and an intent without it is E0302:

check-2.md
---
midad: "0.1"
module: intent2
---

```ai:intent
name: classify
input: text: string
output: string
prompt: "Is this a question? {{ text }}"
fallback: "unknown"
```

```exec
print(classify("hello"));
```
midad check
× E0302: ai:intent `classify` requires `ai: true` in permissions

ai is the only grant that is a boolean rather than a list. There is nothing to name: the program either may call an intent or may not.

Without a fallback

The fallback is not optional in this build, because there is nothing else to answer with:

error-3.md
---
midad: "0.1"
module: intent3
permissions:
  ai: true
---

```ai:intent
name: classify
input: text: string
output: string
prompt: "Is this a question? {{ text }}"
```

```exec
print(classify("hello"));
```
midad run (exit 1)
error-3.md:16:7
  × R0001: ai:intent `classify` has no LLM provider configured in this build
  │ and no `fallback:`
    ╭─[error-3.md:16:7]
 15 │ ```exec
 16 │ print(classify("hello"));
    ·       ────────┬────────
    ·               ╰── ai:intent `classify` has no LLM provider configured in this build and no `fallback:`
 17 │ ```
    ╰────

The schema is checked

An intent's parameters are typed, and a call that does not match them is a checker error:

check-4.md
---
midad: "0.1"
module: intent4
permissions:
  ai: true
---

```ai:intent
name: classify
input: text: string
output: string
prompt: "Is this a question? {{ text }}"
fallback: "unknown"
```

```exec
print(classify(1));
```
midad check
× E0230: type mismatch: expected string, found number

The argument count is checked the same way, and a malformed block is reported rather than ignored: an unknown field is E0150, and a block missing name:, output: or prompt: is E0151.

A native build

A native build lowers an intent to its fallback value, since a binary has no model to call. One with no fallback is refused by name:

c backend failed: unsupported in native subset: the C backend does not cover
this yet: `ai:intent classify`: a native build has no model, and the intent has
no fallback to use instead is not supported there

So a program with intents compiles today as long as each intent has a fallback, and it answers the same thing there as the interpreter does.

On this page