# setModel()

Select the provider model and thinking level for an agent turn.

Call `pi.setModel()` inside `before_agent_start`:

```js
pi.on('before_agent_start', async (_event, ctx) => {
  if (ctx.external?.conversationType === 'dm') {
    const accepted = await pi.setModel({
      provider: 'openai',
      modelId: 'gpt-5.2',
      thinkingLevel: 'medium',
    });

    if (!accepted) {
      throw new Error('The requested model selection is invalid.');
    }
  }
});
```

## Selection

| Field           | Requirement                       |
| --------------- | --------------------------------- |
| `provider`      | Non-empty provider identifier     |
| `modelId`       | Non-empty model identifier        |
| `thinkingLevel` | Optional supported thinking level |

Supported thinking values are `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`.

The method resolves to `true` for a structurally valid selection and `false` for an invalid one. The selected provider/model must also be available to the hosted runtime; availability is checked when Salambo applies it.

## Lifecycle

The hosted runtime applies model selection from `before_agent_start`. Do not call `setModel()` unconditionally at module initialization: manifest discovery exposes registration methods, not runtime mutation methods.

Salambo records and restores the active model and thinking level on durable follow-up turns.
