> For the complete documentation index, see [llms.txt](https://rwapact.gitbook.io/whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rwapact.gitbook.io/whitepaper/the-five-layer-pact/kgr-gas-router.md).

# KGR, Gas Router

## KGR, Gas Router

Autonomous agents may trade frequently. Gas costs can materially affect the economics of repeated execution.

KGR is the gas optimization layer of the Five-Layer Pact. It evaluates whether a requested execution can use a more efficient gas condition or execution path. Gas is therefore part of the decision context before execution.

KGR is not a generic DEX router or the execution venue itself. It evaluates gas and routing conditions for the Pact.

### Optimization strategies

| Strategy             | Role                                        |
| -------------------- | ------------------------------------------- |
| Gas price monitoring | Track current base fee and priority fee.    |
| Delay window         | Queue a trade when gas is high.             |
| Batch execution      | Combine multiple agent trades.              |
| Alternative routes   | Compare execution paths for gas efficiency. |
| L2 fallback          | Use a cheaper L2 when available.            |

These strategies define the scope of KGR in the specification. They support gas-aware decisions but do not guarantee savings.

### Gas route

KGR represents a proposed route with the following `GasRoute` fields:

| Field          | Meaning                                          |
| -------------- | ------------------------------------------------ |
| `estimatedGas` | Estimated gas required for the route.            |
| `gasPrice`     | Gas price used for the route assessment.         |
| `totalCost`    | Estimated total route cost.                      |
| `routePath`    | Proposed execution path.                         |
| `delayed`      | Whether the route uses a delayed condition.      |
| `executeAfter` | Time after which delayed execution can continue. |

The structure describes the proposed gas route and its execution conditions. It does not add routing parameters beyond those defined by the specification.

### KGR within the Pact

```
Trade Intent
  |
  v
Risk
  |
  v
Session
  |
  v
Policy
  |
  v
KGR
  |
  v
Authorization
  |
  v
Execution
```

KGR does not replace KRO, KSO, or KPV. A cheap route can still be too risky or unauthorized. A trade can also pass risk and policy checks while current gas conditions are not optimal.

The Pact decision logic includes `KGR_Gas_Optimized`. Gas optimization is therefore part of the authorization model defined by the specification. It does not mean the transaction is always the cheapest possible.

### Delay windows

When gas is high, the protocol can represent a delayed execution condition where supported. This creates a tradeoff between immediate execution and waiting for `executeAfter`.

```
Gas High
  -> Delay Window
  -> Wait Until executeAfter
  -> Continue Execution Path
```

Execution integrations can support delayed execution differently. KGR represents the condition without requiring identical behavior from every integration.

### Batch execution

KGR can combine multiple agent trades into one transaction where supported. For example, an agent may identify an arbitrage opportunity involving two RWA pools.

KGR evaluates whether both legs can execute in one batch for gas efficiency. The specification does not define a particular batching contract architecture.

### Alternative routes and L2 fallback

Alternative routes compare available execution paths for gas efficiency. L2 fallback routes to a cheaper L2 when available.

These are design strategies in the specification. They do not claim that cross-chain execution is already live.

### Scope of KGR

KGR answers one question:

> Can the requested execution be handled under acceptable gas conditions or a more efficient execution path?

The final layer preserves the resulting decision and context: [KAR, Attestation Registry](/whitepaper/the-five-layer-pact/kar-attestation-registry.md).

***


---

# 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://rwapact.gitbook.io/whitepaper/the-five-layer-pact/kgr-gas-router.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.
