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

agent_wrapper

v0.3.0

Published

A powerful, lightweight SDK for building AI agents with OpenAI Agents SDK. Supports streaming, multi-agent handoffs, guardrails, and structured outputs.

Readme

Agent Wrapper

A powerful, lightweight SDK for building AI agents using the OpenAI Agents SDK. Works seamlessly with OpenAI, Groq, and any OpenAI-compatible API.

npm version License: MIT

✨ Features

  • 🚀 Simple API - Easy-to-use AiAgent class with sensible defaults
  • 🔄 Streaming - Real-time response streaming with runStream()
  • 🛠️ Tool Support - Create and use custom tools with createTool()
  • 🤝 Multi-Agent - Handoffs between specialized agents
  • 🛡️ Guardrails - Input/output validation helpers
  • 💬 Conversation History - runWithHistory() for multi-turn chats
  • 🔌 OpenAI Compatible - Works with OpenAI, Groq, Ollama, and more
  • 📝 TypeScript First - Full type safety and excellent DX

📦 Installation

npm install agent_wrapper
# or
bun add agent_wrapper
# or
pnpm add agent_wrapper

Requirements: Node.js 22+ or Bun 1.0+

🚀 Quick Start

Basic Usage

import { AiAgent } from 'agent_wrapper';

const agent = new AiAgent({
  key: process.env.OPENAI_API_KEY,
  instructions: 'You are a helpful assistant.',
});

const result = await agent.run('What is the capital of France?');
console.log(result); // "Paris"

Using with Groq

const agent = new AiAgent({
  key: process.env.GROQ_API_KEY,
  baseUrl: 'https://api.groq.com/openai/v1',
  modelName: 'llama-3.3-70b-versatile',
  instructions: 'You are a helpful assistant.',
});

const result = await agent.run('Hello!');

Using Tools

import { AiAgent, createTool } from 'agent_wrapper';
import { z } from 'zod';

const calculatorTool = createTool({
  name: 'calculator',
  description: 'Perform math calculations',
  parameters: z.object({
    operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
    a: z.number(),
    b: z.number(),
  }),
  execute: async ({ operation, a, b }) => {
    const ops = { add: a + b, subtract: a - b, multiply: a * b, divide: a / b };
    return `Result: ${ops[operation]}`;
  },
});

const agent = new AiAgent({
  key: process.env.OPENAI_API_KEY,
  instructions: 'Use the calculator for math.',
  tools: [calculatorTool],
});

const result = await agent.run('What is 15 multiplied by 7?');
// Tool is called automatically, returns "105"

Streaming Responses

for await (const event of agent.runStream('Tell me a story')) {
  if (event.type === 'text') {
    process.stdout.write(event.content || '');
  }
}

📚 API Reference

AiAgent Constructor

new AiAgent({
  // Required
  key: string,              // API key

  // Optional
  name?: string,            // Agent name (default: 'Agent')
  baseUrl?: string,         // API endpoint (default: OpenAI)
  instructions?: string,    // System prompt
  modelName?: string,       // Model (default: 'gpt-4o')
  tools?: Tool[],           // Callable tools
  handoffs?: Agent[],       // Agents to delegate to
  handoffDescription?: string,
  modelSettings?: {
    temperature?: number,   // 0.0-2.0
    maxTokens?: number,
    topP?: number,
  },
  enableTracing?: boolean,  // Default: false
})

Methods

| Method | Description | Returns | |--------|-------------|---------| | run(input, options?) | Run agent, return final output | Promise<string> | | runStream(input) | Stream responses in real-time | AsyncGenerator<StreamEvent> | | runWithHistory(messages) | Run with conversation history | Promise<string> | | getAgent() | Get underlying Agent instance | Agent |

Helper Functions

import { createTool, createInputGuardrail, createOutputGuardrail } from 'agent_wrapper';

💡 Examples

Multi-Agent Handoffs

import { Agent } from '@openai/agents';
import { AiAgent } from 'agent_wrapper';

const billingAgent = new Agent({
  name: 'Billing',
  instructions: 'Handle billing questions.',
  handoffDescription: 'Billing specialist',
});

const router = new AiAgent({
  key: process.env.OPENAI_API_KEY,
  instructions: 'Route billing questions to Billing agent.',
  handoffs: [billingAgent],
});

Custom API Provider (Ollama)

const agent = new AiAgent({
  key: 'ollama',  // Ollama doesn't need a real key
  baseUrl: 'http://localhost:11434/v1',
  modelName: 'llama3',
  instructions: 'You are helpful.',
});

✅ Tested & Verified

This SDK has been tested with:

  • Groq - llama-3.3-70b-versatile
  • OpenAI - gpt-4o, gpt-4
  • Tool Execution - Custom tools work correctly
  • Streaming - Real-time response streaming

Run the tests yourself:

bun run test-suite.ts      # 31 unit tests
bun run test-live-groq.ts  # Live API tests

🔄 Migration from 0.1.x

- const result = await agent.runAgent('Hello');
+ const result = await agent.run('Hello');

📋 Dependencies

  • @openai/agents ^0.2.1
  • @ai-sdk/openai-compatible ^1.0.22
  • zod ^4.1.12

📄 License

MIT License - see LICENSE

🤝 Contributing

Contributions welcome! See GitHub Issues.


Version: 0.2.0 | Author: mbittu000 | GitHub