---
title: '@runic-labs/sdk'
description: askRunic y storeResult — todo el contrato de cara al agente.
sidebar:
  order: 3
---
`@runic-labs/sdk` es el único paquete que la mayoría de las integraciones necesitan importar directamente. Envuelve `@runic-labs/cache` y `@runic-labs/ledger` mediante dos funciones.

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

## Funciones de nivel de módulo

Para el caso habitual — un proceso de agente, almacenamiento predeterminado respaldado por archivos — usa directamente las funciones libres:

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

### `askRunic(decision)`

Comprueba si esta decisión exacta ya se ha resuelto.

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

Devuelve `Promise<CachedEntry | null>` — `null` si no se encuentra, o la entrada en caché (y registra un acierto en el libro mayor) si se encuentra.

| 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 un artefacto recién generado para una decisión y anota su coste para que un acierto futuro sepa cuánto ahorró.

| 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. |

Devuelve `Promise<void>`.

## `createRunicClient(options?)`

Usa esto en lugar de las funciones de nivel de módulo cuando necesites varios clientes independientes — normalmente para pruebas o al elegir explícitamente almacenamiento en memoria:

```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. |

Devuelve un `RunicClient` con la misma forma de `askRunic` / `storeResult` que las funciones de nivel de módulo, limitado a las instancias de `cache`/`ledger` que proporcionaste.

## Siguiente

- [Caché](/cache) — crea implementaciones personalizadas de `CacheStore`
- [Libro mayor](/ledger) — lee resúmenes del libro mayor directamente
- [CLI](/cli) — inspecciona el estado desde la línea de comandos
