@anvia/core

Provider-neutral runtime for agents, tools, messages, pipelines, and evals.

@anvia/core is the central package. Every other @anvia/* package depends on it. It provides the agent runtime, tool system, message types, pipeline execution, structured extraction, evals, vector store interfaces, memory, MCP adapters, and observability contracts.

Install

pnpm add @anvia/core

Pair it with a provider package to get a model:

pnpm add @anvia/openai

Quick Start

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

const client = new OpenAIClient({ apiKey });
const model = client.completionModel("gpt-5.5");

const lookupOrder = createTool({
  name: "lookup_order",
  description: "Look up an order by id.",
  input: z.object({ orderId: z.string() }),
  output: z.object({ status: z.string() }),
  async execute({ orderId }) {
    return { status: orderId === "A-100" ? "shipped" : "unknown" };
  },
});

const agent = new AgentBuilder("support", model)
  .name("Support Agent")
  .instructions("Answer support questions. Use tools when needed.")
  .tool(lookupOrder)
  .defaultMaxTurns(3)
  .build();

const response = await agent.prompt("Where is order A-100?").send();
console.log(response.output);

Root Exports

The root import path covers the most common APIs:

import {
  AgentBuilder,
  createTool,
  Message,
  // ...and many more
} from "@anvia/core";

Use the root import for small apps, examples, and prototyping.

Subpath Exports

For larger codebases or narrower dependency boundaries, import from focused subpaths:

SubpathArea
@anvia/core/agentAgent builders, hooks, run controls, errors, run events
@anvia/core/completionCompletion messages, requests, responses, usage, model contracts
@anvia/core/toolTool definitions, registries, tool sets, serialization
@anvia/core/pipelineTyped pipelines and batch execution
@anvia/core/extractorStructured extraction builders
@anvia/core/evalsEval suites, metrics, agent targets, reporters
@anvia/core/embeddingsEmbedding models, documents, vector math
@anvia/core/vector-storeIn-memory vector store, filters, search tools
@anvia/core/memoryDurable session memory interfaces
@anvia/core/mcpMCP connection helpers and normalized types
@anvia/core/observabilityObserver interfaces, trace options, score contracts
@anvia/core/skillsSkill loading, discovery, validation
@anvia/core/streamingAsync iterable to ReadableStream conversion
@anvia/core/loadersNode file and PDF loaders
@anvia/core/model-listingProvider-neutral model listing contracts
@anvia/core/image-generationImage generation contracts
@anvia/core/audio-generationAudio generation contracts
@anvia/core/transcriptionAudio transcription contracts
import { AgentBuilder } from "@anvia/core/agent";
import { createTool } from "@anvia/core/tool";
import type { CompletionModel } from "@anvia/core/completion";

@anvia/core/loaders is intentionally subpath-only so that normal core imports do not pull in Node filesystem and PDF dependencies.

Key Concepts

AgentBuilder is the primary entry point. It configures an agent with a model, instructions, tools, context, observers, and hooks, then .build() produces a reusable agent.

createTool defines a tool with Zod-validated input and output schemas. Tools are pure TypeScript functions that the agent can call during a run.

Messages are plain objects (Message.user(...), Message.assistant(...), Message.tool(...)). History is a Message[] array you store wherever your app persists conversations.

Observers receive lifecycle events (run start/end, generation, tool calls) without changing runtime behavior. Attach them with .observe(...).

Hooks can cancel runs, approve tool calls, or transform requests and responses. Attach them with .onRunStart(...), .onToolCall(...), etc.

When to Use Subpaths

Start with root imports while learning. Move to subpaths when:

  • You want explicit import boundaries between modules
  • Your bundler benefits from tree-shaking narrower entry points
  • You are building an integration package that only needs tool types, not the full agent runtime