コンテンツにスキップ
Runic
日本語
Esc
移動開く⌘Jプレビュー
このページの内容

@runic-labs/sdk

askRunic と storeResult — エージェント向け契約のすべて。

@runic-labs/sdk は、ほとんどの統合で直接インポートする必要がある唯一のパッケージです。@runic-labs/cache@runic-labs/ledger を2つの関数でラップします。

npm install @runic-labs/sdk
pnpm add @runic-labs/sdk
yarn add @runic-labs/sdk
bun add @runic-labs/sdk

モジュールレベル関数

一般的なケース — 1つのエージェントプロセスとデフォルトのファイルバックドストレージ — では、フリー関数を直接使用します。

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

askRunic(decision)

この完全に一致する決定がすでに解決済みかどうかを確認します。

PropType
decisionDecision

{ intent: string; params: Record<string, unknown> }

TypeDecision

Promise<CachedEntry | null> を返します。ミス時は null、ヒット時はキャッシュ済みエントリを返し(かつヒットを台帳に記録します)。

PropType
signature?string

The normalized signature this entry is keyed on.

Typestring
artifact?unknown

Whatever was passed to storeResult() originally.

Typeunknown
tokensSpent?number

What producing this artifact cost the first time.

Typenumber
createdAt?number

Epoch ms when this entry was first stored.

Typenumber
lastUsedAt?number

Epoch ms of the most recent hit.

Typenumber
hitCount?number

Number of times this entry has been reused.

Typenumber
stale?boolean

Advisory only — Runic never acts on this itself.

Typeboolean

storeResult(decision, artifact, tokensSpent)

決定に対して新しく生成したアーティファクトを記録し、そのコストをログに残します。これにより、将来のヒット時にどれだけ節約できたかがわかります。

PropType
decisionDecision

Same shape as askRunic's argument.

TypeDecision
artifactunknown

Whatever you want returned on a future cache hit.

Typeunknown
tokensSpentnumber

Agent-reported cost of producing this artifact. Runic never measures this itself.

Typenumber

Promise<void> を返します。

createRunicClient(options?)

複数の独立したクライアントが必要な場合 — 最も一般的にはテスト時、またはインメモリストレージを明示的に選択する場合 — は、モジュールレベル関数の代わりにこれを使用します。

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);
PropType
cache?Cache

Defaults to a file-backed cache under .runic/ if omitted.

TypeCache
ledger?Ledger

Defaults to a file-backed ledger under .runic/ if omitted.

TypeLedger

モジュールレベル関数と同じ askRunic / storeResult 形式を持つ RunicClient を返します。これは、渡した cache/ledger インスタンスにスコープされます。

次へ

  • キャッシュ — カスタム CacheStore 実装を構築する
  • 台帳 — 台帳サマリーを直接読み取る
  • CLI — コマンドラインから状態を確認する

このページは役に立ちましたか?