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

@tashiscool/agents

v0.1.0

Published

Agent building blocks: tools, memory, and structured output

Readme

@llm-utils/agents

Agent building blocks for LLM applications. Type-safe tools, token-aware memory, and structured output parsing.

Installation

pnpm add @llm-utils/agents
# or
npm install @llm-utils/agents

Features

  • Tool Definition - Type-safe tool/function definitions with Zod schemas
  • Memory Management - Token-aware conversation memory with windowing
  • Output Parsing - Parse and validate structured LLM outputs
  • Provider Agnostic - Works with OpenAI, Anthropic, and other providers
  • Full TypeScript - Complete type safety with generics

Usage

Define Tools

import { defineTool, createToolExecutor, z } from '@llm-utils/agents';

// Define a tool with Zod schema
const weatherTool = defineTool({
  name: 'get_weather',
  description: 'Get current weather for a location',
  parameters: z.object({
    location: z.string().describe('City name'),
    units: z.enum(['celsius', 'fahrenheit']).optional(),
  }),
  execute: async ({ location, units }) => {
    // Your implementation
    return { temperature: 22, conditions: 'sunny' };
  },
});

// Create an executor
const executor = createToolExecutor([weatherTool]);

// Get tools in provider format
const openaiTools = executor.toOpenAI();
const anthropicTools = executor.toAnthropic();

// Execute a tool call from LLM response
const result = await executor.execute({
  id: 'call_123',
  name: 'get_weather',
  arguments: { location: 'San Francisco' },
});

Conversation Memory

import { createMemory, createSlidingWindowMemory } from '@llm-utils/agents';

// Token-aware memory with automatic windowing
const memory = createMemory({
  maxTokens: 4000,
  systemMessage: 'You are a helpful assistant.',
  preserveRecent: 3, // Always keep last 3 messages
});

// Add messages
memory.add({ role: 'user', content: 'Hello!' });
memory.add({ role: 'assistant', content: 'Hi there! How can I help?' });

// Get messages within token budget
const messages = memory.getMessages();

// Check memory stats
const stats = memory.getStats();
console.log(`Using ${stats.utilizationPercent}% of token budget`);

// Simple sliding window (last N messages)
const simpleMemory = createSlidingWindowMemory(20, 'System prompt here');

Structured Output Parsing

import { parseWithSchema, createSchemaParser, Parsers, z } from '@llm-utils/agents';

// Parse with a Zod schema
const result = parseWithSchema(
  llmResponse,
  z.object({
    answer: z.string(),
    confidence: z.number(),
  })
);

if (result.success) {
  console.log(result.data.answer);
}

// Create a reusable parser
const analysisParser = createSchemaParser(
  'Analysis',
  z.object({
    sentiment: z.enum(['positive', 'negative', 'neutral']),
    topics: z.array(z.string()),
    summary: z.string(),
  }),
  'Analyze the provided text'
);

// Get prompt instructions for the LLM
const instructions = analysisParser.getPromptInstructions();

// Parse response
const analysis = analysisParser.parseOrThrow(llmResponse);

// Use built-in parsers
const decision = Parsers.Decision.parse(llmResponse);
const sentiment = Parsers.Sentiment.parse(llmResponse);
const entities = Parsers.Entities.parse(llmResponse);

Summary-Based Memory

import { createSummaryMemory } from '@llm-utils/agents';

const memory = createSummaryMemory({
  maxMessages: 10,
  systemMessage: 'You are an assistant.',
  summarizer: async (messages) => {
    // Call LLM to summarize old messages
    const response = await llm.chat({
      messages: [
        { role: 'system', content: 'Summarize this conversation briefly.' },
        ...messages,
      ],
    });
    return response.content;
  },
});

// Periodically summarize old messages
await memory.summarize();

API Reference

Tools

  • defineTool(config) - Define a tool with typed parameters
  • createToolExecutor(tools?) - Create a tool executor
  • toOpenAITool(tool) - Convert to OpenAI format
  • toAnthropicTool(tool) - Convert to Anthropic format
  • zodToJsonSchema(schema) - Convert Zod to JSON Schema

Memory

  • createMemory(config) - Token-aware memory
  • createSlidingWindowMemory(size, system?) - Simple sliding window
  • createSummaryMemory(config) - Memory with summarization
  • estimateTokens(text) - Rough token estimation

Output Parsing

  • parseWithSchema(text, schema) - Parse and validate with Zod
  • createSchemaParser(name, schema) - Create reusable parser
  • extractJson(text) - Extract JSON from mixed content
  • Parsers - Pre-built parsers for common patterns

Common Schemas

CommonSchemas.Decision    // Yes/no with reasoning
CommonSchemas.Sentiment   // Sentiment analysis
CommonSchemas.Entities    // Entity extraction
CommonSchemas.Classification // Classification result
CommonSchemas.Summary     // Text summary
CommonSchemas.ActionItems // Action item extraction

License

MIT