This comprehensive guide will help you get started with StackOne’s AI tools, covering installation, basic usage, tool filtering, and advanced features.

Installation

# Using npm
npm install @stackone/ai

# Using pnpm
pnpm add @stackone/ai

# Using bun
bun add @stackone/ai

Authentication Setup

Configure authentication using one of these methods:

Using a .env File

STACKONE_API_KEY=<your-api-key>

Load it in your code:

import * as dotenv from 'dotenv';
dotenv.config();

Initializing Toolset

import { StackOneToolSet } from '@stackone/ai';
const toolset = new StackOneToolSet();

Using the ToolSet

Here’s a complete example showing how to use filtered tools:

async function manageEmployees() {
  const tools = toolset.getStackOneTools(['hris_*'], accountId);

  try {
    // List employees
    const employees = await tools.getTool('hris_list_employees')
      .execute();

    // Get specific employee
    const employee = await tools.getTool('hris_get_employee')
      .execute({ employeeId: '123' });

    // Create new employee
    const newEmployee = await tools.getTool('hris_create_employee')
      .execute({
        firstName: 'John',
        lastName: 'Doe',
        email: 'john@example.com'
      });

    console.log('Operations completed:', {
      totalEmployees: employees.length,
      specificEmployee: employee,
      newEmployee
    });
  } catch (error) {
    console.error('Error:', error);
  }
}

AI Framework Integration

OpenAI Functions

import { OpenAI } from 'openai';

const openai = new OpenAI();
const tools = toolset.getStackOneTools(['hris_*'], accountId);
const openAITools = tools.toOpenAI();

const completion = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'List all employees' }],
  tools: openAITools
});

if (completion.choices[0].message.tool_calls) {
  const toolCall = completion.choices[0].message.tool_calls[0];
  const result = await tools.execute(toolCall.function.arguments);
  console.log('Function result:', result);
}

AI SDK by Vercel

Typescript

const toolset = new StackOneToolSet();
const tools = toolset.getStackOneTools(['hris_*'], accountId);
const aiSdkTools = tools.toAISDK();

const { text } = await generateText({
  model: openai('gpt-4o'),
  tools: aiSdkTools,
  prompt: 'Find all employees in the engineering department',
  maxSteps: 3,
});

LangChain Integration

Python
from langchain_openai import ChatOpenAI

toolset = StackOneToolSet()
tools = toolset.get_tools(["hris_*"], account_id=account_id)
langchainTools = tools.to_langchain();

# Create model with tools
model = ChatOpenAI(model="gpt-4o-mini")
model_with_tools = model.bind_tools(langchain_tools)

result = model_with_tools.invoke(f"Find all employees in the engineering department")