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

@agenkit/core

v0.2.0

Published

Minimal, composable interfaces for AI agents - TypeScript implementation

Readme

@agenkit/core

Minimal, composable interfaces for AI agents in TypeScript.

Features

  • Minimal API: Only 2 required methods per agent (name, process)
  • Type Safe: Full TypeScript support with comprehensive type definitions
  • Composable: Easy middleware pattern for retry, timeout, caching, etc.
  • Transport Agnostic: HTTP, WebSocket, gRPC support
  • LLM Ready: Built-in adapters for OpenAI, Anthropic (Claude)
  • Production Ready: Middleware for resilience, observability, and control

Installation

npm install @agenkit/core

Quick Start

Local Agent

import { LocalAgent, createMessage } from '@agenkit/core';

const agent = new LocalAgent({
  name: 'greeter',
  process: async (message) => ({
    role: 'assistant',
    content: `Hello, ${message.content}!`,
  }),
});

const response = await agent.process(createMessage('user', 'World'));
console.log(response.content); // "Hello, World!"

OpenAI Agent

import { OpenAIAgent } from '@agenkit/core';

const agent = new OpenAIAgent({
  apiKey: process.env.OPENAI_API_KEY!,
  model: 'gpt-4o',
});

const response = await agent.process({
  role: 'user',
  content: 'What is the capital of France?',
});

console.log(response.content); // "The capital of France is Paris."

Anthropic (Claude) Agent

import { AnthropicAgent } from '@agenkit/core';

const agent = new AnthropicAgent({
  apiKey: process.env.ANTHROPIC_API_KEY!,
  model: 'claude-sonnet-4-20250514',
});

const response = await agent.process({
  role: 'user',
  content: 'Explain TypeScript in one sentence.',
});

console.log(response.content);

HTTP Transport

import { HTTPAgent } from '@agenkit/core';

const agent = new HTTPAgent({
  baseUrl: 'http://localhost:8000',
});

const response = await agent.process({
  role: 'user',
  content: 'Hello',
});

WebSocket Transport

import { WebSocketAgent } from '@agenkit/core';

const agent = new WebSocketAgent({
  url: 'ws://localhost:8080',
  maxRetries: 5,
  pingInterval: 30000,
});

await agent.connect();

const response = await agent.process({
  role: 'user',
  content: 'Hello',
});

await agent.close();

gRPC Transport

High-performance RPC with Protocol Buffers:

import { GrpcAgent, GrpcServer } from '@agenkit/core';

// Client
const client = new GrpcAgent('my-service', {
  address: 'localhost:50051',
  timeout: 5000,
  useTLS: false,
});

const response = await client.process({
  role: 'user',
  content: 'Hello',
});

await client.close();

// Server
const server = new GrpcServer(myAgent, {
  address: '0.0.0.0:50051',
  useTLS: false,
});

await server.start();
// ... handle requests ...
await server.stop();

Middleware

Apply retry, timeout, or custom middleware:

import { LocalAgent, applyMiddleware, retry, timeout } from '@agenkit/core';

const baseAgent = new LocalAgent({
  name: 'flaky',
  process: async (msg) => {
    // May fail occasionally
    if (Math.random() < 0.3) throw new Error('Network error');
    return { role: 'assistant', content: 'Success!' };
  },
});

// Apply retry and timeout middleware
const robustAgent = applyMiddleware(baseAgent, [
  retry({ maxAttempts: 3, initialDelay: 1000 }),
  timeout({ timeout: 5000 }),
]);

const response = await robustAgent.process({
  role: 'user',
  content: 'Hello',
});

Streaming

Stream responses for real-time interaction:

import { OpenAIAgent } from '@agenkit/core';

const agent = new OpenAIAgent({
  apiKey: process.env.OPENAI_API_KEY!,
});

for await (const chunk of agent.processStream({
  role: 'user',
  content: 'Count from 1 to 10',
})) {
  process.stdout.write(chunk.content);
}

Core Interfaces

Agent

interface Agent {
  name: string;
  process(message: Message): Promise<Message>;
  processStream?(message: Message): AsyncGenerator<Message>;
  capabilities?: string[];
}

Message

interface Message {
  role: string; // "user", "assistant", "system", "tool"
  content: unknown; // string, object, array, etc.
  metadata?: Record<string, unknown>;
  timestamp?: string; // ISO 8601
}

Tool

interface Tool {
  name: string;
  description: string;
  parametersSchema?: Record<string, unknown>;
  execute(params: Record<string, unknown>): Promise<ToolResult>;
}

Adapters

  • LocalAgent: Wrap TypeScript functions as agents
  • HTTPAgent: Communicate over HTTP/REST
  • WebSocketAgent: Real-time bidirectional communication
  • GrpcAgent: High-performance gRPC transport ✨ NEW
  • OpenAIAgent: OpenAI Chat Completion API (GPT-4, GPT-3.5)
  • AnthropicAgent: Anthropic Messages API (Claude 3)

Middleware

  • retry: Automatic retries with exponential backoff
  • timeout: Prevent long-running requests
  • circuitBreaker: Fail fast when service is unhealthy
  • Custom: Easy to implement your own

Why Agenkit?

Minimal

Only 2 required methods per agent. No complex inheritance, no framework lock-in.

Composable

Middleware pattern allows easy wrapping for cross-cutting concerns.

Type Safe

Full TypeScript support with comprehensive type definitions.

Production Ready

Built-in resilience patterns and LLM integrations.

Examples

See examples/ directory for complete, runnable examples:

  • basic-usage.ts: Simple getting started examples
  • middleware-example.ts: Production resilience patterns (retry, timeout, circuit breaker) ✨ NEW
  • transport-comparison.ts: HTTP vs WebSocket vs gRPC comparison ✨ NEW
  • llm-integration.ts: OpenAI & Anthropic integration with best practices ✨ NEW

Run any example:

npx ts-node examples/middleware-example.ts

Development

# Install dependencies
npm install

# Build
npm run build

# Test
npm test

# Lint
npm run lint

# Format
npm run format

License

MIT

Contributing

See CONTRIBUTING.md in the main repository.