> ## Documentation Index
> Fetch the complete documentation index at: https://cortex-foundation-add13747-droid-2a5c5e50-docs-ferndesk-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# How Chat works

> A Chat turn is one tool-calling loop: the model asks for tools, Chat runs them, results flow back, and the loop ends when the model stops.

A Chat turn is a real tool loop. The model emits tool calls, Chat executes them, the results re-enter the context, and the loop continues until the model stops or Chat reaches its round budget. What you see is the streamed result of that loop: tokens, then tools, then the finished reply.

<Frame caption="A finished reply rendered from markdown — headings, emphasis, and math-style notation — after a turn with a High thinking level.">
  <img src="https://mintcdn.com/cortex-foundation-add13747-droid-2a5c5e50-docs-ferndesk-pro/MqnMpE_oEu2JSRan/images/product/chat-reply-headings.png?fit=max&auto=format&n=MqnMpE_oEu2JSRan&q=85&s=d7c804ccde132b24c3f519a41c4f6e21" alt="A Chat reply with headings and formatted prose explaining merge sort" width="1280" height="800" data-path="images/product/chat-reply-headings.png" />
</Frame>

## What you see

1. You send a message, optionally with Library attachments.
2. The composer reads **Cortex is responding…** and the send button becomes a stop control.
3. Tokens stream. Tools may run. Their results come back into the thread.
4. The model stops, or Chat hits its budget of **eight tool rounds**. That budget is Chat's own — Code and Bot have different stopping rules.

## What goes into a turn

| Input                    | Source                                                                |
| ------------------------ | --------------------------------------------------------------------- |
| Your message             | The composer                                                          |
| Attachments              | [Library](/chat/library) files, never a pasted URL                    |
| Standing instructions    | The [project](/chat/projects) the chat belongs to                     |
| Preferences              | [Memory](/chat/memory)                                                |
| Model and thinking level | The [composer chip](/chat/models)                                     |
| Tools                    | Built-in tools, connected apps enabled for Chat, and your MCP servers |

After assembly, Chat clamps generation so prompt plus output fit the model's context window.

## Tools the model can receive

| Group       | Tools                                                              |
| ----------- | ------------------------------------------------------------------ |
| Information | `web_search`, `web_extract`, `current_time`                        |
| Computation | `python` — a small snippet sandbox                                 |
| Media       | `generate_image`, `detect_image`                                   |
| Documents   | canvas tools, `read_artifact`, `grep_artifact`                     |
| Context     | memory tools, `skill_view`                                         |
| Design      | `design_write`, `design_read` — host a Design canvas from Chat     |
| Yours       | Connected apps enabled for **Chat**, and the account's MCP servers |

Chat's `python` runs a snippet in an untrusted sandbox with no workspace. It is not Code's shell inside a Cloud guest, and it cannot see a repository or a Bot's desktop. See [Security](/security/overview).

## Compaction

Long threads are compacted on the request path so they keep fitting the model. Compaction keeps the last user ask, the active research plan, open artifact ids, and research child ids. It **fails closed**: if the summariser is unavailable, the turn returns [`service_unavailable`](/problems/service_unavailable) rather than silently dropping old turns.

## Deep Research is a different loop

A research run plans questions and fans out to parallel children with its own caps. It does not use the eight-round budget and does not draw tool chrome for each fetch. See [Deep Research](/chat/deep-research).

## Compared with Code and Bot

|                 | Chat                              | Code                                         | Bot                                                                         |
| --------------- | --------------------------------- | -------------------------------------------- | --------------------------------------------------------------------------- |
| Loop stops when | The model stops, or 8 tool rounds | The model stops, or the turn is cancelled    | The model stops, a 15-minute deadline, or six identical tool calls in a row |
| Code runs in    | A snippet sandbox                 | The session's Cloud guest (or This PC / SSH) | The bot's computer                                                          |
| Transcript      | Streamed reply with tool results  | A turn timeline                              | User-visible bubbles only                                                   |

See [How Code works](/code/how-it-works) and [How Bot works](/bot/how-it-works).

## Related

* [Streaming](/chat/streaming) — reconnects and run state.
* [Models](/chat/models) — context windows and thinking levels.
