> ## Documentation Index
> Fetch the complete documentation index at: https://botpress.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Use different LLM for Autonomous Nodes

> [!WARNING]
>
> You can now [override default LLMs directly in your Autonomous Node's settings](https://botpress.com/docs/studio/concepts/nodes/autonomous-node.md#override-default-models).
>
> This method is simpler and recommended for most use cases. The guide below remains available for advanced use cases.

You can configure [Autonomous Nodes](https://botpress.com/docs/studio/concepts/nodes/autonomous-node.md) to use a different LLM than the default model specified in your [Bot Settings](https://botpress.com/docs/studio/concepts/bot-settings.md#autonomous-language-model). This is useful if your bot needs a higher-performing model for certain tasks.

> [!NOTE]
>
> You will need:
>
> * A [published bot](https://botpress.com/docs/get-started/quick-start.md)
> * A [Workflow](https://botpress.com/docs/studio/concepts/workflows.md) containing more than one Autonomous Node
> * Familiarity with JavaScript

## Step 1: Find the Node, Workflow and model IDs

First, you need to find:

* The ID of the Autonomous Node whose model you want to change
* The ID of the Workflow containing that Autonomous Node
* The ID of the model you want to change to

### Node and Workflow IDs

1. Start a conversation with your bot in the [Emulator](https://botpress.com/docs/studio/concepts/emulator.md).
2. Continue until the bot transitions to the Autonomous Node whose model you want to change:

![Transition to new Autonomous Node](https://mintcdn.com/botpress/RWKQxTh1qL1DGc-R/studio/guides/how-to/assets/an-transition.png?fit=max\&auto=format\&n=RWKQxTh1qL1DGc-R\&q=85\&s=b196b98fe8bdb4be77868968324a0b17)

3. Select one of your messages from after the bot transitioned to the new Autonomous Node. Then, open the [JSON tab](https://botpress.com/docs/studio/concepts/debugger-logs-json.md#json) in the bottom panel.
4. Under **Payload**, navigate to `state > context`:

![Current Workflow and Node IDs](https://mintcdn.com/botpress/RWKQxTh1qL1DGc-R/studio/guides/how-to/assets/current-ids.png?fit=max\&auto=format\&n=RWKQxTh1qL1DGc-R\&q=85\&s=a92f8e7f12f2dd6eb5bd24930ecdd849)

5. Copy the values of `currentFlow` and `currentNode`—these are your Workflow's ID and Autonomous Node's ID.

### Model ID

1. Return to your conversation in the Emulator.
2. Select ** Inspect** on any message generated by the Autonomous Node whose model you want to change.
3. Select **View Raw ** in the upper-right corner.
4. Navigate to `context > options > models`.
5. Find the model you want to switch to. Expand it, then copy its full `id`. For example, for GPT-4.1:

![GPT 4.1](https://mintcdn.com/botpress/RWKQxTh1qL1DGc-R/studio/guides/how-to/assets/gpt-4-1.png?fit=max\&auto=format\&n=RWKQxTh1qL1DGc-R\&q=85\&s=39098344a11f480158a7b1892e4bdbdd)

## Step 2: Add a Hook to change models

1. In the Studio, navigate to the  [Hooks](https://botpress.com/docs/studio/concepts/hooks.md) section.
2. Select **Create Hook** and set its type to [Before LLMz Execution](https://botpress.com/docs/studio/concepts/hooks.md#before-llmz-execution).
3. Paste the following code into the Hook:

```js highlight={6-7, 15} theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
// Get the current Workflow and Node IDs
const flowID = event?.state?.context?.currentFlow ?? ''
const nodeID = event?.state?.context?.currentNode ?? ''

// Check if they match the ones we're targeting
const flowMatches = (flowID.includes('yourWorkflowID')) // Replace with your own
const nodeMatches = (nodeID.includes('yourNodeID')) // Replace with your own

console.log('Current model: ', context.model)
console.log('Current Workflow: ', flowID.toUpperCase())
console.log('Current Node: ', nodeID.toUpperCase())

// Switch models if they match
if (flowMatches && nodeMatches) {
  context.model = 'yourModelChoice' // Replace with your desired model
  console.log('Switched to ', context.model)
}
```

* Replace `yourWorkflowID` and `yourNodeID` with [your actual IDs](#node-and-workflow-ids).
* Replace `yourModelChoice` with the [actual model ID](#model-id).

> [!TIP]
>
> Now, this Autonomous Node will use a different model than the default model specified in your [Bot Settings](https://botpress.com/docs/studio/concepts/bot-settings.md#autonomous-language-model).

## Troubleshooting

Here are some troubleshooting tips:

### State is undefined

If the `state` property from [Step 1](#node-and-workflow-ids) is `undefined`, make sure you're viewing your own message's logs—not the Autonomous Node's.

### Check if IDs matched

You can check if the Node and Workflow IDs matched by checking your bot's [logs](https://botpress.com/docs/studio/concepts/debugger-logs-json.md) after transitioning to the Autonomous Node in the Emulator:

![Model change logs](https://mintcdn.com/botpress/RWKQxTh1qL1DGc-R/studio/guides/how-to/assets/model-change-logs.png?fit=max\&auto=format\&n=RWKQxTh1qL1DGc-R\&q=85\&s=8afb68eaa6a57759a966e094220a3dd7)

### Check if model actually changed

To check if the model actually changed:

1. Select ** Inspect** on any response from the target Autonomous Node.
2. Select **View Raw ** in the upper-right corner.
3. Navigate to `context > options > model`. This will display model the Autonomous Node used for the response.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.