yantrix
v1.0.0
Published
JavaScript/TypeScript SDK for Yantrix agent infrastructure — policy enforcement, semantic memory, and audit traces
Downloads
37
Maintainers
Readme
yantrix
JavaScript/TypeScript SDK for Yantrix agent infrastructure.
Policy enforcement · Semantic memory · Full audit traces — for any JS/TS agent runtime.
npm install yantrixQuick start
import { configure, run } from "yantrix";
configure({ apiKey: process.env.YANTRIX_API_KEY! });
const result = await run({ intent: "research competitor pricing" });
console.log(result.traceId); // ytx_run_0ba9b36a
console.log(result.status); // "completed" | "policy_denied"
console.log(result.totalCostUsd); // 0.156Client API
import { Yantrix } from "yantrix";
const ytx = new Yantrix({
apiKey: "ytx_...",
agentId: "my_agent",
budgetUsd: 5.0, // daily cap
fallbackOnError: true, // proceed if Yantrix unreachable
});
// Run an intent
const result = await ytx.run({ intent: "summarize latest AI news" });
// Policy check only (no execution)
const policy = await ytx.evaluatePolicy({ action: "send_email", estimatedCostUsd: 0.01 });
if (policy.decision === "deny") throw new Error(policy.reason);
// Memory
await ytx.remember({ key: "research_001", content: "OpenAI cut prices 50%" });
const memories = await ytx.recall({ query: "OpenAI pricing", topK: 3 });
await ytx.forget("research_001");
// Traces
const trace = await ytx.getTrace("ytx_run_0ba9b36a");
const recent = await ytx.listTraces(10);
// Budget
await ytx.setBudget(10.0);
const { today, remaining, limit } = await ytx.getSpend();LangChain.js
import { wrapTools, YantrixCallbackHandler } from "yantrix/langchain";
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
// Option 1: wrap tools (full governance)
const tools = wrapTools(
[new TavilySearchResults()],
{ apiKey: "ytx_...", agentId: "langchain_agent" }
);
// Option 2: callback handler (observability only)
const handler = new YantrixCallbackHandler({ apiKey: "ytx_..." });
const agent = await createReactAgent({ tools, llm, callbacks: [handler] });Vercel AI SDK
import { wrapTools, yantrixMiddleware } from "yantrix/vercel-ai";
import { generateText, wrapLanguageModel } from "ai";
import { openai } from "@ai-sdk/openai";
// Option 1: wrap tools
const tools = wrapTools(myTools, { apiKey: "ytx_...", agentId: "vercel_agent" });
const { text } = await generateText({ model: openai("gpt-4o"), tools, prompt });
// Option 2: model middleware (intercepts all LLM calls)
const model = wrapLanguageModel({
model: openai("gpt-4o"),
middleware: yantrixMiddleware({ apiKey: "ytx_..." }),
});What happens on every call
Your agent action
↓
Policy Engine — is this allowed? within budget?
↓ allow
Semantic Memory — inject relevant past context
↓
Execution — your tool/task runs normally
↓
Trace stored — full audit log
↓
Result returnedFull trace visible at trace.yantrix.ai.
Configuration
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | — | Your Yantrix API key (ytx_...) |
| agentId | string | "js_agent" | Agent identifier for scoping |
| budgetUsd | number | 0 | Daily spend cap in USD |
| timeout | number | 30000 | Request timeout in ms |
| fallbackOnError | boolean | true | Proceed if Yantrix unreachable |
| baseUrl | string | https://runtime.yantrix.ai | Override base URL |
Environment variable: YANTRIX_API_KEY (used by global configure() if no key passed).
