@runic-labs/sdk
askRunic と storeResult — エージェント向け契約のすべて。
@runic-labs/sdk は、ほとんどの統合で直接インポートする必要がある唯一のパッケージです。@runic-labs/cache と @runic-labs/ledger を2つの関数でラップします。
npm install @runic-labs/sdkpnpm add @runic-labs/sdkyarn add @runic-labs/sdkbun add @runic-labs/sdkモジュールレベル関数
一般的なケース — 1つのエージェントプロセスとデフォルトのファイルバックドストレージ — では、フリー関数を直接使用します。
import { askRunic, storeResult } from "@runic-labs/sdk";
askRunic(decision)
この完全に一致する決定がすでに解決済みかどうかを確認します。
decisionDecision
{ intent: string; params: Record<string, unknown> }
DecisionPromise<CachedEntry | null> を返します。ミス時は null、ヒット時はキャッシュ済みエントリを返し(かつヒットを台帳に記録します)。
signature?string
The normalized signature this entry is keyed on.
stringartifact?unknown
Whatever was passed to storeResult() originally.
unknowntokensSpent?number
What producing this artifact cost the first time.
numbercreatedAt?number
Epoch ms when this entry was first stored.
numberlastUsedAt?number
Epoch ms of the most recent hit.
numberhitCount?number
Number of times this entry has been reused.
numberstale?boolean
Advisory only — Runic never acts on this itself.
booleanstoreResult(decision, artifact, tokensSpent)
決定に対して新しく生成したアーティファクトを記録し、そのコストをログに残します。これにより、将来のヒット時にどれだけ節約できたかがわかります。
decisionDecision
Same shape as askRunic's argument.
Decisionartifactunknown
Whatever you want returned on a future cache hit.
unknowntokensSpentnumber
Agent-reported cost of producing this artifact. Runic never measures this itself.
numberPromise<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);
cache?Cache
Defaults to a file-backed cache under .runic/ if omitted.
Cacheledger?Ledger
Defaults to a file-backed ledger under .runic/ if omitted.
Ledgerモジュールレベル関数と同じ askRunic / storeResult 形式を持つ RunicClient を返します。これは、渡した cache/ledger インスタンスにスコープされます。