# Agent recipes

These recipes describe orchestration. Template availability, parameters, chains, prices, and ranges must be discovered from the live service. All example IDs and addresses are placeholders.

## Read a token balance

1. Discover `erc20.token_balance` if it is present; inspect its bind parameters. A single token and wallet use `tokens` and `owners` arrays.
2. Bind the explicit token, wallet, and configured chain.
3. Inspect coverage and the chain head, then select one block as `[n, n+1)`. Confirm finality separately if the application requires it.
4. Materialize a missing block under authorized spending.
5. Read the balance through its own pay gate.
6. Report the declared value type and block; request provenance for the same bound identity and window.

A balance read at the latest materialized block is convenient, but a trading decision may require newer coverage. Compare landmarks before describing it as current.

## Measure transfers over a period

Discover a transfer-volume template, such as `erc20.token_volume` if advertised. Inspect its exact scope holes and definition. Establish block boundaries for the requested period, bind the contract and chain, then use inspect/materialize/read.

Do not substitute transferred amount for trade volume, wallet net flow, or unique senders without a matching definition. If the template does not express the requested quantity, use [question resolution](/agents/authoring/) to check catalog support; unsupported requests cannot create a new Function.

## Resolve ownership

If `erc721.owner` is advertised, inspect its token/contract parameters before binding. Read the explicit block window and preserve the chain and token scope. Ownership at a historical block is not ownership at the current head.

## Produce an auditable report

For each measure, retain its bound identity, operator's intended definition, exact window, returned field type and values, payment receipt, and provenance record. State which source digests were compared. Keep unsupported interpretations out of the numerical result.

## Resume after interruption

Recover stored quote, payment, and job IDs. Inspect the bound-function geometry and any known job. If already running, wait; if done, read. If the quote expired before execution, request a new quote and reconcile the previous settlement before paying. Treat timeout as unknown state until inspected.

## Read only the needed rows

Use `read.key` to restrict a leading run of key parts advertised by the Function's row schema. For example, `{"token":"<TOKEN_ADDRESS>"}` applies when `token` is the first key part. Every matching row includes all its attributes. Narrow an explicit window when useful. `attributes`, `entity`, `cursor`, and `limit` are retired inputs. Do not assume a key filter changes the price; the quote decides.

## Reuse another agent's work

Share the endpoint and bound-function identity with its chain/scope record. Inspect coverage independently and read the required window. Shared materialization reduces repeated computation; reads still use the current read pay gate. Keep any claim-right ownership separate from the identity of an agent that happens to query the dataset.
