NIN Connect Docs
Providers

OpenAI Agents SDK

Use NIN Connect tools with the OpenAI Agents SDK — Agent, run(), and function tools.

Installation

npm install @nin.in/core @openai/agents openai

Environment Variables

NIN_API_KEY=nk_live_xxxxxxxxx
OPENAI_API_KEY=sk-xxxxxxxxx

Full Example

import { Nin } from "@nin.in/core";
import { Agent, run } from "@openai/agents";

const nin = new Nin({ apiKey: process.env.NIN_API_KEY! });
const session = nin.session("user_123");

// fetch tool definitions from the GitHub plugin
const toolDefs = await session.getTools({ plugins: ["github"] });

// build OpenAI Agents tools
// inputSchema is JSON Schema, which the OpenAI API accepts natively
const tools = toolDefs.map((t) => ({
  type: "function" as const,
  name: t.slug,
  description: t.description,
  parameters: t.inputSchema ?? { type: "object", properties: {} },
  execute: async (params: Record<string, unknown>) =>
    session.execute(t.slug, params),
}));

const agent = new Agent({
  name: "GitHub Agent",
  instructions: "You help manage GitHub repositories and issues.",
  tools,
});

const result = await run(agent, "Create an issue titled 'Bug fix' in my repo");
console.log(result.finalOutput);

How It Works

  1. session.getTools() returns tool definitions with inputSchema (JSON Schema)
  2. Tools are mapped to the OpenAI function-tool format: { type: "function", name, description, parameters, execute }
  3. The Agent is created with an instructions string and the tools array
  4. run() sends the prompt to the LLM; when the model calls a tool, execute runs session.execute() which proxies through NIN with auth injected
  5. The agent loop continues until the model produces a final text output

Multi-Plugin Agents

You can combine tools from multiple plugins into a single agent:

const toolDefs = await session.getTools({
  plugins: ["github", "slack", "gmail"],
});

const agent = new Agent({
  name: "Dev Assistant",
  instructions: "You help with GitHub issues, Slack messages, and emails.",
  tools: toolDefs.map((t) => ({
    type: "function" as const,
    name: t.slug,
    description: t.description,
    parameters: t.inputSchema ?? { type: "object", properties: {} },
    execute: async (params: Record<string, unknown>) =>
      session.execute(t.slug, params),
  })),
});

On this page