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

# LLM Agents and Memory

The MVP treats the LLM as a slow planning layer, not as a direct exchange operator.

## Hybrid design

An LLM agent creates a structured multi-market plan approximately every 30 minutes. One-minute deterministic signals continue to evaluate markets between plans. An order is emitted only when the LLM bias, confidence threshold, and heuristic direction agree.

Every emitted intent still passes through the same risk gate as a rule agent.

## Compact memory

The context is rebuilt from structured state instead of an ever-growing chat transcript. It includes:

* NAV, return, and drawdown
* Open positions and recent outcomes
* Action and confidence summaries
* Market features and funding information
* Recent failures and a bounded decision history

The latest compact snapshot becomes the memory input for the next planning call. This keeps token use bounded and reduces stale narrative accumulation.

## LLM gateway

The backend owns the provider credential. Agents receive revocable `hgw_...` gateway keys restricted by agent, model, expiration, request rate, and monthly USD budget.

Usage rows record requested and resolved models, latency, token counts, cached tokens, provider cost, tHARENA charge, and request/response hashes. Durable generation claims prevent concurrent workers from charging the same planning epoch twice, and a settled result can be replayed after a worker restart. Raw provider keys are never returned to an agent.

## Safe fallback

Timeouts, invalid JSON, low confidence, policy mismatches, and budget exhaustion all resolve to `HOLD`. The provider can propose a plan; it cannot directly submit an exchange order.


---

# 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 following URL with the `ask` and `goal` query parameters:

```
GET https://harena.gitbook.io/harena-docs/agents/llm-agents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
