Skip to content

@anvia/core ​

@anvia/core is Anvia's provider-neutral runtime. It owns agents, direct completions, typed tools, memory contracts, retrieval, pipelines, streaming events, guardrails, skills, MCP connections, evaluations, and the shared message types used by the rest of the SDK.

Use it when application code should describe agent behavior without depending on one model provider. Provider packages such as @anvia/openai, @anvia/anthropic, and @anvia/gemini supply the runnable model objects.

Install ​

sh
pnpm add @anvia/core zod

zod is a direct dependency of Core, but application code normally imports it when defining tool inputs and structured outputs.

Build a useful agent ​

ts
import { AgentBuilder, createTool } from '@anvia/core'
import { OpenAIClient } from '@anvia/openai'
import { z } from 'zod'

const model = new OpenAIClient({
  apiKey: process.env.OPENAI_API_KEY,
}).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 supportAgent = new AgentBuilder('support', model)
  .instructions('Help customers understand their order status.')
  .tools([lookupOrder])
  .defaultMaxTurns(4)
  .build()

const response = await supportAgent
  .prompt('What is happening with order A123?')
  .send()

console.log(response.output)

The model, credentials, business data, permissions, storage, and deployment remain application-owned. Core coordinates the run around dependencies supplied by the application.

Key features ​

CapabilityPrimary entry pointUse it for
Agents@anvia/core/agentStateful model-and-tool loops with instructions and runtime policy
Completions@anvia/core/completionDirect model requests, streaming, messages, and parsed results
Tools@anvia/core/toolTyped tools, middleware, approvals, tool sets, and dynamic discovery
Memory@anvia/core/memoryConversation persistence and compaction contracts
Retrieval@anvia/core/embeddings, @anvia/core/vector-storeEmbedding documents and searching vector indexes
Pipelines@anvia/core/pipelineTyped multi-stage workflows, batches, graphs, and run events
Media@anvia/core/image-generation, @anvia/core/audio-generation, @anvia/core/transcriptionProvider-neutral media requests
Runtime control@anvia/core/hooks, @anvia/core/guardrailsIntercepting runs and enforcing input/output policy
Integration@anvia/core/mcp, @anvia/core/skills, @anvia/core/observabilityExternal tools, reusable instructions, and run telemetry
Evaluation@anvia/core/evalsTyped evaluation suites, metrics, reporters, and CLI output

The root @anvia/core entry point re-exports the most common agent, completion, tool, hook, memory, guardrail, and UI-stream APIs. Prefer a capability subpath when it makes ownership clearer or when the symbol is not available from the root.

Common patterns ​

Inject provider models ​

Create provider clients near the server boundary, then pass their completion, embedding, or media models into Core. This keeps credentials and provider-specific configuration outside agent definitions.

Use direct completions for one model call ​

Choose createCompletion or createParsedCompletion when a workflow does not need agent turns or tool execution. See Completions and Structured output.

Keep persistence behind contracts ​

Agents accept MemoryStore, AgentEventStore, and VectorSearchIndex implementations. Start with an in-memory implementation during development, then replace it with the adapter that matches production storage. See Memory and Knowledges.

Keep tool authorization in the application ​

Schemas validate model-produced arguments; they do not authorize a user or tenant. Enforce permissions inside the tool or middleware before accessing product data. See Tool security.

Runtime compatibility ​

FieldValue
Package formatESM
TypeScriptDeclarations included
Peer dependenciesNone declared
Schema libraryZod 4
Runtime boundaryModern JavaScript runtimes; individual entry points may require runtime-specific capabilities

Core's contracts are broadly portable, but not every entry point has the same environment needs. File/PDF loaders need file or binary access, MCP stdio needs a process-capable server runtime, and web-stream adapters need ReadableStream. Keep those APIs on the server unless the target runtime explicitly supports them.

Continue learning ​

For exact exports and signatures, use the API reference. For release history, read the source changelog.

Built for Anvia.