> For the complete documentation index, see [llms.txt](https://docs.sigrex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sigrex.io/reaction/llm-reaction.md).

# LLM Reaction

An LLM Reaction allows Sigrex to process incoming data using an AI model.

LLM Reactions are **event-driven** and are triggered automatically when data is received through a **Data Webhook**.

They can be used for:

* Data interpretation and classification
* AI-based decision making
* Event-driven trading logic
* Signal generation without chart analysis

***

### 🛠️ How LLM Reactions Work

1. A **Data Webhook** receives an incoming request
2. The payload is forwarded to all connected **Reactions**
3. The **LLM Reaction** injects the data into its prompt
4. The AI processes the request
5. The result is stored and optionally forwarded as a signal

LLM Reactions run **only when new data arrives** — there is no scheduling.

***

### ⚙️ Configuration

#### Prompt

The prompt defines how the AI should interpret incoming data.

LLM Reactions support the following template variables:

* `{{data}}` → Raw payload from the webhook request
* `{{ip}}` → IP address of the sender
* `{{headers}}` → Request headers in JSON format

These variables are replaced at runtime with the actual values from the incoming request.

***

#### 🧾 Example Prompt

```
You will receive external data below.

IP: {{ip}}
Headers: {{headers}}

Payload:
{{data}}

Analyze the data and decide whether any action is required.
If the data is incomplete or unreliable, take no action.
```

***

### 🧩 Incoming Data & Context

The AI receives structured context from the webhook request:

#### `{{data}}`

* Contains the full request body
* Passed to the AI **as-is**
* No schema enforcement
* Typically JSON (text support coming soon)

***

#### `{{headers}}`

* Contains all HTTP request headers
* Provided as a **JSON object**
* Useful for authentication, source identification, or metadata

***

#### `{{ip}}`

* The IP address of the request sender (if available)
* Can be used for filtering or trust-based logic

***

### 🧪 Example Incoming Payload

```
{
  "event": "trend_signal",
  "symbol": "BTCUSDT",
  "direction": "up",
  "confidence": 0.81
}
```

***

### 🧾 Output & Storage

Each execution produces an output that:

* Is stored in the platform
* Is linked to the triggering webhook event
* Can be reviewed for debugging and auditing
* Can be forwarded to downstream systems

***

### 🧠 System Context (Automatically Injected)

When Trading Decision Mode is enabled, Sigrex automatically injects system-level context.

#### Prepended Context

```
You are a trading decision engine.

The last action was {{last_trigger_action}}.
That action executed at {{last_trigger_at}}.
The current time is {{current_time}}.

IMPORTANT:
- Only one position can be open at a time.
- If the last action was LONG or SHORT, a position is currently open.
- A new position may only be opened after an EXIT.
```

***

### 🧠 Prompt Writing Best Practices

* Clearly define **when to act**
* Explicitly describe **exit conditions**
* Handle conflicting or low-confidence data
* Prefer deterministic language
* Suppress explanations when using decision mode

#### Example Trading Prompt

```
You will receive external trading data below.

{{data}}

Open a position only if confidence is above 0.8.
Exit immediately if the data contradicts the current position.
If conditions are unclear, respond with HOLD.
```

***

### 🚫 Limitations

* No chart or image input
* No price selection
* One action per execution
* No partial positions
* Output must be exact

***

### 🔗 Related Features

* [**Data Webhook**](/reaction/data-webhook.md) – Receive external data
* [**Code Reaction**](/reaction/code-reaction.md) – Deterministic logic processing
* [**LLM Session**](/startegies/llm-session.md) – Scheduled AI analysis
* [**Chart Analysis**](/startegies/llm-session/chart-setup.md) **with** [**Signal Generation**](/startegies/llm-session/signal-generation.md) – Chart-based signals
* [**Signal Bots**](/cex-signal-bot/creating-a-cex-signal-bot.md) – Execute trades

***

### 🧠 Summary

LLM Reactions provide a powerful way to:

* React to live external data
* Apply AI reasoning in real time
* Make structured trading decisions
* Build event-driven trading systems without charts

They are best suited for **clean, rule-guided AI decisions** triggered by external events.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.sigrex.io/reaction/llm-reaction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
