---
title: '@runic-labs/sdk'
description: askRunic e storeResult — todo o contrato voltado para o agente.
sidebar:
  order: 3
---
`@runic-labs/sdk` é o único pacote que a maioria das integrações precisa importar diretamente. Ele encapsula `@runic-labs/cache` e `@runic-labs/ledger` por trás de duas funções.

```package-install
npm i @runic-labs/sdk
```

## Funções no nível do módulo

Para o caso comum — um processo de agente, armazenamento padrão baseado em arquivos — use as funções livres diretamente:

```ts
import { askRunic, storeResult } from "@runic-labs/sdk";
```

### `askRunic(decision)`

Verifica se esta decisão exata já foi resolvida.

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | { intent: string; params: Record<string, unknown> } |

Retorna `Promise<CachedEntry | null>` — `null` em caso de ausência, ou a entrada em cache (e registra um acerto no ledger) em caso de acerto.

| Prop | Type | Default | Description |
| - | - | - | - |
| `signature?` | `string` | - | The normalized signature this entry is keyed on. |
| `artifact?` | `unknown` | - | Whatever was passed to storeResult() originally. |
| `tokensSpent?` | `number` | - | What producing this artifact cost the first time. |
| `createdAt?` | `number` | - | Epoch ms when this entry was first stored. |
| `lastUsedAt?` | `number` | - | Epoch ms of the most recent hit. |
| `hitCount?` | `number` | - | Number of times this entry has been reused. |
| `stale?` | `boolean` | - | Advisory only — Runic never acts on this itself. |

### `storeResult(decision, artifact, tokensSpent)`

Registra um artefato recém-gerado para uma decisão e registra seu custo para que um acerto futuro saiba quanto ele economizou.

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | Same shape as askRunic's argument. |
| `artifact` | `unknown` | - | Whatever you want returned on a future cache hit. |
| `tokensSpent` | `number` | - | Agent-reported cost of producing this artifact. Runic never measures this itself. |

Retorna `Promise<void>`.

## `createRunicClient(options?)`

Use isto em vez das funções no nível do módulo quando precisar de vários clientes independentes — mais comumente para testes ou ao escolher explicitamente o armazenamento em memória:

```ts
import { createRunicClient } from "@runic-labs/sdk";
import { createCache, MemoryCacheStore } from "@runic-labs/cache";
import { createLedger, MemoryLedgerStore } from "@runic-labs/ledger";

const runic = createRunicClient({
  cache: createCache(new MemoryCacheStore()),
  ledger: createLedger(new MemoryLedgerStore()),
});

await runic.askRunic({ intent: "summarize_pr", params: { repo, pr } });
await runic.storeResult({ intent: "summarize_pr", params: { repo, pr } }, artifact, tokensUsed);
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `cache?` | `Cache` | - | Defaults to a file-backed cache under .runic/ if omitted. |
| `ledger?` | `Ledger` | - | Defaults to a file-backed ledger under .runic/ if omitted. |

Retorna um `RunicClient` com a mesma estrutura de `askRunic` / `storeResult` das funções no nível do módulo, restrito às instâncias de `cache`/`ledger` que você passou.

## Próximo

- [Cache](/cache) — construa implementações personalizadas de `CacheStore`
- [Ledger](/ledger) — leia resumos do ledger diretamente
- [CLI](/cli) — inspecione o estado pela linha de comando
