npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anvia/core

v0.2.4

Published

Core runtime primitives for context-aware Anvia agents.

Downloads

2,150

Readme

@anvia/core

Core runtime primitives for Anvia agents, tools, structured extraction, pipelines, streaming, RAG, MCP, skills, and observability.

This package is provider-neutral. Pair it with a provider adapter such as @anvia/openai, @anvia/anthropic, or @anvia/gemini to create runnable models.

Installation

pnpm add @anvia/core

In this monorepo, the package is available through the workspace:

pnpm --filter @anvia/core build

Usage

import { z } from "zod";
import { AgentBuilder, ExtractorBuilder, PipelineBuilder, createTool } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({
  apiKey,
});

const model = client.completionModel("gpt-5");

const lookupOrder = createTool({
  name: "lookup_order",
  description: "Look up an order by id.",
  input: z.object({ orderId: z.string() }),
  execute: async ({ orderId }) => ({ orderId, status: "processing" }),
});

const agent = new AgentBuilder("support", model)
  .instructions("Help customers with order questions.")
  .tool(lookupOrder)
  .defaultMaxTurns(4)
  .build();

const response = await agent.prompt("What is happening with order A123?").send();

console.log(response.output);

Prompts and Memory

Use a plain prompt for stateless calls:

await agent.prompt("Summarize this ticket.").send();

Use a message array when you already own the transcript. The last message is the active prompt and earlier messages are request history:

import { Message } from "@anvia/core";

await agent
  .prompt([
    Message.user("My project is named Anvia."),
    Message.assistant("Noted."),
    Message.user("What is my project named?"),
  ])
  .send();

Configure durable conversation memory on the agent, then run through a session:

import {
  AgentBuilder,
  type MemoryAppendInput,
  type MemoryContext,
  type MemoryStore,
  type Message,
} from "@anvia/core";

class AppMemoryStore implements MemoryStore {
  private readonly sessions = new Map<string, Message[]>();

  async load(context: MemoryContext): Promise<Message[]> {
    return [...(this.sessions.get(context.sessionId) ?? [])];
  }

  async append(input: MemoryAppendInput): Promise<void> {
    const current = this.sessions.get(input.context.sessionId) ?? [];
    this.sessions.set(input.context.sessionId, [...current, ...input.messages]);
  }

  async clear(context: MemoryContext): Promise<void> {
    this.sessions.delete(context.sessionId);
  }
}

const memory = new AppMemoryStore();
const agent = new AgentBuilder("support", model).memory(memory).build();

await agent.session("thread_123", { userId: "user_456" }).prompt("Remember my plan.").send();
await agent.session("thread_123", { userId: "user_456" }).prompt("What is my plan?").send();

Memory defaults to savePolicy: "message", which saves the user prompt, each completed assistant message, and each completed tool result as soon as they are ready. You can choose "turn" or "run" at configuration time:

new AgentBuilder("support", model).memory(memory, { savePolicy: "turn" });

Structured Extraction

const ticketSchema = z.object({
  customer: z.string(),
  priority: z.enum(["low", "medium", "high"]),
  summary: z.string(),
});

const extractor = new ExtractorBuilder(model, ticketSchema).retries(1).build();

const ticket = await extractor.extract(
  "Acme Co. reports checkout failures. Priority is high.",
);

Pipelines

const pipeline = new PipelineBuilder<string>()
  .step((input) => `Extract this support ticket:\n\n${input}`)
  .prompt(agent)
  .extract(extractor)
  .build();

const result = await pipeline.run("Customer cannot complete checkout.");

Public Areas

  • agent: agent runtime and AgentBuilder
  • tool: typed tool creation and tool sets
  • completion: provider-neutral completion request and response types
  • memory: durable session memory interfaces and in-memory store
  • extractor: schema-first structured extraction
  • pipeline: typed sequential and parallel workflows
  • embeddings: embedding helpers and document embedding utilities
  • vector-store: in-memory vector search and vector search tools
  • streaming: normalized stream helpers
  • mcp: MCP server connection helpers
  • skills: local skill loading
  • observability: observer interfaces for runs, generations, and tool calls
  • evals: evaluation helpers and reporters
  • loaders: document loading utilities
  • audio-generation, image-generation, transcription: provider-neutral media interfaces

Development

pnpm --filter @anvia/core typecheck
pnpm --filter @anvia/core test
pnpm --filter @anvia/core build