# How a simulation ends: end conditions and turn limits

> A simulation ends when the character recognizes one of your end conditions or when the learner reaches the turn limit you set.

- Plans: All plans
- Canonical: https://docs.devlin.ai/simulations/ending-a-simulation

## Two ways a simulation ends

A simulation can end in two ways, and you can use both together:

- **End conditions.** Plain-language descriptions of the moments that should close the scenario. The character watches for them and wraps up when one happens.
- **A turn limit.** A hard cap on how long a text conversation can run, whatever happens in the scenario.

Both settings are in the simulation editor, in the **Design** stage, **Simulation** section, under the **Simulation Ending** heading. They are available on every plan. Save your changes for them to take effect.

A simulation with no end conditions and no turn limit has no designed ending, so set at least one of the two.

## End conditions

Each end condition is one free-text line that describes something observable in the conversation, such as the example in the editor: "The learner successfully de-escalates the situation". Select **+ Add End Condition** to add another line, and use the × next to a line to remove it. The simulation ends when any one of the conditions is met, so a list of conditions is a list of alternative endings (for example a successful outcome and a breakdown).

Lines you leave blank are ignored when you save. The editor does not cap how many conditions you add or how long each one is.

When you create a simulation by describing it, the generated draft normally includes end conditions. Review them in the editor like any other generated field. See [Create a simulation](https://docs.devlin.ai/simulations/create-a-simulation).

### How the character decides

End conditions are given to the character as part of its instructions. There is no keyword matching: the character judges from the conversation whether a condition has occurred. When it recognizes one, it can add a brief closing remark in character, and that reply ends the simulation. The learner never sees the internal signal the character uses to end the simulation, only the closing reply.

Because the character makes the call, write conditions as things it can observe in what is said, not as outcomes it would have to guess at. For help with wording, see [Scenario design and difficulty](https://docs.devlin.ai/design-guidance/scenario-design-difficulty).

## Turn limit

Turn on **Enable max turns** to show the **Max Turns** field, then enter the number of turns you want. The editor marks the setting as recommended: it sets a hard limit on simulation length to keep things focused.

- **What counts as a turn.** Each turn is one learner message plus the character's response. When the character speaks first, its opening message is not counted.
- **The last turn.** On the learner's final allowed message, the character is told this is the final exchange: it responds to the message and concludes naturally. The simulation then ends with that reply, whether or not an end condition was met.
- **After the limit.** A message sent after the limit is not answered. The simulation ends instead.
- **Default.** A simulation you create without a turn limit has the checkbox off and no limit. A simulation generated from a description normally comes with a limit suggested to fit the scenario, which you can change or turn off.

Turning **Enable max turns** off removes the limit.

The turn limit applies to text conversations. Voice sessions do not enforce it unless you opt in from the voice settings shown under **Max Turns** when voice is enabled for the simulation.

## What the learner sees

When the simulation ends, by either route:

1. The character's last reply stays in the conversation.
2. The message box is replaced by the line "Simulation complete." The learner cannot send more messages.
3. If evaluation is turned on, it starts automatically and "Results loading" shows next to the completion line until the result is ready. With evaluation off, nothing more happens. See [Evaluation and scoring](https://docs.devlin.ai/simulations/evaluation-and-scoring).
4. If the simulation is set to offer another attempt, the Try Again button appears once any evaluation has finished. See [Criteria breakdown and attempt limits](https://docs.devlin.ai/results-and-analytics/learner-results-and-attempts).

In an embedded course, the simulation's completion variable is set to `true` at the moment the simulation ends, before any evaluation result arrives, so the course can react to completion regardless of the result. See [Storyline web object setup](https://docs.devlin.ai/publish-and-embed/storyline-web-object-setup).

## Voice sessions

End conditions work in voice sessions as well. The character is instructed to always say a brief closing remark before the session ends, so the learner hears an ending instead of silence.

## Editing over MCP

An AI tool connected through the [MCP server](https://docs.devlin.ai/integrations/mcp-server-and-ai-tool-connectors) can read and change both settings when it updates a simulation: end conditions as a list of plain-language strings, and the turn limit as a number. The limit must be a whole number of 1 or more; a save with a negative or fractional limit is refused, and 0 means no limit.

## Related

- [Build a simulation](https://docs.devlin.ai/simulations/build-a-simulation)
- [Evaluation and scoring](https://docs.devlin.ai/simulations/evaluation-and-scoring)
- [Criteria breakdown and attempt limits](https://docs.devlin.ai/results-and-analytics/learner-results-and-attempts)
- [Scenario design and difficulty](https://docs.devlin.ai/design-guidance/scenario-design-difficulty)
- [Storyline web object setup](https://docs.devlin.ai/publish-and-embed/storyline-web-object-setup)
