# Autonomous Margin Layer

> The Autonomous Margin Layer (AML) is Liqui’s intelligent module for margin trading, combining AI agents and smart contracts deployed on MegaETH.&#x20;
>
> AML enables adaptive leveraged trading by dynamically adjusting position parameters based on market conditions, user behavior, and real-time risk evaluation.

### AML Components

**AI Agents:**

* Analyzes market data in real time (price, volatility, liquidity, trader activity)
* Determines leverage, liquidation thresholds, and position risk profile

**Oracle Layer:**

* Relays AI decisions to smart contracts on MegaETH
* Can use multisig or custom oracle implementation

&#x20;**Smart Contracts:**

* Enforce AI recommendations: open positions, adjust leverage, trigger liquidation
* Use isolated collateral storage and dynamic margin levels

### How It Works:

* The user initiates a margin position through the Liqui interface
* The AI agent evaluates acceptable leverage, risk score, and liquidation threshold
* The parameters are signed and sent to the contract
* The smart contract executes the position under those constraints
* The AI continuously monitors the position and suggests updates or closure when needed

### AI Feedback & Security

* All AI decisions include a signature and hash, verified on-chain
* Historical data feeds back into model improvement
* Contracts include failsafes: halts, freezes, risk boundary checks

{% hint style="info" %}
**Benefits:**

* Adaptive leverage configuration in real time
* Safer and more precise liquidation logic
* AI-driven risk profiling per user and asset
* Transparent and verifiable margin management
  {% endhint %}


---

# 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.liqui.io/autonomous-margin-layer.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.
