Agents
Routes for creating, reading and running hosted agents. All need a session. Routes under /v1/agents/:id answer only the agent's owner, the address that created it; any other session gets 404 NO_SUCH_AGENT.
The agent object#
| Field | Type | Notes |
|---|---|---|
| id | string | a- and 16 hex digits. |
| owner | string | Your address. |
| name | string | |
| side | lender or borrower | Set by the preset. |
| preset | string | steady, yield, refinancer, taker, switcher or shopper. |
| address | string | The agent's own Sui address. |
| treasuryId, ownerCapId, agentCapId | string or null | Set after create lands. For a borrower, these are the SUI treasury's. |
| cash | object or null | Borrowers only: the cash treasury and its caps. |
| capExpiresAtMs | number or null | When the agent's rules end. |
| mandate | object or null | Lenders: the form last applied on chain, when and with which digest. |
| borrow | object or null | Borrowers: the same for the borrower form. |
| revoked | boolean | |
| selfRun | true or absent | A self-run agent: the server holds no key for it and never launches it. |
| status | setup, ready or revoked | ready once rules are applied. |
| createdAt, updatedAt | string | ISO time. |
The agent's key is never returned.
List agents#
{ ok, agents: Agent[] }Oldest first.
Create an agent#
201 { ok, agent }This creates the agent and its key; nothing is on chain until you sign create.
| Field | Type | Notes |
|---|---|---|
| name | string | Lowercase letters, digits and dashes, starting with a letter or digit, up to 63 characters. |
| preset | string | A lender or borrower style. |
| Error | Status |
|---|---|
BAD_NAME | 400 |
BAD_PRESET | 400 |
AGENT_LIMIT | 429 — you already have the maximum number of agents. |
curl -s -X POST http://127.0.0.1:8790/v1/agents \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"name": "my-lender", "preset": "steady"}'Preview a lender's rules#
With { form } → { ok, sentence, chain }, or 400 BAD_FORM with an errors list of { field, message }. Nothing is signed.
The lender form:
| Field | Type | Rule |
|---|---|---|
| name | string | As above. |
| preset | string | steady, yield or refinancer. |
| totalBudget | decimal string | Above zero, at most the budget limit (100 USDC on testnet). |
| minLoan, maxLoan | decimal string | Above zero; min ≤ max ≤ totalBudget. |
| minRateBps | integer | 0 to 99,999. |
| maxLtvBps | integer | 1 up to the market's borrow limit. |
| termsDays | integer[] | One or more of 1, 7, 30. |
| expiresAtMs | integer | In the future and within 30 days. |
| aiMode | boolean | Must be off: AI mode is not available. |
chain holds what will be written on chain: totalCap, minFill, maxFill, minRateBps, maxDurationMs, takerKind, takers, maxLtvBps, capExpiresAtMs.
The borrower form is not this create body. It is the form on POST /v1/agents/:id/tx (create, deposit, rules) and on POST /v1/borrow/preview. Every field:
| Field | Type | Required | Default | Units | Validation |
|---|---|---|---|---|---|
| name | string | yes | — | — | ^[a-z0-9][a-z0-9-]{0,62}$. |
| preset | string | yes | — | — | taker, switcher or shopper. switcher needs a pool. A hosted shopper cannot launch. |
| collateral | string | yes | — | SUI, ≤ 9 decimals | Above zero. |
| amount | string | yes | — | USDC, ≤ 6 decimals | Above zero, at most 100. |
| maxRateBps | number | yes | — | basis points a year | Integer 1–100000. |
| repayBeforeHours | number | yes | — | hours | Integer 0–720. The on-chain lead is at least 1 hour. |
| cashFloat | string | yes | — | USDC | "0" or positive. |
| expiresAtMs | number | yes | — | Unix ms | 62 minutes to 30 days ahead. |
| autoTopUp | boolean | no | off | — | Boolean when present. |
| topUpSui | string | no | "0" | SUI | "0" or positive. |
| autoClaim | boolean | no | on | — | Boolean when present. Only false turns it off. |
{
"action": "create",
"form": {
"name": "desk-taker",
"preset": "taker",
"collateral": "1",
"amount": "1",
"maxRateBps": 800,
"repayBeforeHours": 6,
"cashFloat": "0.05",
"expiresAtMs": 1793500000000,
"autoTopUp": false,
"topUpSui": "0.1",
"autoClaim": true
}
}Set expiresAtMs to a real time in that window. The same object is what EsseyAgent.borrowFromOffer and borrowFromPool run under, once GET /v1/agent/setup is ready: collateral leaves the SUI treasury, the USDC lands in the cash treasury, and repay spends the cash treasury. The calls are on Agent transactions.
Get an agent#
| Field | What it is |
|---|---|
| agent | The agent object. |
| runner | {desired, status, ticks, lastTickAt, lastError, killed} or null if never launched. |
| balances | {treasury} for a lender; {treasury (SUI), cash (USDC), allowance} for a borrower; base units. |
| balances.allowance | Borrowers: {total, remaining} as strings in USDC base units. total is what your last signed rules allowed; remaining is what the chain has left (treasury::borrow_allowance_of). Null before the borrow rules are set. |
| warnings | What needs your attention now (below). |
| withdrawWarnings | Borrowers: the repay warnings you would get if you withdrew all the cash. |
Runner status is one of running, paused, stopped, killed, limited or blocked.
| Warning | Side | Meaning |
|---|---|---|
REPAY_UNDERFUNDED | borrower | The cash treasury will not cover a repay by its deadline; includes shortfall and deadlineMs. |
RULES_BLOCK_REPAY | borrower | The agent's cash rules end too soon or allow too little per draw to repay. |
NEAR_LIQUIDATION | borrower | A loan nears its safety line and auto top-up is off or short; includes suiNeeded. |
LOAN_UNDERWATER | lender | A loan it made is past its safety line. |
Launch, pause, stop#
, /pause, /stop → { ok, runner }. Stop also cancels the agent's standing offers.
Launch is refused with 409 and one of:
| Error | When |
|---|---|
REVOKED | The agent was revoked. |
SELF_RUN | A self-run agent runs on its own machine; the server does not launch it. |
ROOM_NEEDS_PASSKEY | A shopper cannot be hosted: only your passkey can open its room's bids. |
NOT_READY | Rules not applied yet. |
NOT_FUNDED | The treasury is empty (a borrower's SUI treasury). |
KILL_SWITCH_ON | The operator stopped all agents. |
CANNOT_START: <reason> | The agent failed to start. |
Settings#
— hosted borrowers only.
| Field | Type |
|---|---|
| autoTopUp | boolean, optional |
| autoClaim | boolean, optional |
Returns { ok, agent, runner }; a running agent restarts on the new settings. Errors: NOT_READY (409), BAD_SETTING (400) when a value is not a boolean or nothing is set.
Loans#
{ ok, loans }For a lender, the loans it made; for a borrower, the loans whose deed its SUI treasury holds. Each item is:
| Field | Notes |
|---|---|
| id | The loan object id. Kept for older clients. |
| loanId | The same id. GET /v1/borrow/loans already names the field loanId. |
| principal | Loan-coin units, decimal string. |
| rateBps | The offer's rate, or the pool rate the summary recorded. |
| collateral | Collateral units, decimal string. |
| state | open, or a closed state such as repaid, liquidated, defaulted. |
| maturityMs | When an offer loan matures. 0 on a pool loan. |
| dueAtMs | When a default can be collected. For a borrower this is maturityMs. |
| claimable | Lender: the loan is open, past due, and collectable. Borrower: closed with collateral left to claim. |
Activity#
{ ok, items, more }On-chain events for the agent's treasury merged with the agent's own decisions, the newest 200; more is true when older ones exist. Each item is {at, source: "chain" | "runner", kind, text, digest}.