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

@kigathi/ai-agents

v0.1.3

Published

Forward-only Agents/Bots SDK on top of OpenAI Responses API.

Readme

@kigathi/ai-agents

Unified Agents/Bots SDK for the OpenAI Responses API.

Install

npm install @kigathi/ai-agents

For direct mode, also install:

npm install openai

Quick API shape

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient(config);
sdk.registerTool(tool);
sdk.createAgent(agent);
const result = await sdk.run(params);

Modes

The SDK supports three setup patterns, and in normal usage you do not need to pass mode manually. The client infers it from the config you provide.

1. Direct mode

Use this when your app should call OpenAI directly and you do not need backend persistence.

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
});

Required:

  • apiKey

2. Proxy mode

Use this when your app should call your backend, and your backend should perform the agent run.

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  backendUrl: "https://api.example.com",
});

Required:

  • backendUrl

3. Direct mode with backend persistence

Use this when your app should call OpenAI directly, but you still want your backend to persist messages, receive tool events, or trigger downstream workflows.

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
  backendUrl: "https://api.example.com",
});

Required:

  • apiKey
  • backendUrl

Behavior summary:

  • apiKey only: direct OpenAI execution
  • backendUrl only: proxy mode, where your backend performs the run
  • apiKey and backendUrl together: direct OpenAI execution plus backend persistence and event sync

Minimal vs full examples

The sections below show the smallest valid call for each API, followed by a more realistic production-style example.

1. Create a client

Minimal direct mode:

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
});

Minimal proxy mode:

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  backendUrl: "https://api.example.com",
});

Full example:

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
  orgId: process.env.OPENAI_ORG_ID,
  projectId: process.env.OPENAI_PROJECT_ID,
  backendUrl: "https://api.example.com",
  pricing: {
    "gpt-4.1-mini": {
      prompt_per_million: 0.4,
      completion_per_million: 1.6,
    },
  },
});

Required parameters:

  • Direct mode: apiKey
  • Proxy mode: backendUrl

Optional parameters:

  • mode
  • orgId
  • projectId
  • pricing

Direct OpenAI + backend persistence mode

You can also run the model directly with OpenAI while still sending conversation events to your backend for persistence, analytics, or post-processing.

Use apiKey and backendUrl together:

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
  backendUrl: "https://api.example.com",
});

What this mode does:

  • Runs the actual model request against OpenAI directly
  • Persists user and assistant messages to your backend
  • Syncs tool-call events to your backend on a best-effort basis

Useful request fields in this mode:

  • conversation_id
  • user_id
  • metadata
  • client_message_id
  • idempotency_key
  • idempotency_key_response

2. Register a tool

Minimal example:

sdk.registerTool({
  name: "lookup_order",
});

Full example:

sdk.registerTool({
  name: "lookup_order",
  type: "function",
  description: "Find order details by order number.",
  parameters_schema: {
    type: "object",
    properties: {
      order_number: { type: "string" },
    },
    required: ["order_number"],
  },
  handler: async ({ order_number }, context) => {
    return {
      order_number,
      status: "processing",
      requested_by: context.userId ?? null,
    };
  },
});

Required parameters:

  • name

Useful optional parameters:

  • description
  • parameters_schema
  • handler

Notes:

  • If you omit handler, tool calls will fail gracefully with Tool not registered: <name>.
  • If an agent does not list specific tools, it can use all registered tools.

3. Register an agent

Minimal example:

sdk.createAgent({
  name: "support-bot",
  model: "gpt-4.1-mini",
});

Full example:

sdk.createAgent({
  id: "support-bot-v1",
  name: "support-bot",
  model: "gpt-4.1-mini",
  instructions: "You are a concise support assistant. Use tools when needed.",
  temperature: 0.3,
  max_output_tokens: 400,
  tools: ["lookup_order"],
  metadata: {
    team: "support",
    channel: "web",
  },
});

Required parameters:

  • name
  • model

Useful optional parameters:

  • id
  • instructions
  • temperature
  • max_output_tokens
  • tools
  • metadata

4. Run an agent

Minimal example:

const result = await sdk.run({
  agent: "support-bot",
  message: "Where is order AX-4420?",
});

console.log(result.output_text);

Full example:

const result = await sdk.run({
  agent: "support-bot",
  message: "Check order AX-4420 and summarize the current status.",
  conversation_id: 1234,
  conversation_key: "support:customer-42",
  user_id: 42,
  context: {
    userId: 42,
    accountId: "acc_123",
  },
  messages: [
    { role: "user", content: "Hi" },
    { role: "assistant", content: "How can I help?" },
  ],
  max_history_messages: 20,
  maxToolIterations: 8,
});

console.log(result.output_text);
console.log(result.usage);
console.log(result.cost_usd);

Required parameters:

  • agent
  • message

Useful optional parameters:

  • conversation_id
  • conversation_key
  • user_id
  • context
  • messages
  • max_history_messages
  • maxToolIterations
  • previous_response_id
  • replying_to

5. Stream an agent response

Minimal example:

for await (const delta of sdk.runStream({
  agent: "support-bot",
  message: "Give me a short update on order AX-4420.",
})) {
  process.stdout.write(delta);
}

Full example:

for await (const delta of sdk.runStream({
  agent: "support-bot",
  message: "Summarize the latest ticket updates.",
  conversation_key: "support:customer-42",
  user_id: 42,
})) {
  process.stdout.write(delta);
}

Complete minimal working example

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
});

sdk.registerTool({
  name: "lookup_order",
  description: "Return a fake order status.",
  parameters_schema: {
    type: "object",
    properties: {
      order_number: { type: "string" },
    },
    required: ["order_number"],
  },
  handler: async ({ order_number }) => ({
    order_number,
    status: "processing",
  }),
});

sdk.createAgent({
  name: "support-bot",
  model: "gpt-4.1-mini",
  instructions: "You are a concise support assistant.",
  tools: ["lookup_order"],
});

const result = await sdk.run({
  agent: "support-bot",
  message: "Check order AX-4420",
});

console.log(result.output_text);

Complete proxy example

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  backendUrl: "https://api.example.com",
});

const result = await sdk.run({
  agent: "support-bot",
  message: "Start claim #99",
  conversation_id: 1234,
});

console.log(result.output_text);

Complete direct + backend persistence example

import { createClient } from "@kigathi/ai-agents";

const sdk = createClient({
  apiKey: process.env.OPENAI_API_KEY,
  backendUrl: "https://api.example.com",
});

sdk.registerTool({
  name: "lookup_order",
  description: "Find order by order number.",
  parameters_schema: {
    type: "object",
    properties: {
      order_number: { type: "string" },
    },
    required: ["order_number"],
  },
  handler: async ({ order_number }) => ({
    order_number,
    status: "processing",
  }),
});

sdk.createAgent({
  name: "support-bot",
  model: "gpt-4.1-mini",
  instructions: "You are a concise support assistant.",
  tools: ["lookup_order"],
});

const result = await sdk.run({
  agent: "support-bot",
  message: "Check order AX-4420",
  conversation_id: 1234,
  user_id: 42,
  client_message_id: "msg_123",
  metadata: {
    source: "dashboard",
    account_id: "acc_123",
  },
});

console.log(result.output_text);

Full sample apps

All three use @kigathi/ai-agents in direct mode with backend persistence so OpenAI handles model execution while Axis stores conversation, message, and related event metadata.

Notes

  • createClient() auto-selects proxy mode when backendUrl is provided without apiKey. Otherwise it uses direct mode.
  • In direct mode, the consuming app must have the openai package installed.
  • In direct mode with backendUrl, the SDK still calls OpenAI directly, then asynchronously persists messages and tool events to your backend.
  • You can pass either an agent name/id or a full agent object to run().
  • If proxy mode cannot find a local agent, it will try to resolve the agent from the backend.