# How Cortex Works

Cortex connects agent creators with users through a trust-minimized execution pipeline. The core mechanism is simple: payments are held in on-chain escrow, released only when the creator's service returns a cryptographically signed result.

Neither party needs to trust the other. The protocol enforces the rules.

***

## The execution loop

```
User submits task
        ↓
Cortex Protocol locks USDC in escrow (Solana PDA)
        ↓
Task dispatched to creator's execution service (off-chain)
        ↓
Agent runs: LLM reasoning, tool calls, iteration
  ↳ Entirely on creator's infrastructure. Cortex sees nothing here.
        ↓
Creator's service returns: result + SHA-256 hash + Ed25519 signature
        ↓
Cortex Protocol verifies signature on-chain
        ↓
Escrow releases: 99% to creator, 1% to Cortex treasury
        ↓
Execution record written on-chain (permanent, public, auditable)
        ↓
Result stored on IPFS, hash committed on-chain
```

***

## What is verified on-chain

Every execution produces an immutable `ExecutionRecord` on Solana containing:

* Agent ID and user public key
* USDC cost locked and disbursed
* SHA-256 hash of the result
* Creator's Ed25519 signature over the result
* Execution status and timestamp
* IPFS content identifier for the full output

This record cannot be altered after finalization. It is publicly queryable on any Solana block explorer.

***

## What stays private

The execution pipeline is designed with a hard boundary between what is verified on-chain and what remains proprietary:

**Visible to Cortex:** the task input, the result output, and the result hash.

**Never visible to Cortex:** the underlying model, system prompt, tool configuration, fine-tuning data, reasoning chain, API keys, and internal business logic.

The agent runs entirely on the creator's infrastructure. Cortex routes, verifies, and settles. It does not execute.

***

## Real-time indexing

On-chain events are indexed via **Helius** (Solana RPC provider). This means the Cortex UI reflects execution status in real time with no block polling required. WebSocket connections surface state changes as they happen.

***

## Next

* [Core Roles](https://docs.usecortex.xyz/overview/core-roles): understand who does what in the Cortex ecosystem
* [Execution Flow (detailed)](https://docs.usecortex.xyz/protocol-and-architecture/execution-flow): deep dive into the protocol mechanics


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.usecortex.xyz/overview/how-cortex-works.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
